-
Notifications
You must be signed in to change notification settings - Fork 148
/
command_name_test.go
47 lines (44 loc) · 1.38 KB
/
command_name_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
package gore
import (
"fmt"
"testing"
"github.com/stretchr/testify/assert"
)
func TestCommandName(t *testing.T) {
testCases := []struct {
name string
str string
target string
matches bool
prefix bool
}{
{"foobar", "foobar", "foobarr", false, false},
{"foobar", "foobar", "foobar", true, true},
{"foobar", "foobar", "foo", false, true},
{"foobar", "foobar", "", false, true},
{"foo[bar]", "foobar", "foobarr", false, false},
{"foo[bar]", "foobar", "foobar", true, true},
{"foo[bar]", "foobar", "foob", true, true},
{"foo[bar]", "foobar", "foo", true, true},
{"foo[bar]", "foobar", "fo", false, true},
{"foo[bar]", "foobar", "", false, true},
{"foo[bar]", "foobar", "foo[bar]", false, false},
{"foo[bar]", "foobar", "foobar]", false, false},
{"foo[bar]", "foobar", "foo[]", false, false},
{"foo[bar]", "foobar", "foo[", false, false},
{"foo[bar]", "foobar", "[", false, false},
{"[bar]", "bar", "foobar", false, false},
{"[bar]", "bar", "bar", true, true},
{"[bar]", "bar", "bra", false, false},
{"[bar]", "bar", "ba", true, true},
{"[bar]", "bar", "", true, true},
}
for _, tc := range testCases {
t.Run(tc.name+"/"+tc.target, func(t *testing.T) {
cn := commandName(tc.name)
assert.Equal(t, tc.str, fmt.Sprint(cn))
assert.Equal(t, tc.matches, cn.matches(tc.target))
assert.Equal(t, tc.prefix, cn.matchesPrefix(tc.target))
})
}
}