aboutsummaryrefslogtreecommitdiff
path: root/main_test.go
blob: c3e9d2eaae464f215e639a5da050194068c9a40e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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)
		}
	}
}