Browse Source

Test xlsxXf.Equals.

Geoffrey J. Teale 11 years ago
parent
commit
eb8f638a2e
2 changed files with 60 additions and 7 deletions
  1. 5 5
      xmlStyle.go
  2. 55 2
      xmlStyle_test.go

+ 5 - 5
xmlStyle.go

@@ -634,7 +634,7 @@ type xlsxXf struct {
 	FillId          int           `xml:"fillId,attr"`
 	FontId          int           `xml:"fontId,attr"`
 	NumFmtId        int           `xml:"numFmtId,attr"`
-	alignment       xlsxAlignment `xml:"alignment"`
+	Alignment       xlsxAlignment `xml:"alignment"`
 }
 
 func (xf *xlsxXf) Equals(other xlsxXf) bool {
@@ -647,17 +647,17 @@ func (xf *xlsxXf) Equals(other xlsxXf) bool {
 		xf.FillId == other.FillId &&
 		xf.FontId == other.FontId &&
 		xf.NumFmtId == other.NumFmtId &&
-		xf.alignment.Equals(other.alignment)
+		xf.Alignment.Equals(other.Alignment)
 }
 
 func (xf *xlsxXf) Marshal(outputBorderMap, outputFillMap, outputFontMap map[int]int) (result string, err error) {
-	var xalignment string
+	var xAlignment string
 	result = fmt.Sprintf(`<xf applyAlignment="%b" applyBorder="%b" applyFont="%b" applyFill="%b" applyProtection="%b" borderId="%d" fillId="%d" fontId="%d" numFmtId="%d">`, bool2Int(xf.ApplyAlignment), bool2Int(xf.ApplyBorder), bool2Int(xf.ApplyFont), bool2Int(xf.ApplyFill), bool2Int(xf.ApplyProtection), outputBorderMap[xf.BorderId], outputFillMap[xf.FillId], outputFontMap[xf.FontId], xf.NumFmtId)
-	xalignment, err = xf.alignment.Marshal()
+	xAlignment, err = xf.Alignment.Marshal()
 	if err != nil {
 		return
 	}
-	result += xalignment
+	result += xAlignment
 	result += `</xf>`
 	return
 }

+ 55 - 2
xmlStyle_test.go

@@ -90,7 +90,7 @@ func (x *XMLStyleSuite) TestMarshalXlsxStyleSheetWithACellStyleXf(c *C) {
 	xf.FillId = 0
 	xf.FontId = 0
 	xf.NumFmtId = 0
-	xf.alignment = xlsxAlignment{
+	xf.Alignment = xlsxAlignment{
 		Horizontal:   "left",
 		Indent:       1,
 		ShrinkToFit:  true,
@@ -123,7 +123,7 @@ func (x *XMLStyleSuite) TestMarshalXlsxStyleSheetWithACellXf(c *C) {
 	xf.FillId = 0
 	xf.FontId = 0
 	xf.NumFmtId = 0
-	xf.alignment = xlsxAlignment{
+	xf.Alignment = xlsxAlignment{
 		Horizontal:   "left",
 		Indent:       1,
 		ShrinkToFit:  true,
@@ -230,3 +230,56 @@ func (x *XMLStyleSuite) TestBorderEquals(c *C) {
 	// for sanity
 	c.Assert(borderA.Equals(borderB), Equals, true)
 }
+
+func (x *XMLStyleSuite) TestXfEquals(c *C) {
+	xfA := xlsxXf{
+		ApplyAlignment:  true,
+		ApplyBorder:     true,
+		ApplyFont:       true,
+		ApplyFill:       true,
+		ApplyProtection: true,
+		BorderId:        0,
+		FillId:          0,
+		FontId:          0,
+		NumFmtId:        0}
+	xfB := xlsxXf{
+		ApplyAlignment:  true,
+		ApplyBorder:     true,
+		ApplyFont:       true,
+		ApplyFill:       true,
+		ApplyProtection: true,
+		BorderId:        0,
+		FillId:          0,
+		FontId:          0,
+		NumFmtId:        0}
+	c.Assert(xfA.Equals(xfB), Equals, true)
+	xfB.ApplyAlignment = false
+	c.Assert(xfA.Equals(xfB), Equals, false)
+	xfB.ApplyAlignment = true
+	xfB.ApplyBorder = false
+	c.Assert(xfA.Equals(xfB), Equals, false)
+	xfB.ApplyBorder = true
+	xfB.ApplyFont = false
+	c.Assert(xfA.Equals(xfB), Equals, false)
+	xfB.ApplyFont = true
+	xfB.ApplyFill = false
+	c.Assert(xfA.Equals(xfB), Equals, false)
+	xfB.ApplyFill = true
+	xfB.ApplyProtection = false
+	c.Assert(xfA.Equals(xfB), Equals, false)
+	xfB.ApplyProtection = true
+	xfB.BorderId = 1
+	c.Assert(xfA.Equals(xfB), Equals, false)
+	xfB.BorderId = 0
+	xfB.FillId = 1
+	c.Assert(xfA.Equals(xfB), Equals, false)
+	xfB.FillId = 0
+	xfB.FontId = 1
+	c.Assert(xfA.Equals(xfB), Equals, false)
+	xfB.FontId = 0
+	xfB.NumFmtId = 1
+	c.Assert(xfA.Equals(xfB), Equals, false)
+	xfB.NumFmtId = 0
+	// for sanity
+	c.Assert(xfA.Equals(xfB), Equals, true)
+}