forked from gokcehan/lf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
complete_test.go
55 lines (48 loc) · 1.26 KB
/
complete_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package main
import (
"reflect"
"testing"
)
func TestMatchLongest(t *testing.T) {
tests := []struct {
s1 string
s2 string
exp string
}{
{"", "", ""},
{"", "foo", ""},
{"foo", "", ""},
{"foo", "bar", ""},
{"foo", "foobar", "foo"},
{"foo", "barfoo", ""},
{"foobar", "foobaz", "fooba"},
}
for _, test := range tests {
if got := matchLongest(test.s1, test.s2); got != test.exp {
t.Errorf("at input '%s' and '%s' expected '%s' but got '%s'", test.s1, test.s2, test.exp, got)
}
}
}
func TestMatchWord(t *testing.T) {
tests := []struct {
s string
words []string
matches []string
longest string
}{
{"", nil, nil, ""},
{"", []string{"foo", "bar", "baz"}, []string{"foo", "bar", "baz"}, ""},
{"fo", []string{"foo", "bar", "baz"}, []string{"foo"}, "foo "},
{"ba", []string{"foo", "bar", "baz"}, []string{"bar", "baz"}, "ba"},
{"fo", []string{"bar", "baz"}, nil, "fo"},
}
for _, test := range tests {
m, l := matchWord(test.s, test.words)
if !reflect.DeepEqual(m, test.matches) {
t.Errorf("at input '%s' with '%s' expected '%s' but got '%s'", test.s, test.words, test.matches, m)
}
if l != test.longest {
t.Errorf("at input '%s' with '%s' expected '%s' but got '%s'", test.s, test.words, test.longest, l)
}
}
}