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 / nav_test.go
nav_test.go 1.8K
1package sheet23import "testing"45func TestEdge(t *testing.T) {6 s := New()7 for _, a := range []string{"A1", "A2", "A3", "A6", "A7"} {8 s.Set(at(a), "1")9 }10 tests := []struct {11 from string12 dc, dr int13 want string14 }{15 {"A1", 0, 1, "A3"}, // inside a block: to its end16 {"A3", 0, 1, "A6"}, // end of a block: to the next block17 {"A4", 0, 1, "A6"}, // from a blank: to the next filled cell18 {"A7", 0, 1, "A1048576"}, // nothing ahead: sheet edge19 {"A6", 0, -1, "A3"},20 {"A1", 0, -1, "A1"}, // already at the edge21 {"A1", 1, 0, "XFD1"},22 {"C1", -1, 0, "A1"},23 }24 for _, tt := range tests {25 if got := s.Edge(at(tt.from), tt.dc, tt.dr); got != at(tt.want) {26 t.Errorf("Edge(%s, %d, %d) = %s, want %s", tt.from, tt.dc, tt.dr, got, tt.want)27 }28 }29}3031func TestUsedRangeAndStats(t *testing.T) {32 s := New()33 if _, ok := s.UsedRange(); ok {34 t.Error("empty sheet has a used range")35 }36 s.Set(at("B2"), "10")37 s.Set(at("B3"), "32")38 s.Set(at("D1"), "label")39 if r, _ := s.UsedRange(); r.String() != "A1:D3" {40 t.Errorf("UsedRange = %s", r)41 }42 want := Stats{Sum: 42, Count: 3, Nums: 2}43 if got := s.RangeStats(NewRect(at("A1"), at("D3"))); got != want {44 t.Errorf("RangeStats small = %+v", got)45 }46 // Whole columns take the sparse path.47 if got := s.RangeStats(NewRect(at("A1"), at("D8192"))); got != want {48 t.Errorf("RangeStats large = %+v", got)49 }50 // The cached result follows edits, recalculation and undo.51 r := NewRect(at("A1"), at("D3"))52 s.Set(at("C1"), "=B2*2")53 if got := s.RangeStats(r); got != (Stats{Sum: 62, Count: 4, Nums: 3}) {54 t.Errorf("after an edit = %+v", got)55 }56 s.Set(at("B2"), "1")57 if got := s.RangeStats(r); got != (Stats{Sum: 35, Count: 4, Nums: 3}) {58 t.Errorf("after a recalc = %+v", got)59 }60 s.Undo()61 if got := s.RangeStats(r); got != (Stats{Sum: 62, Count: 4, Nums: 3}) {62 t.Errorf("after undo = %+v", got)63 }64}