From 6ec4eda8da2342599c61a79e5a4e98e748a1b1c3 Mon Sep 17 00:00:00 2001 From: Martin Czygan Date: Thu, 6 May 2021 00:24:29 +0200 Subject: add test --- skate/zippy.go | 4 ++-- skate/zippy_test.go | 25 +++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 skate/zippy_test.go (limited to 'skate') diff --git a/skate/zippy.go b/skate/zippy.go index 76f576d..ad1923a 100644 --- a/skate/zippy.go +++ b/skate/zippy.go @@ -133,10 +133,10 @@ func ZippyVerifyRefs(releases, refs io.Reader, w io.Writer) error { } // makeKeyFunc creates a function that can be used as keyFunc, selecting a -// column from sep. +// column from fields separated by sep; column is 1-indexed. func makeKeyFunc(sep string, column int) func(string) (string, error) { return func(s string) (string, error) { - if k := lineColumn(s, "\t", 2); k == "" { + if k := lineColumn(s, sep, column); k == "" { return k, fmt.Errorf("cannot get key: %s", s) } else { return k, nil diff --git a/skate/zippy_test.go b/skate/zippy_test.go new file mode 100644 index 0000000..49f4a54 --- /dev/null +++ b/skate/zippy_test.go @@ -0,0 +1,25 @@ +package skate + +import "testing" + +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 := lineColumn(c.line, c.sep, c.column) + if result != c.result { + t.Fatalf("got %v, want %v", result, c.result) + } + } +} -- cgit v1.2.3