style_test.go 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. package xlsx
  2. import (
  3. . "gopkg.in/check.v1"
  4. )
  5. type StyleSuite struct{}
  6. var _ = Suite(&StyleSuite{})
  7. func (s *StyleSuite) TestNewStyle(c *C) {
  8. style := NewStyle()
  9. c.Assert(style, NotNil)
  10. }
  11. func (s *StyleSuite) TestNewStyleDefaultts(c *C) {
  12. style := NewStyle()
  13. c.Assert(style.Font, Equals, *DefaultFont())
  14. c.Assert(style.Fill, Equals, *DefaultFill())
  15. c.Assert(style.Border, Equals, *DefaultBorder())
  16. }
  17. func (s *StyleSuite) TestMakeXLSXStyleElements(c *C) {
  18. style := NewStyle()
  19. font := *NewFont(12, "Verdana")
  20. font.Bold = true
  21. font.Italic = true
  22. font.Underline = true
  23. style.Font = font
  24. fill := *NewFill("solid", "00FF0000", "FF000000")
  25. style.Fill = fill
  26. border := *NewBorder("thin", "thin", "thin", "thin")
  27. style.Border = border
  28. style.ApplyBorder = true
  29. style.ApplyFill = true
  30. style.ApplyFont = true
  31. xFont, xFill, xBorder, xCellXf := style.makeXLSXStyleElements()
  32. c.Assert(xFont.Sz.Val, Equals, "12")
  33. c.Assert(xFont.Name.Val, Equals, "Verdana")
  34. c.Assert(xFont.B, NotNil)
  35. c.Assert(xFont.I, NotNil)
  36. c.Assert(xFont.U, NotNil)
  37. c.Assert(xFill.PatternFill.PatternType, Equals, "solid")
  38. c.Assert(xFill.PatternFill.FgColor.RGB, Equals, "00FF0000")
  39. c.Assert(xFill.PatternFill.BgColor.RGB, Equals, "FF000000")
  40. c.Assert(xBorder.Left.Style, Equals, "thin")
  41. c.Assert(xBorder.Right.Style, Equals, "thin")
  42. c.Assert(xBorder.Top.Style, Equals, "thin")
  43. c.Assert(xBorder.Bottom.Style, Equals, "thin")
  44. c.Assert(xCellXf.ApplyBorder, Equals, true)
  45. c.Assert(xCellXf.ApplyFill, Equals, true)
  46. c.Assert(xCellXf.ApplyFont, Equals, true)
  47. }
  48. type FontSuite struct{}
  49. var _ = Suite(&FontSuite{})
  50. func (s *FontSuite) TestNewFont(c *C) {
  51. font := NewFont(12, "Verdana")
  52. c.Assert(font, NotNil)
  53. c.Assert(font.Name, Equals, "Verdana")
  54. c.Assert(font.Size, Equals, 12)
  55. }