diff options
Diffstat (limited to 'main_test.go')
-rw-r--r-- | main_test.go | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/main_test.go b/main_test.go new file mode 100644 index 0000000..c3e9d2e --- /dev/null +++ b/main_test.go @@ -0,0 +1,36 @@ +package main + +import ( + "github.com/gocarina/gocsv" + "testing" +) + +type Type struct { + Headerless string `csv:""` + Headered string `csv:"header"` +} + +func TestNoHeader(t *testing.T) { + types := []*Type{} + csv := `,header +foo,bar +baz,quux` + + if err := gocsv.UnmarshalString(csv, &types); err != nil { + t.Fatal(err) + } + + for i, tc := range []struct { + actual string + expected string + }{ + {types[0].Headerless, "foo"}, + {types[0].Headered, "bar"}, + {types[1].Headerless, "baz"}, + {types[1].Headered, "quux"}, + } { + if tc.actual != tc.expected { + t.Errorf("Test case %d: Got \"%s\", expected \"%s\"", i, tc.actual, tc.expected) + } + } +} |