Skip to content

Commit

Permalink
Add tests for the other two matchers
Browse files Browse the repository at this point in the history
  • Loading branch information
suzaku committed May 5, 2016
1 parent e133d82 commit 6709d71
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions matcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand All @@ -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)
}
Expand Down

0 comments on commit 6709d71

Please sign in to comment.