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 (
4 "testing"
5
6 "amadan.net/oficina/sheets/internal/sheets/calc"
7)
8
9func numValue(n float64) calc.Value { return calc.Value{Kind: calc.KindNum, Num: n} }
10func errValue(e calc.ErrKind) calc.Value { return calc.Value{Kind: calc.KindErr, Err: e} }
11
12func TestDisplay(t *testing.T) {
13 for _, tc := range []struct {
14 numFmt string
15 num float64
16 want string
17 }{
18 {"General", 1234.5678, "1234.5678"},
19 {"0.00", 1234.5678, "1234.57"},
20 {"#,##0.00", 1234.5678, "1,234.57"},
21 {"0%", 0.075, "8%"},
22 {"0.0%", 0.075, "7.5%"},
23 {`"€"#,##0.00"`, 1234.5, "€1,234.50"},
24 } {
25 got := Display(numValue(tc.num), tc.numFmt)
26 if got != tc.want {
27 t.Errorf("Display(%v, %q) = %q, want %q", tc.num, tc.numFmt, got, tc.want)
28 }
29 }
30}
31
32// An error value displays as its Excel text regardless of number format —
33// a currency format must not render #DIV/0! as a currency amount.
34func TestDisplayErrorIgnoresNumberFormat(t *testing.T) {
35 if got := Display(errValue(calc.ErrDiv0), "#,##0.00"); got != "#DIV/0!" {
36 t.Fatalf("error under currency format = %q", got)
37 }
38}
39