diff options
author | Martin Czygan <martin.czygan@gmail.com> | 2021-03-21 01:17:38 +0100 |
---|---|---|
committer | Martin Czygan <martin.czygan@gmail.com> | 2021-03-21 01:17:38 +0100 |
commit | 09a7e8c9d013f13a1aa1ef4e9b7f397647b79967 (patch) | |
tree | 122b474e27afbc66cba1182e983ef5c8555ed12f /skate/zipkey/zipkey_test.go | |
parent | a7e0cf191ebf8fb499e0ab9a3b6cae45727f1286 (diff) | |
download | refcat-09a7e8c9d013f13a1aa1ef4e9b7f397647b79967.tar.gz refcat-09a7e8c9d013f13a1aa1ef4e9b7f397647b79967.zip |
initial import of skate
Diffstat (limited to 'skate/zipkey/zipkey_test.go')
-rw-r--r-- | skate/zipkey/zipkey_test.go | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/skate/zipkey/zipkey_test.go b/skate/zipkey/zipkey_test.go new file mode 100644 index 0000000..0a49a45 --- /dev/null +++ b/skate/zipkey/zipkey_test.go @@ -0,0 +1,83 @@ +package zipkey + +import ( + "bytes" + "encoding/json" + "strings" + "testing" + + "git.archive.org/martin/cgraph/skate/must" +) + +func TestZipRun(t *testing.T) { + makeKeyFunc := func(index int) func(string) (string, error) { + return func(s string) (string, error) { + parts := strings.Fields(s) + if index >= len(parts) { + return "", nil + } + return parts[index], nil + } + } + var cases = []struct { + a string + b string + c string + kf func(string) (string, error) + }{ + { + "testdata/c0a", + "testdata/c0b", + "testdata/c0c", + makeKeyFunc(0), + }, + { + "testdata/c1a", + "testdata/c1b", + "testdata/c1c", + makeKeyFunc(0), + }, + { + "testdata/c2a", + "testdata/c2b", + "testdata/c2c", + makeKeyFunc(0), + }, + { + "testdata/c3a", + "testdata/c3b", + "testdata/c3c", + makeKeyFunc(0), + }, + { + "testdata/c4a", + "testdata/c4b", + "testdata/c4c", + makeKeyFunc(1), + }, + { + "testdata/c5a", + "testdata/c5b", + "testdata/c5c", + makeKeyFunc(0), + }, + } + for _, c := range cases { + var ( + ar = must.Open(c.a) + br = must.Open(c.b) + cr = strings.TrimSpace(string(must.ReadFile(c.c))) + buf bytes.Buffer + groupFunc = func(g *Group) error { + return json.NewEncoder(&buf).Encode(g) + } + cm = New(ar, br, c.kf, groupFunc) + ) + if err := cm.Run(); err != nil { + t.Errorf("[%s] failed: %v", c.a, err) + } + if got := strings.TrimSpace(buf.String()); cr != got { + t.Errorf("[%s ...] got %v, want %v", c.a, got, cr) + } + } +} |