Browse Source

End-to-end test the creation, saving, loading and interrogation of an XLSX file.

Geoffrey J. Teale 11 years ago
parent
commit
fdf1b44e51
1 changed files with 19 additions and 2 deletions
  1. 19 2
      file_test.go

+ 19 - 2
file_test.go

@@ -63,6 +63,7 @@ func (l *FileSuite) TestAddSheet(c *C) {
 	c.Assert(f.Sheets["MySheet"], Equals, sheet)
 	c.Assert(f.Sheets["MySheet"], Equals, sheet)
 }
 }
 
 
+// Test that we can create a Workbook and marshal it to XML. 
 func (l *FileSuite) TestMarshalWorkbook(c *C) {
 func (l *FileSuite) TestMarshalWorkbook(c *C) {
 	var f *File
 	var f *File
 
 
@@ -220,6 +221,7 @@ func (l *FileSuite) TestMarshalFile(c *C) {
 }
 }
 
 
 
 
+// We can save a File as a valid XLSX file at a given path.
 func (l *FileSuite) TestSaveFile(c *C) {
 func (l *FileSuite) TestSaveFile(c *C) {
 	var tmpPath string = c.MkDir()
 	var tmpPath string = c.MkDir()
 	var f *File
 	var f *File
@@ -232,7 +234,22 @@ func (l *FileSuite) TestSaveFile(c *C) {
 	row2 := sheet2.AddRow()
 	row2 := sheet2.AddRow()
 	cell2 := row2.AddCell()
 	cell2 := row2.AddCell()
 	cell2.Value = "A cell!"
 	cell2.Value = "A cell!"
-	tmpPath = "/tmp"
-	err := f.Save(filepath.Join(tmpPath, "TestSaveFile.xlsx"))
+	xlsxPath := filepath.Join(tmpPath, "TestSaveFile.xlsx")
+	err := f.Save(xlsxPath)
 	c.Assert(err, IsNil)
 	c.Assert(err, IsNil)
+
+	// Let's eat our own dog food
+	xlsxFile, err := OpenFile(xlsxPath)
+	c.Assert(err, IsNil)
+	c.Assert(xlsxFile, NotNil)
+	c.Assert(len(xlsxFile.Sheets), Equals, 2)
+
+	sheet1, ok := xlsxFile.Sheets["MySheet"]
+	c.Assert(ok, Equals, true)
+	c.Assert(len(sheet1.Rows), Equals, 1)
+	row1 = sheet1.Rows[0]
+	c.Assert(len(row1.Cells), Equals, 1)
+	cell1 = row1.Cells[0]
+	c.Assert(cell1.Value, Equals, "A cell!")
+	c.Assert(cell1.String(), Equals, "A cell!")
 }
 }