Skip to content

Commit e28de17

Browse files
committed
Update go test.
1 parent c5cffaa commit e28de17

File tree

1 file changed

+51
-39
lines changed

1 file changed

+51
-39
lines changed

Diff for: excelize_test.go

+51-39
Original file line numberDiff line numberDiff line change
@@ -6,65 +6,77 @@ import (
66
)
77

88
func TestExcelize(t *testing.T) {
9-
// Test update a XLSX file
10-
file, err := OpenFile("./test/Workbook1.xlsx")
9+
// Test update a XLSX file.
10+
f1, err := OpenFile("./test/Workbook1.xlsx")
1111
if err != nil {
1212
t.Log(err)
1313
}
14-
file.UpdateLinkedValue()
15-
file.SetCellInt("SHEET2", "A1", 100)
16-
file.SetCellStr("SHEET2", "C11", "Knowns")
17-
file.NewSheet(3, "TestSheet")
18-
file.SetCellInt("Sheet3", "A23", 10)
19-
file.SetCellStr("SHEET3", "b230", "10")
20-
file.SetCellStr("SHEET10", "b230", "10")
21-
file.SetActiveSheet(2)
22-
// Test read cell value with given illegal rows number
23-
file.GetCellValue("Sheet2", "a-1")
24-
// Test read cell value with given lowercase column number
25-
file.GetCellValue("Sheet2", "a5")
26-
file.GetCellValue("Sheet2", "C11")
27-
file.GetCellValue("Sheet2", "D11")
28-
file.GetCellValue("Sheet2", "D12")
29-
// Test SetCellValue function
30-
file.SetCellValue("Sheet2", "F1", "Hello")
31-
file.SetCellValue("Sheet2", "G1", []byte("World"))
32-
file.SetCellValue("Sheet2", "F2", 42)
33-
file.SetCellValue("Sheet2", "G2", nil)
34-
// Test read cell value with given axis large than exists row
35-
file.GetCellValue("Sheet2", "E13")
14+
f1.UpdateLinkedValue()
15+
f1.SetCellInt("SHEET2", "A1", 100)
16+
f1.SetCellStr("SHEET2", "C11", "Knowns")
17+
f1.NewSheet(3, "TestSheet")
18+
f1.SetCellInt("Sheet3", "A23", 10)
19+
f1.SetCellStr("SHEET3", "b230", "10")
20+
f1.SetCellStr("SHEET10", "b230", "10")
21+
f1.SetActiveSheet(2)
22+
// Test read cell value with given illegal rows number.
23+
f1.GetCellValue("Sheet2", "a-1")
24+
// Test read cell value with given lowercase column number.
25+
f1.GetCellValue("Sheet2", "a5")
26+
f1.GetCellValue("Sheet2", "C11")
27+
f1.GetCellValue("Sheet2", "D11")
28+
f1.GetCellValue("Sheet2", "D12")
29+
// Test SetCellValue function.
30+
f1.SetCellValue("Sheet2", "F1", "Hello")
31+
f1.SetCellValue("Sheet2", "G1", []byte("World"))
32+
f1.SetCellValue("Sheet2", "F2", 42)
33+
f1.SetCellValue("Sheet2", "G2", nil)
34+
// Test read cell value with given axis large than exists row.
35+
f1.GetCellValue("Sheet2", "E13")
3636

3737
for i := 1; i <= 300; i++ {
38-
file.SetCellStr("SHEET3", "c"+strconv.Itoa(i), strconv.Itoa(i))
38+
f1.SetCellStr("SHEET3", "c"+strconv.Itoa(i), strconv.Itoa(i))
3939
}
40-
err = file.Save()
40+
err = f1.Save()
4141
if err != nil {
4242
t.Log(err)
4343
}
44-
// Test write file to given path
45-
err = file.WriteTo("./test/Workbook_2.xlsx")
44+
// Test write file to given path.
45+
err = f1.WriteTo("./test/Workbook_2.xlsx")
4646
if err != nil {
4747
t.Log(err)
4848
}
49-
// Test write file to not exist directory
50-
err = file.WriteTo("")
49+
// Test write file to not exist directory.
50+
err = f1.WriteTo("")
5151
if err != nil {
5252
t.Log(err)
5353
}
5454

55-
// Test create a XLSX file
56-
file2 := CreateFile()
57-
file2.NewSheet(2, "XLSXSheet2")
58-
file2.NewSheet(3, "XLSXSheet3")
59-
file2.SetCellInt("Sheet2", "A23", 56)
60-
file2.SetCellStr("SHEET1", "B20", "42")
61-
file2.SetActiveSheet(0)
62-
err = file2.WriteTo("./test/Workbook_3.xlsx")
55+
// Test write file with broken file struct.
56+
f2 := File{}
57+
err = f2.Save()
58+
if err != nil {
59+
t.Log(err)
60+
}
61+
// Test write file with broken file struct with given path.
62+
err = f2.WriteTo("./test/Workbook_3.xlsx")
63+
if err != nil {
64+
t.Log(err)
65+
}
66+
67+
// Test create a XLSX file.
68+
f3 := CreateFile()
69+
f3.NewSheet(2, "XLSXSheet2")
70+
f3.NewSheet(3, "XLSXSheet3")
71+
f3.SetCellInt("Sheet2", "A23", 56)
72+
f3.SetCellStr("SHEET1", "B20", "42")
73+
f3.SetActiveSheet(0)
74+
err = f3.WriteTo("./test/Workbook_3.xlsx")
6375
if err != nil {
6476
t.Log(err)
6577
}
6678

67-
// Test open a XLSX file with given illegal path
79+
// Test open a XLSX file with given illegal path.
6880
_, err = OpenFile("./test/Workbook.xlsx")
6981
if err != nil {
7082
t.Log(err)

0 commit comments

Comments
 (0)