@@ -14,20 +14,20 @@ import (
1414
1515const (
1616 csv1 = `"order", name ,"mass","distance","habitable","note"
17- 1, Mercury, 0.055, 0.4,false,""
18- 2, Venus, 0.815, 0.7,false,""
19- 3, Earth, 1.0, 1.0,true,""
20- 4, Mars, 0.107, 1.5,false,""
17+ 1, Mercury, 0.055, 0.4,false,"2006-01-02T15:04:05+09:00 "
18+ 2, Venus, 0.815, 0.7,false,"2006-01-02T15:04:05+09:00 "
19+ 3, Earth, 1.0, 1.0,true,"2006-01-02T15:04:05+09:00 "
20+ 4, Mars, 0.107, 1.5,false,"2006-01-02T15:04:05+09:00 "
2121`
22- tsv1 = `1 Mercury 0.055 0.4 false ""
23- 2 Venus 0.815 0.7 false ""
24- 3 Earth 1.0 1.0 true ""
25- 4 Mars 0.107 1.5 false ""
22+ tsv1 = `1 Mercury 0.055 0.4 false "2006-01-02T15:04:05+09:00 "
23+ 2 Venus 0.815 0.7 false "2006-01-02T15:04:05+09:00 "
24+ 3 Earth 1.0 1.0 true "2006-01-02T15:04:05+09:00 "
25+ 4 Mars 0.107 1.5 false "2006-01-02T15:04:05+09:00 "
2626`
2727)
2828
2929func TestWithNil (t * testing.T ) {
30- r := csvdata .NewRows ((* csvdata .Reader )(nil ).WithComma (',' ).WithLazyQuotes (true ).WithTrimLeadingSpace (true ).WithFieldsPerRecord (1 ), true )
30+ r := csvdata .NewRows ((* csvdata .Reader )(nil ).WithComma (',' ).WithTrimSpace ( true ). WithLazyQuotes (true ).WithTrimLeadingSpace (true ).WithFieldsPerRecord (1 ), true )
3131 defer r .Close () //dummy
3232 if err := r .Next (); ! errors .Is (err , csvdata .ErrNullPointer ) {
3333 t .Errorf ("Next() is \" %+v\" , want \" %+v\" ." , err , csvdata .ErrNullPointer )
@@ -65,7 +65,7 @@ func TestWithNil(t *testing.T) {
6565
6666func TestErrReader (t * testing.T ) {
6767 errtest := errors .New ("test" )
68- r := csvdata .NewRows (csvdata .New (iotest .ErrReader (errtest )).WithComma (',' ).WithLazyQuotes (true ).WithTrimLeadingSpace (true ).WithFieldsPerRecord (1 ), true )
68+ r := csvdata .NewRows (csvdata .New (iotest .ErrReader (errtest )).WithComma (',' ).WithTrimSpace ( true ). WithLazyQuotes (true ).WithTrimLeadingSpace (true ).WithFieldsPerRecord (1 ), true )
6969 defer r .Close () //dummy
7070 if err := r .Next (); ! errors .Is (err , errtest ) {
7171 t .Errorf ("Next() is \" %+v\" , want \" %+v\" ." , err , errtest )
@@ -107,7 +107,7 @@ func TestNormal(t *testing.T) {
107107 }
108108
109109 for _ , tc := range testCases {
110- rc := csvdata .NewRows (csvdata .New (tc .inp ).WithComma (tc .sep ).WithLazyQuotes (true ).WithTrimLeadingSpace (true ).WithFieldsPerRecord (tc .size ), tc .headerFlag )
110+ rc := csvdata .NewRows (csvdata .New (tc .inp ).WithComma (tc .sep ).WithLazyQuotes (true ).WithTrimSpace ( true ). WithTrimLeadingSpace (true ).WithFieldsPerRecord (tc .size ), tc .headerFlag )
111111 if err := rc .Next (); err != nil {
112112 t .Errorf ("Next() is \" %+v\" , want nil." , err )
113113 } else {
@@ -140,7 +140,7 @@ func TestNormal(t *testing.T) {
140140 t .Errorf ("Column() is \" %v\" , want \" %v\" ." , name , tc .name2 )
141141 }
142142 //bool
143- if _ , err = rc .GetBool (5 ); ! errors .Is (err , csvdata . ErrNullValue ) {
143+ if _ , err = rc .GetBool (5 ); ! errors .Is (err , strconv . ErrSyntax ) {
144144 t .Errorf ("GetBool() is \" %+v\" , want \" %+v\" ." , err , strconv .ErrSyntax )
145145 }
146146 if _ , err = rc .ColumnBool ("name" ); ! errors .Is (err , strconv .ErrSyntax ) && ! errors .Is (err , tc .err ) {
@@ -161,7 +161,7 @@ func TestNormal(t *testing.T) {
161161 t .Errorf ("ColumnBool() is \" %+v\" , want \" %+v\" ." , flagBool , tc .flagBool )
162162 }
163163 //float
164- if _ , err = rc .GetFloat64 (5 ); ! errors .Is (err , csvdata . ErrNullValue ) {
164+ if _ , err = rc .GetFloat64 (5 ); ! errors .Is (err , strconv . ErrSyntax ) {
165165 t .Errorf ("GetFloat() is \" %+v\" , want \" %+v\" ." , err , strconv .ErrSyntax )
166166 }
167167 if _ , err = rc .ColumnFloat64 ("name" ); ! errors .Is (err , strconv .ErrSyntax ) && ! errors .Is (err , tc .err ) {
@@ -182,7 +182,7 @@ func TestNormal(t *testing.T) {
182182 t .Errorf ("ColumnNullFloat64() is \" %+v\" , want \" %+v\" ." , massFloat64 , tc .massFloat64 )
183183 }
184184 //int
185- if _ , err = rc .GetInt64 (5 , 10 ); ! errors .Is (err , csvdata . ErrNullValue ) {
185+ if _ , err = rc .GetInt64 (5 , 10 ); ! errors .Is (err , strconv . ErrSyntax ) {
186186 t .Errorf ("GetInt64() is \" %+v\" , want \" %+v\" ." , err , strconv .ErrSyntax )
187187 }
188188 if _ , err = rc .ColumnInt64 ("name" , 10 ); ! errors .Is (err , strconv .ErrSyntax ) && ! errors .Is (err , tc .err ) {
@@ -251,6 +251,13 @@ func TestNormal(t *testing.T) {
251251 if err == nil && orderInt64 != tc .orderInt64 {
252252 t .Errorf ("ColumnNullInt64() is \" %+v\" , want \" %+v\" ." , orderInt64 , tc .orderInt64 )
253253 }
254+ // time
255+ if _ , err = rc .ColumnNullTime ("note" , "" ); ! errors .Is (err , tc .err ) {
256+ t .Errorf ("ColumnNullTime() is \" %+v\" , want \" %+v\" ." , err , tc .err )
257+ }
258+ if _ , err = rc .ColumnTime ("note" , "" ); ! errors .Is (err , tc .err ) {
259+ t .Errorf ("ColumnNullTime() is \" %+v\" , want \" %+v\" ." , err , tc .err )
260+ }
254261 }
255262 }
256263}
0 commit comments