oficina / sheets Public

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

Plain git — no account needed to clone.

Download

Download this file

1package store
2
3import (
4 "testing"
5
6 "amadan.net/oficina/sheets/internal/sheets/calc"
7)
8
9// textOf is what raw input evaluates to when it holds no references:
10// a literal's node, or a constant formula's single node.
11func textOf(t *testing.T, raw string) (calc.Node, bool) {
12 t.Helper()
13 node, blank, err := contentNode(raw)
14 if err != nil {
15 t.Fatalf("contentNode(%q): %v", raw, err)
16 }
17 return node, blank
18}
19
20func TestTextInputWrapsOnlyAmbiguousText(t *testing.T) {
21 cases := []struct {
22 in string
23 raw string
24 wrapped bool
25 }{
26 {"hello", "hello", false},
27 {" 123", " 123", false},
28 {"1,000", "1,000", false},
29 {"+353 1 234 5678", "+353 1 234 5678", false},
30 {"", `=""`, true},
31 {"00123", `="00123"`, true},
32 {"+5", `="+5"`, true},
33 {"1e5", `="1e5"`, true},
34 {"TRUE", `="TRUE"`, true},
35 {"false", `="false"`, true},
36 {"NaN", `="NaN"`, true},
37 {"Inf", `="Inf"`, true},
38 {"-infinity", `="-infinity"`, true},
39 {"0x1p-2", `="0x1p-2"`, true},
40 {"=SUM(A1)", `="=SUM(A1)"`, true},
41 {`="quoted"`, `="=""quoted"""`, true},
42 }
43 for _, c := range cases {
44 raw, wrapped := TextInput(c.in)
45 if raw != c.raw || wrapped != c.wrapped {
46 t.Errorf("TextInput(%q) = %q, %v; want %q, %v", c.in, raw, wrapped, c.raw, c.wrapped)
47 }
48 }
49}
50
51// Whatever the text, the raw input TextInput returns must read back
52// as exactly that text and nothing else.
53func FuzzTextInputReadsBackAsItself(f *testing.F) {
54 for _, s := range []string{"", "0", "00123", "TRUE", "NaN", "=A1", `"`, `""`, "a\"b", "\n", "1e999", "é"} {
55 f.Add(s)
56 }
57 f.Fuzz(func(t *testing.T, s string) {
58 raw, _ := TextInput(s)
59 node, blank := textOf(t, raw)
60 if blank {
61 t.Fatalf("TextInput(%q) = %q reads as blank", s, raw)
62 }
63 str, ok := node.(*calc.Str)
64 if !ok || str.V != s {
65 t.Fatalf("TextInput(%q) = %q reads as %#v", s, raw, node)
66 }
67 })
68}
69