-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstyle_test.go
80 lines (75 loc) · 1.71 KB
/
style_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
package xlsxtra_test
import (
"testing"
"github.com/stanim/xlsxtra"
"github.com/tealeg/xlsx"
)
func checkStyle(t *testing.T, row *xlsxtra.Row) {
style := xlsxtra.NewStyle(
"", // color
&xlsx.Font{Size: 10, Name: "Arial", Bold: true},
xlsx.NewBorder("thin", "thin", "thin", "thin"),
&xlsx.Alignment{
Horizontal: "general",
Indent: 0,
ShrinkToFit: false,
TextRotation: 0,
Vertical: "top",
WrapText: false,
},
)
if style.ApplyFill {
t.Fatal("NewStyle: ApplyFill not expected")
}
if !style.ApplyFont {
t.Fatal("NewStyle: ApplyFont expected")
}
if !style.ApplyBorder {
t.Fatal("NewStyle: ApplyBorder expected")
}
if !style.ApplyAlignment {
t.Fatal("NewStyle: ApplyAlignment expected")
}
row.SetStyle(style)
for _, cell := range row.Cells {
style = cell.GetStyle()
if style.ApplyFill {
t.Fatal("NewStyle: ApplyFill not expected")
}
if !style.ApplyFont {
t.Fatal("NewStyle: ApplyFont expected")
}
if !style.ApplyBorder {
t.Fatal("NewStyle: ApplyBorder expected")
}
if !style.ApplyAlignment {
t.Fatal("NewStyle: ApplyAlignment expected")
}
}
}
func TestNewStyle(t *testing.T) {
sheet, err := xlsxtra.NewFile().AddSheet("Sheet1")
if err != nil {
t.Fatal(err)
}
row := sheet.AddRow()
row.AddString("foo")
row.AddInt(2)
checkStyle(t, row)
}
func TestNewStyles(t *testing.T) {
rgb := []string{"00ff0000", "0000ff00", "000000ff"}
styles := xlsxtra.NewStyles(rgb, nil, nil, nil)
sGot := styles[0].Fill.FgColor
sWant := rgb[0]
if sGot != sWant {
t.Fatalf("NewStyles: got %q; want %q", sGot, sWant)
}
bGot := styles[0].ApplyFill
bWant := true
if bGot != bWant {
t.Fatalf(
"NewStyles: ApplyFill got \"%v\"; want \"%v\"",
bGot, bWant)
}
}