-
Notifications
You must be signed in to change notification settings - Fork 0
/
path_test.go
46 lines (44 loc) · 1.31 KB
/
path_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
package bacom
import (
"testing"
)
func TestMatchPath(t *testing.T) {
for _, test := range []struct {
Pattern string
Input string
Expected bool
Error bool
}{
{"*", "foo", true, false},
{"/*", "", true, false},
{"/*", "/foo", true, false},
{"/foo/*", "/foo/bar", true, false},
{"/foo/bar", "/foo/bar", true, false},
{"/foo", "/foo/bar", false, false},
{"/foo/bar", "/foo", false, false},
{"/**", "/foo/bar", true, false},
{"/foo/**/bar", "/foo/bar", true, false},
{"/foo/**/bar", "/foo/fizz/bar", true, false},
{"/foo/**/bar", "/foo/fizz/buzz/bar", true, false},
{"/foo*", "/foobar", true, false},
{"/foo*", "/bar", false, false},
{"/*foo", "/foo", true, false},
{"/*foo", "/barfoo", true, false},
{"/*foo", "/bar", false, false},
{"/foo/**/bar", "/bar/bar", false, false},
{"/[-]/**/bar", "/bar/bar", false, true},
{"[-]", "/bar", false, true},
{"", "", true, false},
} {
ok, err := MatchPath(test.Pattern, test.Input)
if !test.Error && err != nil {
t.Errorf("Match(%q, %q): unexpected error: %s", test.Pattern, test.Input, err)
}
if test.Error && err == nil {
t.Errorf("Match(%q, %q): expected error, got nil", test.Pattern, test.Input)
}
if ok != test.Expected {
t.Errorf("Match(%q, %q) = %v, expected %v", test.Pattern, test.Input, ok, test.Expected)
}
}
}