cat / 012
clone

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

cat/module-path
012 / internal / sheet / explain_test.go
explain_test.go 2.2K
1package sheet23import "testing"45func TestHyperlink(t *testing.T) {6 checkFormulas(t, fixture(t), []fnCase{7 {`=HYPERLINK("https://example.com")`, txt("https://example.com")},8 {`=HYPERLINK("https://example.com", "Example")`, txt("Example")},9 {`=HYPERLINK("https://example.com", "")`, txt("https://example.com")},10 {`=HYPERLINK(1/0, "x")`, ErrDiv0},11 })12}1314func TestLink(t *testing.T) {15 s := sheetOf(t, map[string]string{16 "A1": "https://example.com/a?b=1",17 "A2": "mailto:ann@example.com",18 "A3": "see https://example.com",19 "A4": "http://",20 "A5": `=HYPERLINK("example.com", "Example")`,21 "A6": `=HYPERLINK(A1, "Docs")`,22 "A7": `=HYPERLINK("ftp://x", "x")`,23 "A8": `=UPPER(A1)`,24 "A9": "12",25 "B1": `="https://"&"example.com"`,26 })27 tests := map[string]string{28 "A1": "https://example.com/a?b=1",29 "A2": "mailto:ann@example.com",30 "A3": "",31 "A4": "",32 "A5": "https://example.com",33 "A6": "https://example.com/a?b=1",34 "A7": "",35 "A8": "HTTPS://EXAMPLE.COM/A?B=1",36 "A9": "",37 "B1": "https://example.com",38 "C1": "",39 }40 for a, want := range tests {41 if got := s.Link(at(a)); got != want {42 t.Errorf("Link(%s) = %q, want %q", a, got, want)43 }44 }45}4647func TestExplainError(t *testing.T) {48 s := sheetOf(t, map[string]string{49 "A1": "10", "A2": "0", "A3": "text",50 "B1": "=A1/A2",51 "B2": "=B1+1",52 "B3": "=SUM(A1:B2)",53 "B4": "=A1+A3",54 "B5": "=FOO+1",55 "B6": `=VLOOKUP(99, A1:A2, 1, FALSE)`,56 "B7": "=SQRT(-1)",57 "B8": "=C8", "C8": "=B8",58 "B9": "=-A1:A2",59 "B10": "=IFERROR(B1, 0)",60 "B11": "=AVERAGE(A3)",61 "B12": "5",62 })63 tests := map[string]string{64 "B1": "Division by zero in A1/A2",65 "B2": "From B1: division by zero in A1/A2",66 "B3": "From B1: division by zero in A1/A2",67 "B4": "Wrong type of value in A1+A3",68 "B5": "Unknown name FOO",69 "B6": "No match found by VLOOKUP(99,A1:A2,1,FALSE)",70 "B7": "Number out of range in SQRT(-1)",71 "B8": "Circular reference: B8 → C8 → B8",72 "B9": "A range where one value is expected: A1:A2",73 "B10": "",74 "B11": "Division by zero in AVERAGE(A3)",75 "B12": "",76 "A3": "",77 }78 for a, want := range tests {79 if got := s.ExplainError(at(a)); got != want {80 t.Errorf("ExplainError(%s) = %q, want %q", a, got, want)81 }82 }83}