aboutsummaryrefslogtreecommitdiffstats
path: root/skate
diff options
context:
space:
mode:
authorMartin Czygan <martin.czygan@gmail.com>2021-05-06 00:24:29 +0200
committerMartin Czygan <martin.czygan@gmail.com>2021-05-06 00:24:29 +0200
commit6ec4eda8da2342599c61a79e5a4e98e748a1b1c3 (patch)
tree355321537ae224a753f5268795597ece965f73ba /skate
parent6967f14e37bf8dbc192ea31749f223cfbb598b4b (diff)
downloadrefcat-6ec4eda8da2342599c61a79e5a4e98e748a1b1c3.tar.gz
refcat-6ec4eda8da2342599c61a79e5a4e98e748a1b1c3.zip
add test
Diffstat (limited to 'skate')
-rw-r--r--skate/zippy.go4
-rw-r--r--skate/zippy_test.go25
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)
+ }
+ }
+}