package xlsx import ( "bytes" "encoding/xml" "fmt" "testing" ) // Test we can succesfully unmarshal the sheetN.xml files within and // XLSX file into an xlsxWorksheet struct (and it's related children). func TestUnmarshallWorksheet(t *testing.T) { var sheetxml = bytes.NewBufferString(` `) worksheet := new(xlsxWorksheet) error := xml.NewDecoder(sheetxml).Decode(worksheet) if error != nil { t.Error(error.Error()) return } if worksheet.Dimension.Ref != "A1:B2" { t.Error(fmt.Sprintf("Expected worksheet.Dimension.Ref == 'A1:B2', got %s", worksheet.Dimension.Ref)) } if len(worksheet.SheetData.Row) == 0 { t.Error(fmt.Sprintf("Expected len(worksheet.SheetData.Row) == '2', got %d", worksheet.SheetData.Row)) } row := worksheet.SheetData.Row[0] if row.R != 1 { t.Error(fmt.Sprintf("Expected row.r == 1, got %d", row.R)) } if len(row.C) != 2 { t.Error(fmt.Sprintf("Expected len(row.C) == 2, got %s", row.C)) } c := row.C[0] if c.R != "A1" { t.Error(fmt.Sprintf("Expected c.R == 'A1' got %s", c.R)) } if c.T != "s" { t.Error(fmt.Sprintf("Expected c.T == 's' got %s", c.T)) } if c.V != "0" { t.Error(fmt.Sprintf("Expected c.V.Data == '0', got %s", c.V)) } }