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 / linejson_test.go
linejson_test.go 1.5K
1package sheet23import (4 "strings"5 "testing"6)78func TestLinesRoundTrip(t *testing.T) {9 c := Chart{Type: ChartLine, Data: Rect{To: Addr{Col: 2, Row: 6}}, At: Addr{Col: 4, Row: 1}, W: 44, H: 14, Header: true, Title: "Sales"}10 c.Legend = LegendNone11 got, err := ParseChart(c.JSON())12 if err != nil || got.JSON() != c.JSON() {13 t.Fatalf("chart %s came back %s, %v", c.JSON(), got.JSON(), err)14 }15 if _, err := ParseChart(`{"type":"blimp","data":"A1:B2","at":"C1"}`); err == nil {16 t.Error("a chart of an unknown type was read")17 }1819 p := Pivot{Source: "Q3 plan", Range: Rect{To: Addr{Col: 3, Row: 9}}, Rows: []PivotGroup{{Col: 1, Desc: true}},20 Values: []PivotValue{{Col: 3, Summarize: SumBy}}, Filters: []PivotFilter{{Col: 0, Criteria: Criteria{Hidden: []string{"North"}}}}, RowTotals: true}21 back, err := ParsePivot(p.JSON())22 if err != nil || back.JSON() != p.JSON() || !strings.HasPrefix(p.JSON(), `{"source":"'Q3 plan'!A1:D10"`) {23 t.Fatalf("pivot %s came back %s, %v", p.JSON(), back.JSON(), err)24 }2526 cr := Criteria{Hidden: []string{"", "x"}, Cond: Condition{Op: CondGreater, Arg: "3"}}27 if cr.JSON() != `{"hidden":["","x"],"condition":"gt","value":"3"}` {28 t.Fatalf("criteria %s", cr.JSON())29 }30 crBack, err := ParseCriteria(cr.JSON())31 if err != nil || crBack.JSON() != cr.JSON() {32 t.Fatalf("criteria came back %s, %v", crBack.JSON(), err)33 }34 if empty, _ := ParseCriteria(`{"condition":"empty","value":"ignored"}`); empty.Cond.Arg != "" {35 t.Errorf("a condition without a value kept %q", empty.Cond.Arg)36 }37}