aboutsummaryrefslogtreecommitdiffstats
path: root/skate/matchset_test.go
diff options
context:
space:
mode:
authorMartin Czygan <martin.czygan@gmail.com>2021-06-01 12:53:37 +0200
committerMartin Czygan <martin.czygan@gmail.com>2021-06-01 12:53:37 +0200
commitbd862b51161fab8a62bcae49eb7452a82dd2b70a (patch)
treebca4e7c65ea68e162386d64c424287e926d4e125 /skate/matchset_test.go
parent99ab76153c4fef7f3efb3d58441a8ea784157750 (diff)
downloadrefcat-bd862b51161fab8a62bcae49eb7452a82dd2b70a.tar.gz
refcat-bd862b51161fab8a62bcae49eb7452a82dd2b70a.zip
add match set
Diffstat (limited to 'skate/matchset_test.go')
-rw-r--r--skate/matchset_test.go81
1 files changed, 81 insertions, 0 deletions
diff --git a/skate/matchset_test.go b/skate/matchset_test.go
new file mode 100644
index 0000000..0436faf
--- /dev/null
+++ b/skate/matchset_test.go
@@ -0,0 +1,81 @@
+package skate
+
+import (
+ "reflect"
+ "sort"
+ "testing"
+)
+
+func TestMatchSetLookup(t *testing.T) {
+ var cases = []struct {
+ s string
+ ps []string
+ n int
+ result []string
+ }{
+ {
+ s: "",
+ ps: []string{},
+ n: -1,
+ result: nil,
+ },
+ {
+ s: "hello",
+ ps: []string{"lo"},
+ n: -1,
+ result: nil,
+ },
+ {
+ s: "hello",
+ ps: []string{"zz"},
+ n: -1,
+ result: nil,
+ },
+ {
+ s: "hello",
+ ps: []string{"h", "he", "hel"},
+ n: -1,
+ result: nil,
+ },
+ {
+ s: "hello",
+ ps: []string{"hello"},
+ n: -1,
+ result: []string{"hello"},
+ },
+ {
+ s: "hello world",
+ ps: []string{"hello", "world"},
+ n: -1,
+ result: nil,
+ },
+ {
+ s: "he",
+ ps: []string{"hello", "world", "hel"},
+ n: -1,
+ result: []string{"hello", "hel"},
+ },
+ {
+ s: "american italian proceedings",
+ ps: []string{
+ "italian",
+ "american",
+ "american italian",
+ "american italian proceedings",
+ "proceedings",
+ },
+ n: -1,
+ result: []string{"american italian proceedings"},
+ },
+ }
+ for _, c := range cases {
+ ms := NewMatchSet(c.ps)
+ result := ms.Lookup(c.s, c.n)
+ sort.Strings(result)
+ sort.Strings(c.result)
+ if !reflect.DeepEqual(result, c.result) {
+ t.Errorf("got %v, want %v -> s=%s ps=%s",
+ result, c.result, c.s, c.ps)
+ }
+ }
+}