-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathutil_test.go
57 lines (53 loc) · 1.3 KB
/
util_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
56
57
package urlrouter
import (
"reflect"
"testing"
)
func Test_NextSeparator(t *testing.T) {
for _, testcase := range []struct {
path string
start int
expected interface{}
}{
{"/path/to/route", 0, 0},
{"/path/to/route", 1, 5},
{"/path/to/route", 9, 14},
{"/path.html", 1, 5},
{"/foo/bar.html", 1, 4},
{"/foo/bar.html/baz.png", 5, 8},
{"/foo/bar.html/baz.png", 10, 13},
} {
actual := NextSeparator(testcase.path, testcase.start)
expected := testcase.expected
if !reflect.DeepEqual(actual, expected) {
t.Errorf("path = %q, start = %v expect %v, but %v", testcase.path, testcase.start, expected, actual)
}
}
}
func Test_IsMetaChar(t *testing.T) {
for _, c := range []byte{':', '*'} {
if !IsMetaChar(c) {
t.Errorf("Expect %q is meta charcter, but isn't", c)
}
}
for c := byte(0); c < 0xff && c != ':' && c != '*'; c++ {
if IsMetaChar(c) {
t.Errorf("Expect %q is not meta character, but isn't", c)
}
}
}
func Test_ParamNames(t *testing.T) {
for path, expected := range map[string][]string{
"/:a": {":a"},
"/:b": {":b"},
"/:a/:b": {":a", ":b"},
"/:ab": {":ab"},
"/*w": {"*w"},
"/*w/:p": {"*w", ":p"},
} {
actual := ParamNames(path)
if !reflect.DeepEqual(actual, expected) {
t.Errorf("%q expects %q, but %q", path, expected, actual)
}
}
}