cat / 012
clone

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

main
012 / e2e / locale_test.go
locale_test.go 3.0K
1package e2e23import (4 "os"5 "path/filepath"6 "strings"7 "testing"8)910// germanBudget types a small budget in English (United States), then11// picks German (Germany) in File > Settings > Locale from the palette.12func germanBudget(s *session) {13 s.keys("Item", "<tab>", "Amount", "<tab>", "Due", "<enter>")14 s.keys("Rent", "<tab>", "$950.00", "<tab>", "9/26/2026", "<enter>")15 s.keys("Power", "<tab>", "$84.20", "<tab>", "10/3/2026", "<enter>")16 s.keys("Total", "<tab>", "=SUM(B2:B3)", "<enter>")17 s.keys("VAT", "<tab>", "=ROUND(B4*0.19, 2)", "<enter>")18 s.keys("<ctrl+k>", "locale", "<enter>")19 s.waitFor("Type a language, country or tag")20 s.keys("germany", "<enter>")21 s.waitFor("Locale German (Germany)")22}2324// Switching the locale redraws the sheet German, takes entries and25// formulas typed the German way, saves them as en-US writes them, and26// undoes back to en-US.27func TestLocaleSwitch(t *testing.T) {28 t.Parallel()29 dir := t.TempDir()30 s := start(t, dir)31 germanBudget(s)32 s.waitFor("1.034,20")33 s.waitFor("26.9.2026")34 s.keys("<up>", "<right>")35 s.waitForBar("B5", "=ROUND(B4*0,19; 2)")3637 s.keys("<down>", "<left>", "Rate", "<tab>", "12,5 %", "<enter>")38 s.keys("Share", "<tab>", "=ROUND(B5/B4; ")39 s.waitFor("ROUND(value; [places])")40 s.keys("3)", "<enter>")41 s.keys("<up>", "<right>")42 s.waitForBar("B7", "=ROUND(B5/B4; 3)")43 s.waitFor("0,19")4445 s.keys("<ctrl+s>", "budget", "<enter>")46 s.eventually("saved", func() bool { return s.title() == "012 - budget.012" })47 data, err := os.ReadFile(filepath.Join(dir, "budget.012"))48 if err != nil {49 t.Fatal(err)50 }51 for _, want := range []string{`"locale": "de-DE"`, `"=ROUND(B4*0.19, 2)"`, `"12.5%"`, `"=ROUND(B5/B4, 3)"`, `"9/26/2026"`} {52 if !strings.Contains(string(data), want) {53 t.Errorf("the file lacks %s:\n%s", want, data)54 }55 }5657 // Undo the entries and the locale: the sheet is en-US's again.58 s.keys("<ctrl+z>", "<ctrl+z>", "<ctrl+z>", "<ctrl+z>", "<ctrl+z>")59 s.waitFor("$1,034.20")60 s.waitFor("9/26/2026")61}6263// The config's locale, here from LANG, is the default of new sheets;64// a file saved without a locale of its own opens in the reader's.65func TestLocaleFromLANG(t *testing.T) {66 t.Parallel()67 dir := t.TempDir()68 s := startWith(t, options{dir: dir, env: []string{"LANG=de_DE.UTF-8"}})69 s.keys("1,5", "<enter>", "=A1*2", "<enter>")70 s.keys("<up>")71 s.waitForBar("A2", "=A1*2")72 s.keys("<up>")73 s.waitForBar("A1", "1,5")74 s.keys("<ctrl+s>", "half", "<enter>")75 s.eventually("saved", func() bool { return s.title() == "012 - half.012" })76 s.keys("<ctrl+q>")77 s.waitExit()7879 r := start(t, dir, "half.012")80 r.waitForBar("A1", "1.5")81}8283// In German, a date typed with a German month name is a date, shown84// with German names, and a formula that doesn't parse names German's85// separator.86func TestLocaleNamesAndErrors(t *testing.T) {87 t.Parallel()88 s := start(t, t.TempDir())89 germanBudget(s)90 s.keys("<ctrl+g>", "D1", "<enter>", "3. Okt. 2026", "<enter>")91 s.waitFor("3 Okt 2026")92 s.keys("=SUM(1;2 3)", "<enter>")93 s.waitFor("Expected ; or ) in SUM")94}