forked from pcarleton/sheets
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcell_test.go
69 lines (59 loc) · 1.32 KB
/
cell_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package sheets
import (
"testing"
)
var posTests = []struct {
pos CellPos
expected string
}{
{CellPos{0, 0}, "A1"},
{CellPos{1, 0}, "A2"},
{CellPos{0, 1}, "B1"},
{CellPos{1, 1}, "B2"},
{CellPos{10, 10}, "K11"},
{CellPos{0, 25}, "Z1"},
{CellPos{0, 26}, "AA1"},
{CellPos{0, 27}, "AB1"},
{CellPos{0, 52}, "BA1"},
{CellPos{0, 624}, "XA1"},
{CellPos{0, 650}, "YA1"},
{CellPos{0, 675}, "YZ1"},
{CellPos{0, 701}, "ZZ1"},
{CellPos{0, 702}, "AAA1"},
}
func TestCellPosA1Notation(t *testing.T) {
for _, tt := range posTests {
got := tt.pos.A1Notation()
if got != tt.expected {
t.Errorf("Wanted %s, but got %s for %v", tt.expected, got, tt.pos)
}
}
}
var rangeTests = []struct {
topLeft CellPos
width int
height int
expected string
}{
{CellPos{}, 1, 1, "A1:A1"},
{CellPos{}, 1, 2, "A1:A2"},
{CellPos{}, 2, 2, "A1:B2"},
{CellPos{0, 10}, 2, 2, "K1:L2"},
{CellPos{10, 3}, 2, 3, "D11:E13"},
}
func TestRange(t *testing.T) {
for _, tt := range rangeTests {
var data [][]interface{}
for i := 0; i < tt.height; i++ {
var row []interface{}
for j := 0; j < tt.width; j++ {
row = append(row, "1")
}
data = append(data, row)
}
got := tt.topLeft.RangeForData(data).String()
if got != tt.expected {
t.Errorf("Wanted %s, but got %s for %+v, table: %v", tt.expected, got, tt, data)
}
}
}