oficina / sheets Public

Clone
git clone https://amadan.net/oficina/sheets

Plain git — no account needed to clone.

Download

Download this file

1package format
2
3import "testing"
4
5func TestDisplayCurrencySymbols(t *testing.T) {
6 for _, tc := range []struct{ code, want string }{
7 {`€#,##0.00`, "€1,234.50"},
8 {`\€#,##0.00`, "€1,234.50"},
9 {`[$€]#,##0.00`, "€1,234.50"},
10 {`[$£]#,##0.00`, "£1,234.50"},
11 {`[$$]#,##0.00`, "$1,234.50"},
12 {`[$CAD]#,##0.00`, "CAD1,234.50"},
13 {`[$CAD-1009]#,##0.00`, "CAD1,234.50"},
14 {`[$€-407]#,##0.00`, "€1,234.50"},
15 {`#,##0.00[$€]`, "1,234.50€"},
16 {`"[$€]"#,##0.00`, "[$€]1,234.50"},
17 {`\[$€]#,##0.00`, "[$€]1,234.50"},
18 } {
19 t.Run(tc.code, func(t *testing.T) {
20 if got := Display(numValue(1234.5), tc.code); got != tc.want {
21 t.Fatalf("Display = %q, want %q", got, tc.want)
22 }
23 })
24 }
25}
26
27func TestCurrencySectionsAndUnicodeDates(t *testing.T) {
28 for _, tc := range []struct {
29 code string
30 num float64
31 want string
32 }{
33 {`[$€]0.00`, -12.5, "-€12.50"},
34 {`[$€]0.00;([$€]0.00);"zero"`, -12.5, "(€12.50)"},
35 {`[$€]0.00;([$€]0.00);"zero"`, 0, "zero"},
36 {`[$CAD]`, -12.5, "CAD"},
37 {`yyyy年mm月dd日`, 1, "1899年12月31日"},
38 {`yyyy\年mm\月dd\日`, 1, "1899年12月31日"},
39 } {
40 if got := Display(numValue(tc.num), tc.code); got != tc.want {
41 t.Errorf("Display(%v, %q) = %q, want %q", tc.num, tc.code, got, tc.want)
42 }
43 }
44}
45
46func TestCurrencyExpansionDoesNotInterpretOtherSyntax(t *testing.T) {
47 for _, code := range []string{`[$]0`, `[$€-]0`, `[$€-garbage]0`, `[$€`, `[Red]0`, `[$"x"]0`, `[$€;0]`} {
48 if got := expandCurrency(code); got != code {
49 t.Errorf("unsupported currency token changed: %q -> %q", code, got)
50 }
51 }
52}
53