oficina / sheets Public

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

Plain git — no account needed to clone.

Download

Download this file

1package calc
2
3import "testing"
4
5func TestInspectNamesUnknownAndVolatileCalls(t *testing.T) {
6 cases := []struct {
7 src string
8 unknown bool
9 volatile bool
10 }{
11 {"1+2", false, false},
12 {"SUM(A1:A3)*2", false, false},
13 {"IF(A1>0,VLOOKUP(A1,B1:C9,2,FALSE),-A1)", false, false},
14 {"NOW()-TODAY()", false, true},
15 {"FOO(1)", true, false},
16 {"SUM(1,QUERY(A1))", true, false},
17 {"-NOTAFUNCTION(A1)", true, false},
18 {"IF(TRUE,1,BAR())+NOW()", true, true},
19 }
20 for _, c := range cases {
21 n, err := Parse(c.src)
22 if err != nil {
23 t.Fatalf("Parse(%q): %v", c.src, err)
24 }
25 got := Inspect(n)
26 if got.Unknown != c.unknown || got.Volatile != c.volatile {
27 t.Errorf("Inspect(%q) = %+v, want unknown=%v volatile=%v", c.src, got, c.unknown, c.volatile)
28 }
29 }
30}
31
32// The import converter treats a formula that fails to parse as
33// unsupported. These are the shapes Google and Excel write for things
34// this engine has no model of; each must fail here rather than parse
35// into something that evaluates.
36func TestParseRefusesShapesImportCannotKeep(t *testing.T) {
37 for _, src := range []string{
38 "Sheet2!A1",
39 "'My Sheet'!A1:B2",
40 "[1]Sheet1!A1",
41 "TaxRate*A1",
42 "_xlfn.XLOOKUP(1,A1:A2,B1:B2)",
43 `IFERROR(__xludf.DUMMYFUNCTION("QUERY(A1)"),3)`,
44 "SUM(Table1[Col])",
45 "{1,2}",
46 "A1#",
47 "@A1",
48 } {
49 if n, err := Parse(src); err == nil {
50 t.Errorf("Parse(%q) = %#v, want an error", src, n)
51 }
52 }
53}
54