Geoffrey J. Teale 6 years ago
parent
commit
d9a28ac759
5 changed files with 54 additions and 54 deletions
  1. 34 34
      col_test.go
  2. 8 8
      date.go
  3. 2 2
      stream_file_builder.go
  4. 9 9
      stream_style_test.go
  5. 1 1
      write.go

+ 34 - 34
col_test.go

@@ -106,7 +106,7 @@ func TestMakeWay(t *testing.T) {
 
 	// Col1: |--|
 	// Col2:    |--|
-	assertWayMade([]*Col{&Col{Min: 1, Max: 2}, &Col{Min: 3, Max: 4}},
+	assertWayMade([]*Col{{Min: 1, Max: 2}, {Min: 3, Max: 4}},
 		func(cs *ColStore) {
 			c.Assert(cs.Len, qt.Equals, 2)
 			root := cs.Root
@@ -123,7 +123,7 @@ func TestMakeWay(t *testing.T) {
 
 	// Col1:    |--|
 	// Col2: |--|
-	assertWayMade([]*Col{&Col{Min: 3, Max: 4}, &Col{Min: 1, Max: 2}},
+	assertWayMade([]*Col{{Min: 3, Max: 4}, {Min: 1, Max: 2}},
 		func(cs *ColStore) {
 			root := cs.Root
 			c.Assert(cs.Len, qt.Equals, 2)
@@ -140,7 +140,7 @@ func TestMakeWay(t *testing.T) {
 
 	// Col1: |--x|
 	// Col2:   |--|
-	assertWayMade([]*Col{&Col{Min: 1, Max: 3}, &Col{Min: 3, Max: 4}},
+	assertWayMade([]*Col{{Min: 1, Max: 3}, {Min: 3, Max: 4}},
 		func(cs *ColStore) {
 			root := cs.Root
 			c.Assert(cs.Len, qt.Equals, 2)
@@ -157,7 +157,7 @@ func TestMakeWay(t *testing.T) {
 
 	// Col1:  |x-|
 	// Col2: |--|
-	assertWayMade([]*Col{&Col{Min: 2, Max: 3}, &Col{Min: 1, Max: 2}},
+	assertWayMade([]*Col{{Min: 2, Max: 3}, {Min: 1, Max: 2}},
 		func(cs *ColStore) {
 			root := cs.Root
 			c.Assert(cs.Len, qt.Equals, 2)
@@ -174,7 +174,7 @@ func TestMakeWay(t *testing.T) {
 
 	// Col1: |---xx---|
 	// Col2:    |--|
-	assertWayMade([]*Col{&Col{Min: 1, Max: 8}, &Col{Min: 4, Max: 5}},
+	assertWayMade([]*Col{{Min: 1, Max: 8}, {Min: 4, Max: 5}},
 		func(cs *ColStore) {
 			root := cs.Root
 			c.Assert(cs.Len, qt.Equals, 3)
@@ -196,7 +196,7 @@ func TestMakeWay(t *testing.T) {
 
 	// Col1: |xx|
 	// Col2: |--|
-	assertWayMade([]*Col{&Col{Min: 1, Max: 2, Width: 40.1}, &Col{Min: 1, Max: 2, Width: 10.0}},
+	assertWayMade([]*Col{{Min: 1, Max: 2, Width: 40.1}, {Min: 1, Max: 2, Width: 10.0}},
 		func(cs *ColStore) {
 			root := cs.Root
 			c.Assert(cs.Len, qt.Equals, 1)
@@ -211,7 +211,7 @@ func TestMakeWay(t *testing.T) {
 
 	// Col1:  |xx|
 	// Col2: |----|
-	assertWayMade([]*Col{&Col{Min: 2, Max: 3, Width: 40.1}, &Col{Min: 1, Max: 4, Width: 10.0}},
+	assertWayMade([]*Col{{Min: 2, Max: 3, Width: 40.1}, {Min: 1, Max: 4, Width: 10.0}},
 		func(cs *ColStore) {
 			root := cs.Root
 			c.Assert(cs.Len, qt.Equals, 1)
@@ -226,7 +226,7 @@ func TestMakeWay(t *testing.T) {
 	// Col1: |--|
 	// Col2:    |--|
 	// Col3:       |--|
-	assertWayMade([]*Col{&Col{Min: 1, Max: 2}, &Col{Min: 3, Max: 4}, &Col{Min: 5, Max: 6}},
+	assertWayMade([]*Col{{Min: 1, Max: 2}, {Min: 3, Max: 4}, {Min: 5, Max: 6}},
 		func(cs *ColStore) {
 			root := cs.Root
 			c.Assert(cs.Len, qt.Equals, 3)
@@ -249,7 +249,7 @@ func TestMakeWay(t *testing.T) {
 	// Col1:       |--|
 	// Col2:    |--|
 	// Col3: |--|
-	assertWayMade([]*Col{&Col{Min: 5, Max: 6}, &Col{Min: 3, Max: 4}, &Col{Min: 1, Max: 2}},
+	assertWayMade([]*Col{{Min: 5, Max: 6}, {Min: 3, Max: 4}, {Min: 1, Max: 2}},
 		func(cs *ColStore) {
 			root := cs.Root
 			c.Assert(cs.Len, qt.Equals, 3)
@@ -272,7 +272,7 @@ func TestMakeWay(t *testing.T) {
 	// Col1: |--|
 	// Col2:          |--|
 	// Col3:     |--|
-	assertWayMade([]*Col{&Col{Min: 1, Max: 2}, &Col{Min: 10, Max: 11}, &Col{Min: 5, Max: 6}},
+	assertWayMade([]*Col{{Min: 1, Max: 2}, {Min: 10, Max: 11}, {Min: 5, Max: 6}},
 		func(cs *ColStore) {
 			root := cs.Root
 			c.Assert(cs.Len, qt.Equals, 3)
@@ -296,7 +296,7 @@ func TestMakeWay(t *testing.T) {
 	// Col2:        |x-|
 	// Col3:  |-------|
 	assertWayMade([]*Col{
-		&Col{Min: 1, Max: 2}, &Col{Min: 8, Max: 9}, &Col{Min: 2, Max: 8}},
+		{Min: 1, Max: 2}, {Min: 8, Max: 9}, {Min: 2, Max: 8}},
 		func(cs *ColStore) {
 			root := cs.Root
 			c.Assert(cs.Len, qt.Equals, 3)
@@ -320,7 +320,7 @@ func TestMakeWay(t *testing.T) {
 	// Col2:        |--|
 	// Col3:  |-----|
 	assertWayMade([]*Col{
-		&Col{Min: 1, Max: 2}, &Col{Min: 8, Max: 9}, &Col{Min: 2, Max: 7}},
+		{Min: 1, Max: 2}, {Min: 8, Max: 9}, {Min: 2, Max: 7}},
 		func(cs *ColStore) {
 			root := cs.Root
 			c.Assert(cs.Len, qt.Equals, 3)
@@ -344,7 +344,7 @@ func TestMakeWay(t *testing.T) {
 	// Col2:        |x-|
 	// Col3:    |-----|
 	assertWayMade([]*Col{
-		&Col{Min: 1, Max: 2}, &Col{Min: 8, Max: 9}, &Col{Min: 3, Max: 8}},
+		{Min: 1, Max: 2}, {Min: 8, Max: 9}, {Min: 3, Max: 8}},
 		func(cs *ColStore) {
 			root := cs.Root
 			c.Assert(cs.Len, qt.Equals, 3)
@@ -370,10 +370,10 @@ func TestMakeWay(t *testing.T) {
 	// Col4:   |--|
 	assertWayMade(
 		[]*Col{
-			&Col{Min: 1, Max: 2},
-			&Col{Min: 3, Max: 4, Width: 1.0},
-			&Col{Min: 5, Max: 6},
-			&Col{Min: 3, Max: 4, Width: 2.0},
+			{Min: 1, Max: 2},
+			{Min: 3, Max: 4, Width: 1.0},
+			{Min: 5, Max: 6},
+			{Min: 3, Max: 4, Width: 2.0},
 		},
 		func(cs *ColStore) {
 			root := cs.Root
@@ -401,10 +401,10 @@ func TestMakeWay(t *testing.T) {
 	// Col4:  |----|
 	assertWayMade(
 		[]*Col{
-			&Col{Min: 1, Max: 2, Width: 1.0},
-			&Col{Min: 3, Max: 4, Width: 2.0},
-			&Col{Min: 5, Max: 6, Width: 3.0},
-			&Col{Min: 2, Max: 5, Width: 4.0},
+			{Min: 1, Max: 2, Width: 1.0},
+			{Min: 3, Max: 4, Width: 2.0},
+			{Min: 5, Max: 6, Width: 3.0},
+			{Min: 2, Max: 5, Width: 4.0},
 		},
 		func(cs *ColStore) {
 			root := cs.Root
@@ -545,35 +545,35 @@ func (css *ColStoreSuite) TestGetOrMakeColsForRange(c *C) {
 	}
 
 	// make everything
-	assertCols(1, 11, nil, []*Col{&Col{Min: 1, Max: 11}})
+	assertCols(1, 11, nil, []*Col{{Min: 1, Max: 11}})
 
 	// get everything, one col
-	assertCols(1, 11, []*Col{&Col{Min: 1, Max: 11}}, []*Col{&Col{Min: 1, Max: 11}})
+	assertCols(1, 11, []*Col{{Min: 1, Max: 11}}, []*Col{{Min: 1, Max: 11}})
 
 	// get everything, many cols
 	assertCols(1, 11,
 		[]*Col{
-			&Col{Min: 1, Max: 4},
-			&Col{Min: 5, Max: 8},
-			&Col{Min: 9, Max: 11},
+			{Min: 1, Max: 4},
+			{Min: 5, Max: 8},
+			{Min: 9, Max: 11},
 		},
 		[]*Col{
-			&Col{Min: 1, Max: 4},
-			&Col{Min: 5, Max: 8},
-			&Col{Min: 9, Max: 11},
+			{Min: 1, Max: 4},
+			{Min: 5, Max: 8},
+			{Min: 9, Max: 11},
 		},
 	)
 
 	// make missing col
 	assertCols(1, 11,
 		[]*Col{
-			&Col{Min: 1, Max: 4},
-			&Col{Min: 9, Max: 11},
+			{Min: 1, Max: 4},
+			{Min: 9, Max: 11},
 		},
 		[]*Col{
-			&Col{Min: 1, Max: 4},
-			&Col{Min: 5, Max: 8},
-			&Col{Min: 9, Max: 11},
+			{Min: 1, Max: 4},
+			{Min: 5, Max: 8},
+			{Min: 9, Max: 11},
 		},
 	)
 

+ 8 - 8
date.go

@@ -6,11 +6,11 @@ import (
 )
 
 const (
-	MJD_0 float64 = 2400000.5
+	MJD_0      float64 = 2400000.5
 	MJD_JD2000 float64 = 51544.5
 
-	secondsInADay = float64((24*time.Hour)/time.Second)
-	nanosInADay = float64((24*time.Hour)/time.Nanosecond)
+	secondsInADay = float64((24 * time.Hour) / time.Second)
+	nanosInADay   = float64((24 * time.Hour) / time.Nanosecond)
 )
 
 var (
@@ -25,8 +25,8 @@ var (
 	excel1900Epoc = time.Date(1899, time.December, 30, 0, 0, 0, 0, time.UTC)
 	excel1904Epoc = time.Date(1904, time.January, 1, 0, 0, 0, 0, time.UTC)
 	// Days between epocs, including both off by one errors for 1900.
-	daysBetween1970And1900 = float64(unixEpoc.Sub(excel1900Epoc)/(24 * time.Hour))
-	daysBetween1970And1904 = float64(unixEpoc.Sub(excel1904Epoc)/(24 * time.Hour))
+	daysBetween1970And1900 = float64(unixEpoc.Sub(excel1900Epoc) / (24 * time.Hour))
+	daysBetween1970And1904 = float64(unixEpoc.Sub(excel1904Epoc) / (24 * time.Hour))
 )
 
 func TimeToUTCTime(t time.Time) time.Time {
@@ -124,7 +124,7 @@ func TimeFromExcelTime(excelTime float64, date1904 bool) time.Time {
 		date = excel1900Epoc
 	}
 	durationPart := time.Duration(nanosInADay * floatPart)
-	return date.AddDate(0,0, wholeDaysPart).Add(durationPart)
+	return date.AddDate(0, 0, wholeDaysPart).Add(durationPart)
 }
 
 // TimeToExcelTime will convert a time.Time into Excel's float representation, in either 1900 or 1904
@@ -132,9 +132,9 @@ func TimeFromExcelTime(excelTime float64, date1904 bool) time.Time {
 // TODO should this should handle Julian dates?
 func TimeToExcelTime(t time.Time, date1904 bool) float64 {
 	// Get the number of days since the unix epoc
-	daysSinceUnixEpoc := float64(t.Unix())/secondsInADay
+	daysSinceUnixEpoc := float64(t.Unix()) / secondsInADay
 	// Get the number of nanoseconds in days since Unix() is in seconds.
-	nanosPart := float64(t.Nanosecond())/nanosInADay
+	nanosPart := float64(t.Nanosecond()) / nanosInADay
 	// Add both together plus the number of days difference between unix and Excel epocs.
 	var offsetDays float64
 	if date1904 {

+ 2 - 2
stream_file_builder.go

@@ -299,7 +299,7 @@ func (sb *StreamFileBuilder) Build() (*StreamFile, error) {
 
 func (sb *StreamFileBuilder) marshalStyles() (string, error) {
 
-	for streamStyle, _ := range sb.customStreamStyles {
+	for streamStyle := range sb.customStreamStyles {
 		XfId := handleStyleForXLSX(streamStyle.style, streamStyle.xNumFmtId, sb.xlsxFile.styles)
 		sb.styleIdMap[streamStyle] = XfId
 	}
@@ -390,7 +390,7 @@ func getSheetIndex(sf *StreamFile, path string) (int, error) {
 func removeDimensionTag(data string) string {
 	start := strings.Index(data, "<dimension")
 	end := strings.Index(data, "</dimension>") + 12
-	return data[0:start] + data[end:len(data)]
+	return data[0:start] + data[end:]
 }
 
 // splitSheetIntoPrefixAndSuffix will split the provided XML sheet into a prefix and a suffix so that

+ 9 - 9
stream_style_test.go

@@ -301,9 +301,9 @@ func TestXlsxStreamWriteWithStyle(t *testing.T) {
 			}
 
 			expectedWorkbookDataStrings := [][][]string{}
-			for j, _ := range testCase.workbookData {
+			for j := range testCase.workbookData {
 				expectedWorkbookDataStrings = append(expectedWorkbookDataStrings, [][]string{})
-				for k, _ := range testCase.workbookData[j] {
+				for k := range testCase.workbookData[j] {
 					if len(testCase.workbookData[j][k]) == 0 {
 						expectedWorkbookDataStrings[j] = append(expectedWorkbookDataStrings[j], nil)
 					} else {
@@ -467,7 +467,7 @@ func TestStreamStyleDates(t *testing.T) {
 	}
 
 	expectedWorkbookDataStrings := [][][]string{}
-	for j, _ := range workbookData {
+	for j := range workbookData {
 		expectedWorkbookDataStrings = append(expectedWorkbookDataStrings, [][]string{})
 		for range workbookData[j] {
 			expectedWorkbookDataStrings[j] = append(expectedWorkbookDataStrings[j], []string{})
@@ -552,9 +552,9 @@ func TestMakeNewStylesAndUseIt(t *testing.T) {
 	}
 
 	expectedWorkbookDataStrings := [][][]string{}
-	for j, _ := range workbookData {
+	for j := range workbookData {
 		expectedWorkbookDataStrings = append(expectedWorkbookDataStrings, [][]string{})
-		for k, _ := range workbookData[j] {
+		for k := range workbookData[j] {
 			expectedWorkbookDataStrings[j] = append(expectedWorkbookDataStrings[j], []string{})
 			for _, cell := range workbookData[j][k] {
 				expectedWorkbookDataStrings[j][k] = append(expectedWorkbookDataStrings[j][k], cell.cellData)
@@ -607,9 +607,9 @@ func TestStreamNewTypes(t *testing.T) {
 	}
 
 	expectedWorkbookDataStrings := [][][]string{}
-	for j, _ := range workbookData {
+	for j := range workbookData {
 		expectedWorkbookDataStrings = append(expectedWorkbookDataStrings, [][]string{})
-		for k, _ := range workbookData[j] {
+		for k := range workbookData[j] {
 			expectedWorkbookDataStrings[j] = append(expectedWorkbookDataStrings[j], []string{})
 			for _, cell := range workbookData[j][k] {
 				if cell.cellData == "1" {
@@ -794,8 +794,8 @@ func TestStreamNoStylesWriteSError(t *testing.T) {
 }
 
 func checkForCorrectCellStyles(actualCells [][][]Cell, expectedCells [][][]StreamCell) error {
-	for i, _ := range actualCells {
-		for j, _ := range actualCells[i] {
+	for i := range actualCells {
+		for j := range actualCells[i] {
 			for k, actualCell := range actualCells[i][j] {
 				expectedCell := expectedCells[i][j][k]
 				if err := compareCellStyles(actualCell, expectedCell); err != nil {

+ 1 - 1
write.go

@@ -42,7 +42,7 @@ func (r *Row) WriteSlice(e interface{}, cols int) int {
 		case fmt.Stringer: // check Stringer first
 			cell := r.AddCell()
 			cell.SetString(t.String())
-		case sql.NullString:  // check null sql types nulls = ''
+		case sql.NullString: // check null sql types nulls = ''
 			cell := r.AddCell()
 			if cell.SetString(``); t.Valid {
 				cell.SetValue(t.String)