From f8e6fa24ec00c94b75e969c8a09d78a337134b83 Mon Sep 17 00:00:00 2001 From: "Geoffrey J. Teale" Date: Sat, 1 Nov 2014 01:03:02 +0100 Subject: [PATCH] Split sharedstrings.go and renamed to reftable.go and xmlSharedStrings.go --- sharedstrings.go => reftable.go | 31 --------------- sharedstrings_test.go => reftable_test.go | 36 ++++++----------- xmlSharedStrings.go | 32 +++++++++++++++ xmlSharedStrings_test.go | 48 +++++++++++++++++++++++ 4 files changed, 92 insertions(+), 55 deletions(-) rename sharedstrings.go => reftable.go (67%) rename sharedstrings_test.go => reftable_test.go (75%) create mode 100644 xmlSharedStrings.go create mode 100644 xmlSharedStrings_test.go 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") +}