diff --git a/sharedstrings.go b/reftable.go similarity index 67% rename from sharedstrings.go rename to reftable.go index f56f3aed..8739dc71 100644 --- a/sharedstrings.go +++ b/reftable.go @@ -1,36 +1,5 @@ package xlsx -import ( - "encoding/xml" -) - -// xlsxSST directly maps the sst element from the namespace -// http://schemas.openxmlformats.org/spreadsheetml/2006/main currently -// I have not checked this for completeness - it does as much as I need. -type xlsxSST struct { - XMLName xml.Name `xml:"http://schemas.openxmlformats.org/spreadsheetml/2006/main sst"` - Count int `xml:"count,attr"` - UniqueCount int `xml:"uniqueCount,attr"` - SI []xlsxSI `xml:"si"` -} - -// xlsxSI directly maps the si element from the namespace -// http://schemas.openxmlformats.org/spreadsheetml/2006/main - -// currently I have not checked this for completeness - it does as -// much as I need. -type xlsxSI struct { - T string `xml:"t"` - R []xlsxR `xml:"r"` -} - -// xlsxR directly maps the r element from the namespace -// http://schemas.openxmlformats.org/spreadsheetml/2006/main - -// currently I have not checked this for completeness - it does as -// much as I need. -type xlsxR struct { - T string `xml:"t"` -} - type RefTable struct { indexedStrings []string knownStrings map[string]int diff --git a/sharedstrings_test.go b/reftable_test.go similarity index 75% rename from sharedstrings_test.go rename to reftable_test.go index e8428a11..a6d50090 100644 --- a/sharedstrings_test.go +++ b/reftable_test.go @@ -3,16 +3,17 @@ package xlsx import ( "bytes" "encoding/xml" + . "gopkg.in/check.v1" ) -type SharedStringsSuite struct { +type RefTableSuite struct { SharedStringsXML *bytes.Buffer } -var _ = Suite(&SharedStringsSuite{}) +var _ = Suite(&RefTableSuite{}) -func (s *SharedStringsSuite) SetUpTest(c *C) { +func (s *RefTableSuite) SetUpTest(c *C) { s.SharedStringsXML = bytes.NewBufferString( ` + + + Foo + + + Bar + + + Baz + + + Quuk + + `) +} + +// Test we can correctly unmarshal an the sharedstrings.xml file into +// an xlsx.xlsxSST struct and it's associated children. +func (s *SharedStringsSuite) TestUnmarshallSharedStrings(c *C) { + sst := new(xlsxSST) + err := xml.NewDecoder(s.SharedStringsXML).Decode(sst) + c.Assert(err, IsNil) + c.Assert(sst.Count, Equals, 4) + c.Assert(sst.UniqueCount, Equals, 4) + c.Assert(sst.SI, HasLen, 4) + si := sst.SI[0] + c.Assert(si.T, Equals, "Foo") +}