Bladeren bron

Update go test.

Ri Xu 9 jaren geleden
bovenliggende
commit
e28de172c6
1 gewijzigde bestanden met toevoegingen van 51 en 39 verwijderingen
  1. 51 39
      excelize_test.go

+ 51 - 39
excelize_test.go

@@ -6,65 +6,77 @@ import (
 )
 
 func TestExcelize(t *testing.T) {
-	// Test update a XLSX file
-	file, err := OpenFile("./test/Workbook1.xlsx")
+	// Test update a XLSX file.
+	f1, err := OpenFile("./test/Workbook1.xlsx")
 	if err != nil {
 		t.Log(err)
 	}
-	file.UpdateLinkedValue()
-	file.SetCellInt("SHEET2", "A1", 100)
-	file.SetCellStr("SHEET2", "C11", "Knowns")
-	file.NewSheet(3, "TestSheet")
-	file.SetCellInt("Sheet3", "A23", 10)
-	file.SetCellStr("SHEET3", "b230", "10")
-	file.SetCellStr("SHEET10", "b230", "10")
-	file.SetActiveSheet(2)
-	// Test read cell value with given illegal rows number
-	file.GetCellValue("Sheet2", "a-1")
-	// Test read cell value with given lowercase column number
-	file.GetCellValue("Sheet2", "a5")
-	file.GetCellValue("Sheet2", "C11")
-	file.GetCellValue("Sheet2", "D11")
-	file.GetCellValue("Sheet2", "D12")
-	// Test SetCellValue function
-	file.SetCellValue("Sheet2", "F1", "Hello")
-	file.SetCellValue("Sheet2", "G1", []byte("World"))
-	file.SetCellValue("Sheet2", "F2", 42)
-	file.SetCellValue("Sheet2", "G2", nil)
-	// Test read cell value with given axis large than exists row
-	file.GetCellValue("Sheet2", "E13")
+	f1.UpdateLinkedValue()
+	f1.SetCellInt("SHEET2", "A1", 100)
+	f1.SetCellStr("SHEET2", "C11", "Knowns")
+	f1.NewSheet(3, "TestSheet")
+	f1.SetCellInt("Sheet3", "A23", 10)
+	f1.SetCellStr("SHEET3", "b230", "10")
+	f1.SetCellStr("SHEET10", "b230", "10")
+	f1.SetActiveSheet(2)
+	// Test read cell value with given illegal rows number.
+	f1.GetCellValue("Sheet2", "a-1")
+	// Test read cell value with given lowercase column number.
+	f1.GetCellValue("Sheet2", "a5")
+	f1.GetCellValue("Sheet2", "C11")
+	f1.GetCellValue("Sheet2", "D11")
+	f1.GetCellValue("Sheet2", "D12")
+	// Test SetCellValue function.
+	f1.SetCellValue("Sheet2", "F1", "Hello")
+	f1.SetCellValue("Sheet2", "G1", []byte("World"))
+	f1.SetCellValue("Sheet2", "F2", 42)
+	f1.SetCellValue("Sheet2", "G2", nil)
+	// Test read cell value with given axis large than exists row.
+	f1.GetCellValue("Sheet2", "E13")
 
 	for i := 1; i <= 300; i++ {
-		file.SetCellStr("SHEET3", "c"+strconv.Itoa(i), strconv.Itoa(i))
+		f1.SetCellStr("SHEET3", "c"+strconv.Itoa(i), strconv.Itoa(i))
 	}
-	err = file.Save()
+	err = f1.Save()
 	if err != nil {
 		t.Log(err)
 	}
-	// Test write file to given path
-	err = file.WriteTo("./test/Workbook_2.xlsx")
+	// Test write file to given path.
+	err = f1.WriteTo("./test/Workbook_2.xlsx")
 	if err != nil {
 		t.Log(err)
 	}
-	// Test write file to not exist directory
-	err = file.WriteTo("")
+	// Test write file to not exist directory.
+	err = f1.WriteTo("")
 	if err != nil {
 		t.Log(err)
 	}
 
-	// Test create a XLSX file
-	file2 := CreateFile()
-	file2.NewSheet(2, "XLSXSheet2")
-	file2.NewSheet(3, "XLSXSheet3")
-	file2.SetCellInt("Sheet2", "A23", 56)
-	file2.SetCellStr("SHEET1", "B20", "42")
-	file2.SetActiveSheet(0)
-	err = file2.WriteTo("./test/Workbook_3.xlsx")
+	// Test write file with broken file struct.
+	f2 := File{}
+	err = f2.Save()
+	if err != nil {
+		t.Log(err)
+	}
+	// Test write file with broken file struct with given path.
+	err = f2.WriteTo("./test/Workbook_3.xlsx")
+	if err != nil {
+		t.Log(err)
+	}
+
+	// Test create a XLSX file.
+	f3 := CreateFile()
+	f3.NewSheet(2, "XLSXSheet2")
+	f3.NewSheet(3, "XLSXSheet3")
+	f3.SetCellInt("Sheet2", "A23", 56)
+	f3.SetCellStr("SHEET1", "B20", "42")
+	f3.SetActiveSheet(0)
+	err = f3.WriteTo("./test/Workbook_3.xlsx")
 	if err != nil {
 		t.Log(err)
 	}
 
-	// Test open a XLSX file with given illegal path
+	// Test open a XLSX file with given illegal path.
 	_, err = OpenFile("./test/Workbook.xlsx")
 	if err != nil {
 		t.Log(err)