diff --git a/matcher_test.go b/matcher_test.go index 04f71e9..8700ccb 100644 --- a/matcher_test.go +++ b/matcher_test.go @@ -2,6 +2,37 @@ package main import "testing" +func TestAnywhere(t *testing.T) { + entries := []*Entry{ + &Entry{"/foo/bar/baz", 10}, + &Entry{"/foo/bazar", 10}, + &Entry{"/tmp", 10}, + &Entry{"/foo/gxxbazabc", 10}, + } + result := matchAnywhere(entries, []string{"foo", "baz"}) + expected := []string{ + "/foo/bar/baz", + "/foo/bazar", + "/foo/gxxbazabc", + } + assertItemsEqual(t, result, expected) +} + +func TestFuzzy(t *testing.T) { + entries := []*Entry{ + &Entry{"/foo/bar/baz", 10}, + &Entry{"/foo/bazar", 10}, + &Entry{"/tmp", 10}, + &Entry{"/foo/gxxbazabc", 10}, + } + result := matchFuzzy(entries, []string{"baz"}) + expected := []string{ + "/foo/bar/baz", + "/foo/bazar", + } + assertItemsEqual(t, result, expected) +} + func TestConsecutive(t *testing.T) { entries := []*Entry{ &Entry{"/foo/bar/baz", 10}, @@ -16,6 +47,10 @@ func TestConsecutive(t *testing.T) { "/foo/bazar", "/foo/xxbaz", } + assertItemsEqual(t, result, expected) +} + +func assertItemsEqual(t *testing.T, result []string, expected []string) { if len(result) != len(expected) { t.Errorf("Expected %v, got %v", expected, result) }