diff options
-rw-r--r-- | skate/zippy.go | 4 | ||||
-rw-r--r-- | skate/zippy_test.go | 25 |
2 files changed, 27 insertions, 2 deletions
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) + } + } +} |