style_test.go 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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, xCellStyleXf, xCellXf := style.makeXLSXStyleElements()
  32. // c.Assert(xNumFmt.NumFmtId, Equals, 164)
  33. // c.Assert(xNumFmt.FormatCode, Equals, "GENERAL")
  34. c.Assert(xFont.Sz.Val, Equals, "12")
  35. c.Assert(xFont.Name.Val, Equals, "Verdana")
  36. c.Assert(xFont.B, NotNil)
  37. c.Assert(xFont.I, NotNil)
  38. c.Assert(xFont.U, NotNil)
  39. c.Assert(xFill.PatternFill.PatternType, Equals, "solid")
  40. c.Assert(xFill.PatternFill.FgColor.RGB, Equals, "00FF0000")
  41. c.Assert(xFill.PatternFill.BgColor.RGB, Equals, "FF000000")
  42. c.Assert(xBorder.Left.Style, Equals, "thin")
  43. c.Assert(xBorder.Right.Style, Equals, "thin")
  44. c.Assert(xBorder.Top.Style, Equals, "thin")
  45. c.Assert(xBorder.Bottom.Style, Equals, "thin")
  46. c.Assert(xCellStyleXf.ApplyBorder, Equals, true)
  47. c.Assert(xCellStyleXf.ApplyFill, Equals, true)
  48. c.Assert(xCellStyleXf.ApplyFont, Equals, true)
  49. c.Assert(xCellXf.ApplyBorder, Equals, true)
  50. c.Assert(xCellXf.ApplyFill, Equals, true)
  51. c.Assert(xCellXf.ApplyFont, Equals, true)
  52. }
  53. type FontSuite struct{}
  54. var _ = Suite(&FontSuite{})
  55. func (s *FontSuite) TestNewFont(c *C) {
  56. font := NewFont(12, "Verdana")
  57. c.Assert(font, NotNil)
  58. c.Assert(font.Name, Equals, "Verdana")
  59. c.Assert(font.Size, Equals, 12)
  60. }