aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Readme.textile10
-rw-r--r--main_test.go36
2 files changed, 46 insertions, 0 deletions
diff --git a/Readme.textile b/Readme.textile
new file mode 100644
index 0000000..14aed69
--- /dev/null
+++ b/Readme.textile
@@ -0,0 +1,10 @@
+h2. Bug
+
+If a column has a blank header, unmarshalling fails.
+
+h2. Running
+
+# go get -u github.com/gocarina/gocsv
+# go get -u github.com/User4574/gocsvexample
+# cd $GOPATH/src/github.com/User4574/gocsvexample
+# go test
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)
+ }
+ }
+}