xmlSharedStrings_test.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. package xlsx
  2. import (
  3. "bytes"
  4. "encoding/xml"
  5. . "gopkg.in/check.v1"
  6. )
  7. type SharedStringsSuite struct {
  8. SharedStringsXML *bytes.Buffer
  9. }
  10. var _ = Suite(&SharedStringsSuite{})
  11. func (s *SharedStringsSuite) SetUpTest(c *C) {
  12. s.SharedStringsXML = bytes.NewBufferString(
  13. `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
  14. <sst xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"
  15. count="4"
  16. uniqueCount="4">
  17. <si>
  18. <t>Foo</t>
  19. </si>
  20. <si>
  21. <t>Bar</t>
  22. </si>
  23. <si>
  24. <t xml:space="preserve">Baz </t>
  25. </si>
  26. <si>
  27. <t>Quuk</t>
  28. </si>
  29. </sst>`)
  30. }
  31. // Test we can correctly unmarshal an the sharedstrings.xml file into
  32. // an xlsx.xlsxSST struct and it's associated children.
  33. func (s *SharedStringsSuite) TestUnmarshallSharedStrings(c *C) {
  34. sst := new(xlsxSST)
  35. err := xml.NewDecoder(s.SharedStringsXML).Decode(sst)
  36. c.Assert(err, IsNil)
  37. c.Assert(sst.Count, Equals, 4)
  38. c.Assert(sst.UniqueCount, Equals, 4)
  39. c.Assert(sst.SI, HasLen, 4)
  40. si := sst.SI[0]
  41. c.Assert(si.T, Equals, "Foo")
  42. }