Explorar o código

Address issue #3 (again) - use `xml:"attr"` instead of "attr" in structs used by xml.Unmarshall. gotest now passes on r59

Geoffrey J. Teale %!s(int64=14) %!d(string=hai) anos
pai
achega
55affccb39
Modificáronse 4 ficheiros con 47 adicións e 46 borrados
  1. 3 3
      sharedstrings.go
  2. 16 16
      workbook.go
  3. 12 12
      worksheet.go
  4. 16 15
      worksheet_test.go

+ 3 - 3
sharedstrings.go

@@ -5,8 +5,8 @@ package xlsx
 // http://schemas.openxmlformats.org/spreadsheetml/2006/main currently
 // I have not checked this for completeness - it does as much as need.
 type XLSXSST struct {
-	Count       string "attr"
-	UniqueCount string "attr"
+	Count       string `xml:"attr"`
+	UniqueCount string `xml:"attr"`
 	SI          []XLSXSI
 }
 
@@ -24,7 +24,7 @@ type XLSXSI struct {
 // currently I have not checked this for completeness - it does as
 // much as I need.
 type XLSXT struct {
-	Data string "chardata"
+	Data string `xml:"chardata"`
 }
 
 

+ 16 - 16
workbook.go

@@ -26,10 +26,10 @@ type XLSXWorkbook struct {
 // - currently I have not checked it for completeness - it does as
 // much as I need.
 type XLSXFileVersion struct {
-	AppName      string "attr"
-	LastEdited   string "attr"
-	LowestEdited string "attr"
-	RupBuild     string "attr"
+	AppName      string `xml:"attr"`
+	LastEdited   string `xml:"attr"`
+	LowestEdited string `xml:"attr"`
+	RupBuild     string `xml:"attr"`
 }
 
 // XLSXWorkbookPr directly maps the workbookPr element from the
@@ -37,7 +37,7 @@ type XLSXFileVersion struct {
 // - currently I have not checked it for completeness - it does as
 // much as I need.
 type XLSXWorkbookPr struct {
-	DefaultThemeVersion string "attr"
+	DefaultThemeVersion string `xml:"attr"`
 }
 
 // XLSXBookViews directly maps the bookViews element from the
@@ -53,10 +53,10 @@ type XLSXBookViews struct {
 // - currently I have not checked it for completeness - it does as
 // much as I need.
 type XLSXWorkBookView struct {
-	XWindow      string "attr"
-	YWindow      string "attr"
-	WindowWidth  string "attr"
-	WindowHeight string "attr"
+	XWindow      string `xml:"attr"`
+	YWindow      string `xml:"attr"`
+	WindowWidth  string `xml:"attr"`
+	WindowHeight string `xml:"attr"`
 }
 
 // XLSXSheets directly maps the sheets element from the namespace
@@ -72,9 +72,9 @@ type XLSXSheets struct {
 // currently I have not checked it for completeness - it does as much
 // as I need.
 type XLSXSheet struct {
-	Name    string "attr"
-	SheetId string "attr"
-	Id      string "attr"
+	Name    string `xml:"attr"`
+	SheetId string `xml:"attr"`
+	Id      string `xml:"attr"`
 }
 
 // XLSXDefinedNames directly maps the definedNames element from the
@@ -91,9 +91,9 @@ type XLSXDefinedNames struct {
 // - currently I have not checked it for completeness - it does as
 // much as I need.
 type XLSXDefinedName struct {
-	Data         string "chardata"
-	Name         string "attr"
-	LocalSheetID string "attr"
+	Data         string `xml:"chardata"`
+	Name         string `xml:"attr"`
+	LocalSheetID string `xml:"attr"`
 }
 
 
@@ -102,7 +102,7 @@ type XLSXDefinedName struct {
 // currently I have not checked it for completeness - it does as much
 // as I need.
 type XLSXCalcPr struct {
-	CalcId string "attr"
+	CalcId string `xml:"attr"`
 }
 
 

+ 12 - 12
worksheet.go

@@ -16,7 +16,7 @@ type XLSXWorksheet struct {
 // currently I have not checked it for completeness - it does as much
 // as I need.
 type XLSXDimension struct {
-	Ref string "attr"
+	Ref string `xml:"attr"`
 }
 
 // XLSXSheetViews directly maps the sheetViews element in the namespace
@@ -32,8 +32,8 @@ type XLSXSheetViews struct {
 // currently I have not checked it for completeness - it does as much
 // as I need.
 type XLSXSheetView struct {
-	TabSelected    string "attr"
-	WorkbookViewID string "attr"
+	TabSelected    string `xml:"attr"`
+	WorkbookViewID string `xml:"attr"`
 	Selection      XLSXSelection
 }
 
@@ -43,8 +43,8 @@ type XLSXSheetView struct {
 // currently I have not checked it for completeness - it does as much
 // as I need.
 type XLSXSelection struct {
-	ActiveCell string "attr"
-	SQRef      string "attr"
+	ActiveCell string `xml:"attr"`
+	SQRef      string `xml:"attr"`
 }
 
 // XLSXSheetFormatPr directly maps the sheetFormatPr element in the namespace
@@ -52,8 +52,8 @@ type XLSXSelection struct {
 // currently I have not checked it for completeness - it does as much
 // as I need.
 type XLSXSheetFormatPr struct {
-	BaseColWidth     string "attr"
-	DefaultRowHeight string "attr"
+	BaseColWidth     string `xml:"attr"`
+	DefaultRowHeight string `xml:"attr"`
 }
 
 // XLSXSheetData directly maps the sheetData element in the namespace
@@ -69,8 +69,8 @@ type XLSXSheetData struct {
 // currently I have not checked it for completeness - it does as much
 // as I need.
 type XLSXRow struct {
-	R     string "attr"
-	Spans string "attr"
+	R     string `xml:"attr"`
+	Spans string `xml:"attr"`
 	C     []XLSXC
 }
 
@@ -79,8 +79,8 @@ type XLSXRow struct {
 // currently I have not checked it for completeness - it does as much
 // as I need.
 type XLSXC struct {
-	R string "attr"
-	T string "attr"
+	R string `xml:"attr"`
+	T string `xml:"attr"`
 	V XLSXV
 }
 
@@ -90,6 +90,6 @@ type XLSXC struct {
 // currently I have not checked it for completeness - it does as much
 // as I need.
 type XLSXV struct {
-	Data string "chardata"
+	Data string `xml:"chardata"`
 }
 

+ 16 - 15
worksheet_test.go

@@ -2,6 +2,7 @@ package xlsx
 
 import (
 	"bytes"
+	"fmt"
 	"testing"
 	"xml"
 )
@@ -18,52 +19,52 @@ func TestUnmarshallWorksheet(t *testing.T) {
 		return
 	}
 	if worksheet.Dimension.Ref != "A1:B2" {
-		t.Error("Expected worksheet.Dimension.Ref == 'A1:B2'")
+		t.Error(fmt.Sprintf("Expected worksheet.Dimension.Ref == 'A1:B2', got %s", worksheet.Dimension.Ref))
 	}
 	if len(worksheet.SheetViews.SheetView) == 0 {
-		t.Error("Expected len(worksheet.SheetViews.SheetView) == 1")
+		t.Error(fmt.Sprintf("Expected len(worksheet.SheetViews.SheetView) == 1, got %d", len(worksheet.SheetViews.SheetView)))
 	}
 	sheetview := worksheet.SheetViews.SheetView[0]
 	if sheetview.TabSelected != "1" {
-		t.Error("Expected sheetview.TabSelected == '1'")
+		t.Error(fmt.Sprintf("Expected sheetview.TabSelected == '1', got %s", sheetview.TabSelected))
 	}
 	if sheetview.WorkbookViewID != "0" {
-		t.Error("Expected sheetview.WorkbookViewID == '0'")
+		t.Error(fmt.Sprintf("Expected sheetview.WorkbookViewID == '0', got %s", sheetview.WorkbookViewID))
 	}
 	if sheetview.Selection.ActiveCell != "C2" {
-		t.Error("Expeceted sheetview.Selection.ActiveCell == 'C2'")
+		t.Error(fmt.Sprintf("Expeceted sheetview.Selection.ActiveCell == 'C2', got %s", sheetview.Selection.ActiveCell))
 	}
 	if sheetview.Selection.SQRef != "C2" {
-		t.Error("Expected sheetview.Selection.SQRef == 'C2'")
+		t.Error(fmt.Sprintf("Expected sheetview.Selection.SQRef == 'C2', got %s", sheetview.Selection.SQRef))
 	}
 	if worksheet.SheetFormatPr.BaseColWidth != "10" {
-		t.Error("Expected worksheet.SheetFormatPr.BaseColWidth == '10'")
+		t.Error(fmt.Sprintf("Expected worksheet.SheetFormatPr.BaseColWidth == '10', got %s", worksheet.SheetFormatPr.BaseColWidth))
 	}
 	if worksheet.SheetFormatPr.DefaultRowHeight != "15" {
-		t.Error("Expected worksheet.SheetFormatPr.DefaultRowHeight == '15'")
+		t.Error(fmt.Sprintf("Expected worksheet.SheetFormatPr.DefaultRowHeight == '15', got %s", worksheet.SheetFormatPr.DefaultRowHeight))
 	}
 	if len(worksheet.SheetData.Row) == 0 {
-		t.Error("Expected len(worksheet.SheetData.Row) == '2'")
+		t.Error(fmt.Sprintf("Expected len(worksheet.SheetData.Row) == '2', got %d", worksheet.SheetData.Row))
 	}
 	row := worksheet.SheetData.Row[0]
 	if row.R != "1" {
-		t.Error("Expected row.r == '1'")
+		t.Error(fmt.Sprintf("Expected row.r == '1', got %s", row.R))
 	}
 	if row.Spans != "1:2" {
-		t.Error("Expected row.Spans == '1:2'")
+		t.Error(fmt.Sprintf("Expected row.Spans == '1:2', got %s", row.Spans))
 	}
 	if len(row.C) != 2 {
-		t.Error("Expected len(row.C) == 2")
+		t.Error(fmt.Sprintf("Expected len(row.C) == 2, got %s", row.C))
 	}
 	c := row.C[0]
 	if c.R != "A1" {
-		t.Error("Expected c.R == 'A1'")
+		t.Error(fmt.Sprintf("Expected c.R == 'A1' got %s", c.R))
 	}
 	if c.T != "s" {
-		t.Error("Expected c.T == 's'")
+		t.Error(fmt.Sprintf("Expected c.T == 's' got %s", c.T))
 	}
 	if c.V.Data != "0" {
-		t.Error("Expected c.V.Data == '0'")
+		t.Error(fmt.Sprintf("Expected c.V.Data == '0', got %s", c.V.Data))
 	}
 
 }