11package csvdata_test
22
33import (
4+ "database/sql"
45 "errors"
56 "io"
67 "strconv"
@@ -84,19 +85,25 @@ func TestBlankReader(t *testing.T) {
8485
8586func TestNormal (t * testing.T ) {
8687 testCases := []struct {
87- sep rune
88- size int
89- headerFlag bool
90- inp io.Reader
91- name1 string
92- name2 string
93- flag bool
94- mass float64
95- order int64
96- err error
88+ sep rune
89+ size int
90+ headerFlag bool
91+ inp io.Reader
92+ name1 string
93+ name2 string
94+ flag bool
95+ flagBool sql.NullBool
96+ mass float64
97+ massFloat64 sql.NullFloat64
98+ order int64
99+ orderByte sql.NullByte
100+ orderInt16 sql.NullInt16
101+ orderInt32 sql.NullInt32
102+ orderInt64 sql.NullInt64
103+ err error
97104 }{
98- {sep : ',' , size : 6 , headerFlag : true , inp : strings .NewReader (csv1 ), name1 : "Mercury" , name2 : "Mercury" , flag : false , mass : 0.055 , order : 1 , err : nil },
99- {sep : '\t' , size : 6 , headerFlag : false , inp : strings .NewReader (tsv1 ), name1 : "Mercury" , name2 : "" , flag : false , mass : 0.055 , order : 1 , err : csvdata .ErrOutOfIndex },
105+ {sep : ',' , size : 6 , headerFlag : true , inp : strings .NewReader (csv1 ), name1 : "Mercury" , name2 : "Mercury" , flag : false , flagBool : sql. NullBool { Bool : false , Valid : true }, mass : 0.055 , massFloat64 : sql. NullFloat64 { Float64 : 0.055 , Valid : true }, order : 1 , orderByte : sql. NullByte { Byte : 1 , Valid : true }, orderInt16 : sql. NullInt16 { Int16 : 1 , Valid : true }, orderInt32 : sql. NullInt32 { Int32 : 1 , Valid : true }, orderInt64 : sql. NullInt64 { Int64 : 1 , Valid : true } , err : nil },
106+ {sep : '\t' , size : 6 , headerFlag : false , inp : strings .NewReader (tsv1 ), name1 : "Mercury" , name2 : "" , flag : false , flagBool : sql. NullBool { Bool : false , Valid : true }, mass : 0.055 , massFloat64 : sql. NullFloat64 { Float64 : 0.055 , Valid : true }, order : 1 , orderByte : sql. NullByte { Byte : 1 , Valid : true }, orderInt16 : sql. NullInt16 { Int16 : 1 , Valid : true }, orderInt32 : sql. NullInt32 { Int32 : 1 , Valid : true }, orderInt64 : sql. NullInt64 { Int64 : 1 , Valid : true } , err : csvdata .ErrOutOfIndex },
100107 }
101108
102109 for _ , tc := range testCases {
@@ -146,6 +153,13 @@ func TestNormal(t *testing.T) {
146153 if err == nil && flag != tc .flag {
147154 t .Errorf ("ColumnBool() is \" %+v\" , want \" %+v\" ." , flag , tc .flag )
148155 }
156+ flagBool , err := rc .ColumnNullBool ("habitable" )
157+ if ! errors .Is (err , tc .err ) {
158+ t .Errorf ("ColumnBool() is \" %+v\" , want \" %+v\" ." , err , tc .err )
159+ }
160+ if err == nil && flagBool != tc .flagBool {
161+ t .Errorf ("ColumnBool() is \" %+v\" , want \" %+v\" ." , flagBool , tc .flagBool )
162+ }
149163 //float
150164 if _ , err = rc .GetFloat64 (5 ); ! errors .Is (err , csvdata .ErrNullPointer ) {
151165 t .Errorf ("GetFloat() is \" %+v\" , want \" %+v\" ." , err , strconv .ErrSyntax )
@@ -160,6 +174,13 @@ func TestNormal(t *testing.T) {
160174 if err == nil && mass != tc .mass {
161175 t .Errorf ("ColumnFloat() is \" %+v\" , want \" %+v\" ." , mass , tc .mass )
162176 }
177+ massFloat64 , err := rc .ColumnNullFloat64 ("mass" )
178+ if ! errors .Is (err , tc .err ) {
179+ t .Errorf ("ColumnFloat() is \" %+v\" , want \" %+v\" ." , err , tc .err )
180+ }
181+ if err == nil && massFloat64 != tc .massFloat64 {
182+ t .Errorf ("ColumnFloat() is \" %+v\" , want \" %+v\" ." , massFloat64 , tc .massFloat64 )
183+ }
163184 //int
164185 if _ , err = rc .GetInt64 (5 , 10 ); ! errors .Is (err , csvdata .ErrNullPointer ) {
165186 t .Errorf ("GetFloat() is \" %+v\" , want \" %+v\" ." , err , strconv .ErrSyntax )
@@ -174,11 +195,39 @@ func TestNormal(t *testing.T) {
174195 if err == nil && order != tc .order {
175196 t .Errorf ("ColumnFloat() is \" %+v\" , want \" %+v\" ." , order , tc .order )
176197 }
198+ orderByte , err := rc .ColumnNullByte ("order" , 10 )
199+ if ! errors .Is (err , tc .err ) {
200+ t .Errorf ("ColumnFloat() is \" %+v\" , want \" %+v\" ." , err , tc .err )
201+ }
202+ if err == nil && orderByte != tc .orderByte {
203+ t .Errorf ("ColumnFloat() is \" %+v\" , want \" %+v\" ." , orderByte , tc .orderByte )
204+ }
205+ orderInt16 , err := rc .ColumnNullInt16 ("order" , 10 )
206+ if ! errors .Is (err , tc .err ) {
207+ t .Errorf ("ColumnFloat() is \" %+v\" , want \" %+v\" ." , err , tc .err )
208+ }
209+ if err == nil && orderInt16 != tc .orderInt16 {
210+ t .Errorf ("ColumnFloat() is \" %+v\" , want \" %+v\" ." , orderInt16 , tc .orderInt16 )
211+ }
212+ orderInt32 , err := rc .ColumnNullInt32 ("order" , 10 )
213+ if ! errors .Is (err , tc .err ) {
214+ t .Errorf ("ColumnFloat() is \" %+v\" , want \" %+v\" ." , err , tc .err )
215+ }
216+ if err == nil && orderInt32 != tc .orderInt32 {
217+ t .Errorf ("ColumnFloat() is \" %+v\" , want \" %+v\" ." , orderInt32 , tc .orderInt32 )
218+ }
219+ orderInt64 , err := rc .ColumnNullInt64 ("order" , 10 )
220+ if ! errors .Is (err , tc .err ) {
221+ t .Errorf ("ColumnFloat() is \" %+v\" , want \" %+v\" ." , err , tc .err )
222+ }
223+ if err == nil && orderInt64 != tc .orderInt64 {
224+ t .Errorf ("ColumnFloat() is \" %+v\" , want \" %+v\" ." , orderInt64 , tc .orderInt64 )
225+ }
177226 }
178227 }
179228}
180229
181- /* Copyright 2021 Spiegel
230+ /* Copyright 2021-2022 Spiegel
182231 *
183232 * Licensed under the Apache License, Version 2.0 (the "License");
184233 * you may not use this file except in compliance with the License.
0 commit comments