cat / 012
clone

a spreadsheet for the terminal: lotus 1-2-3 looks, google sheets keys and formulas, one go binary

cat/module-path
012 / internal / ui / locale_test.go
locale_test.go 3.2K
1package ui23import (4 "strings"5 "testing"67 "src.rest/cat/012/internal/sheet"8)910// File > Settings > Locale picks German (Germany): the sheet shows11// decimal commas without changing a value, entries and formulas are12// typed the German way and stored the en-US way, the formula bar and13// editing show them German again, and undo goes back to en-US.14func TestLocaleSetting(t *testing.T) {15 m := newModel()16 press(t, m, "1234.5", "<enter>", "=A1/4", "<enter>")17 press(t, m, "<alt+f>", "<up>", "<up>", "<right>", "<down>", "<enter>")18 if !strings.Contains(screen(m), "German (Germany)") {19 t.Fatalf("no locale picker:\n%s", screen(m))20 }21 press(t, m, "Germany", "<enter>")22 if tag := m.book().LocaleTag(); tag != "de-DE" || !strings.Contains(line(m, contextLine), "1.234,56") {23 t.Fatalf("locale %q, context %q", tag, line(m, contextLine))24 }25 if v := m.sheet.Value(addr("A2")).Num; v != 308.625 || !strings.Contains(screen(m), "308,625") {26 t.Errorf("A2 = %v:\n%s", v, screen(m))27 }28 press(t, m, "1,5", "<enter>")29 if input(m, "A3") != "1.5" || m.sheet.Value(addr("A3")).Num != 1.5 {30 t.Errorf("A3 %q = %v", input(m, "A3"), m.sheet.Value(addr("A3")))31 }32 press(t, m, "=ROUND(A1;")33 if ctx := line(m, contextLine); !strings.HasPrefix(ctx, "ROUND(value; [places])") {34 t.Errorf("signature %q", ctx)35 }36 press(t, m, "<backspace>", "*1,5; 1)", "<enter>")37 if input(m, "A4") != "=ROUND(A1*1.5, 1)" || m.sheet.Value(addr("A4")).Num != 1851.8 {38 t.Errorf("A4 %q = %v", input(m, "A4"), m.sheet.Value(addr("A4")))39 }40 m.cur = addr("A4")41 if bar := line(m, formulaLine); !strings.Contains(bar, "=ROUND(A1*1,5; 1)") {42 t.Errorf("formula bar %q", bar)43 }44 press(t, m, "<f2>")45 if m.line.Text() != "=ROUND(A1*1,5; 1)" {46 t.Errorf("editing %q", m.line.Text())47 }48 press(t, m, "<esc>", "<ctrl+z>", "<ctrl+z>", "<ctrl+z>")49 if tag := m.book().LocaleTag(); tag != "" || !strings.Contains(screen(m), "308.625") {50 t.Errorf("after undo: locale %q\n%s", tag, screen(m))51 }52}5354// Pasted text is read in the workbook's locale, and copied values are55// written in it.56func TestLocalePasteAndCopy(t *testing.T) {57 m := newModel()58 m.book().SetLocale("de-DE")59 m.handlePaste("1,5\t26.09.2026\n2.000\tText")60 if v := m.sheet.Value(addr("A1")).Num; v != 1.5 {61 t.Errorf("A1 = %v", v)62 }63 if f := m.sheet.Cell(addr("B1")).Format; f.Kind != sheet.FmtDate {64 t.Errorf("B1 format %v", f)65 }66 if v := m.sheet.Value(addr("A2")).Num; v != 2000 {67 t.Errorf("A2 = %v", v)68 }69 clip := m.sheet.Copy(sheet.NewRect(addr("A1"), addr("A2")))70 if got := formatTSV(clip.TextIn(m.locale())); got != "1,5\n2000" {71 t.Errorf("copied %q", got)72 }73}7475// In German, a formula that doesn't parse says which separator was76// expected in German's syntax, and dates show German month names.77func TestLocaleErrorsAndNames(t *testing.T) {78 m := newModel()79 m.book().SetLocale("de-DE")80 press(t, m, "=SUM(1;2 3)", "<enter>")81 if ctx := line(m, contextLine); !strings.Contains(ctx, "Expected ; or ) in SUM") {82 t.Errorf("context %q", ctx)83 }84 press(t, m, "<esc>", "26.10.2026", "<enter>")85 m.sheet.SetFormat(sheet.NewRect(addr("A1"), addr("A1")), sheet.Format{Kind: sheet.FmtCustom, Pattern: "dddd d. mmmm"})86 m.sheet.SetColWidth(0, 22)87 if !strings.Contains(screen(m), "Montag 26. Oktober") {88 t.Errorf("no German names:\n%s", screen(m))89 }90}