forked from unidoc/unioffice
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparse_test.go
71 lines (63 loc) · 1.66 KB
/
parse_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
70
71
// Copyright 2017 Baliance. All rights reserved.
//
// Use of this source code is governed by the terms of the Affero GNU General
// Public License version 3.0 as published by the Free Software Foundation and
// appearing in the file LICENSE included in the packaging of this file. A
// commercial license can be purchased by contacting [email protected].
package spreadsheet_test
import (
"testing"
"baliance.com/gooxml/spreadsheet"
)
func TestParseCellReference(t *testing.T) {
td := []struct {
Inp string
ExpCol string
ExpRow uint32
HasError bool
}{
{"A1", "A", 1, false},
{"B25", "B", 25, false},
{"AZ9", "AZ", 9, false},
{"A", "", 0, true},
{"1", "", 0, true},
}
for _, tc := range td {
col, row, err := spreadsheet.ParseCellReference(tc.Inp)
if tc.HasError {
if err == nil {
t.Errorf("expected error for input %s", tc.Inp)
}
} else if err != nil {
t.Errorf("expected no error for input %s, got %s", tc.Inp, err)
}
if col != tc.ExpCol {
t.Errorf("expected col = %s for %s, got %s", tc.ExpCol, tc.Inp, col)
}
if row != tc.ExpRow {
t.Errorf("expected row = %d for %s, got %d", tc.ExpRow, tc.Inp, row)
}
}
}
func TestColumnToIndex(t *testing.T) {
td := []struct {
Inp string
ExpIndex uint32
}{
{"A", 0},
{"B", 1},
{"Z", 25},
{"AA", 26},
{"AB", 27},
{"AC", 28},
{"GOOXML", 90304485},
}
for _, tc := range td {
if got := spreadsheet.ColumnToIndex(tc.Inp); got != tc.ExpIndex {
t.Errorf("expected %s = %d, got %d", tc.Inp, tc.ExpIndex, got)
}
if got := spreadsheet.IndexToColumn(tc.ExpIndex); got != tc.Inp {
t.Errorf("expected %d = %s, got %s", tc.ExpIndex, tc.Inp, got)
}
}
}