1
0
Fork 0
mirror of https://github.com/imjasonh/csvstruct synced 2026-07-09 03:25:01 +00:00

support DecodeNext(nil) to skip a line

This commit is contained in:
Jason Hall 2014-05-15 12:55:24 -04:00
parent 905ef96dff
commit 2731c3991a
2 changed files with 37 additions and 2 deletions

View file

@ -58,6 +58,9 @@ d
if !reflect.DeepEqual(rows, c.out) {
t.Errorf("unexpected result, got %v, want %v", rows, c.out)
}
if !isDone(d) {
t.Errorf("decoder unexpectedly not done")
}
}
}
@ -128,6 +131,33 @@ a,b`)).DecodeNext(&r); err != nil {
}
}
func TestDecode_DecodeNil(t *testing.T) {
type row struct {
Foo, Bar string
}
d := NewDecoder(strings.NewReader(`Foo,Bar
ignore,this
a,b`))
if err := d.DecodeNext(nil); err != nil {
t.Errorf("unexpected error while skipping line: %v", err)
}
var r row
if err := d.DecodeNext(&r); err != nil {
t.Errorf("unexpected error decoding after skip: %v", err)
}
exp := row{"a", "b"}
if r != exp {
t.Errorf("unexpected result, got %v, want %v", r, exp)
}
if !isDone(d) {
t.Errorf("decoder unexpectedly not done")
}
}
func isDone(d Decoder) bool {
return d.DecodeNext(nil) == io.EOF
}
func ExampleDecoder_DecodeNext() {
csv := `Foo,Bar,Baz
a,b,c