-
Notifications
You must be signed in to change notification settings - Fork 21
/
styles_test.go
82 lines (71 loc) · 1.57 KB
/
styles_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
72
73
74
75
76
77
78
79
80
81
82
package xlsxreader
import (
"testing"
"github.com/stretchr/testify/require"
)
var getFormatCodeTests = []struct {
name string
id int
numberFormats []numberFormat
expected string
}{
{"successful", 123, []numberFormat{{111, "no"}, {123, "dd/MM/YYYY"}}, "dd/MM/YYYY"},
{"not_found", 999, []numberFormat{{111, "no"}, {123, "no"}}, ""},
}
func TestGetFormatCode(t *testing.T) {
for _, test := range getFormatCodeTests {
t.Run(test.name, func(t *testing.T) {
actual := getFormatCode(test.id, test.numberFormats)
require.Equal(t, test.expected, actual)
})
}
}
var dateFormatCodeTests = []struct {
code string
expected bool
}{
{"DD/MM/YYYY", true},
{"hh:mm:ss", true},
{"YYYY-MM-DD", true},
{"000,00,00%", false},
{"potato", false},
{"0;[Red]0", false},
{"[Blue][<=100];[Blue][>100]", false},
{"[mm]:ss", true},
{"[Red]hh:dd;[Red]", true},
{"0.00E+00", false},
{`0.00" YYY"`, false},
{`"Y"YYYY"Y"`, true},
{`0.00\Y`, false},
{`YYYY\YYYYY`, true},
{"", false},
}
func TestIsDateFormatCode(t *testing.T) {
for _, test := range dateFormatCodeTests {
t.Run(test.code, func(t *testing.T) {
actual := isDateFormatCode(test.code)
require.Equal(t, test.expected, actual)
})
}
}
func TestGetDateStylesFromStyleSheet(t *testing.T) {
ss := styleSheet{
NumberFormats: []numberFormat{
{165, "dd/mm/YYYY"},
{170, "00,000"},
},
CellStyles: []cellStyle{
{1},
{14},
{22},
{165},
{170},
},
}
styles := getDateStylesFromStyleSheet(&ss)
require.Equal(t, map[int]bool{
1: true,
2: true,
3: true,
}, *styles)
}