package skate import ( "reflect" "testing" "github.com/kr/pretty" ) func TestLineColumn(t *testing.T) { var cases = []struct { line string sep string column int result string }{ {"", "", 2, ""}, {"1 2 3", " ", 1, "1"}, {"1 2 3", " ", 2, "2"}, {"1 2 3", " ", 3, "3"}, {"1 2 3", " ", 4, ""}, {"1 2 3", "\t", 1, "1 2 3"}, } for _, c := range cases { result := CutSep(c.line, c.sep, c.column) if result != c.result { t.Fatalf("got %v, want %v", result, c.result) } } } func TestUniqueMatches(t *testing.T) { var cases = []struct { docs []string result []*BiblioRef err error }{ { docs: []string{`{}`}, result: []*BiblioRef{&BiblioRef{}}, err: nil, }, { docs: []string{`{ "source_release_ident": "s1", "target_release_ident": "t1"}`}, result: []*BiblioRef{&BiblioRef{ SourceReleaseIdent: "s1", TargetReleaseIdent: "t1", }}, err: nil, }, { docs: []string{` {"source_release_ident": "s1", "target_release_ident": "t1", "match_status": "fuzzy"}`, `{"source_release_ident": "s1", "target_release_ident": "t1", "match_status": "exact"}`, }, result: []*BiblioRef{&BiblioRef{ SourceReleaseIdent: "s1", TargetReleaseIdent: "t1", MatchStatus: "exact", }}, err: nil, }, } for _, c := range cases { result, err := uniqueMatches(c.docs) if err != c.err { t.Fatalf("got %v, want %v", err, c.err) } if !reflect.DeepEqual(result, c.result) { t.Fatalf("got %#v, want %#v", pretty.Sprint(result), pretty.Sprint(c.result)) } } }