-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtoken_test.go
89 lines (85 loc) · 1.9 KB
/
token_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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package prefixtree
import (
"errors"
"testing"
. "github.com/smartystreets/goconvey/convey"
)
func TestNodes(t *testing.T) {
Convey("Проверяем разворачивание path в Tokens", t, func() {
tests := []struct {
path string
expectedPath string
expectedError error
}{
{
path: "/path/:dir/*filepath",
expectedPath: "[/path/]:dir[/]*filepath",
expectedError: nil,
},
{
path: "/path/:dir/*filepath?",
expectedError: errors.New(`unexpected char "?"`),
},
{
path: "/path/:dir/*filepath 123",
expectedError: errors.New(`unexpected char " "`),
},
{
path: "/path/user_:user",
expectedPath: "[/path/user_]:user",
expectedError: nil,
},
{
path: "/path/user_:user/id",
expectedPath: "[/path/user_]:user[/id]",
expectedError: nil,
},
{
path: "/path/user_:user/id/:id",
expectedPath: "[/path/user_]:user[/id/]:id",
expectedError: nil,
},
{
path: "/id:id:name",
expectedError: errors.New("expected Static token"),
},
{
path: "/id:",
expectedError: errors.New("empty token value"),
},
{
path: "/id:/",
expectedError: errors.New("empty token value"),
},
{
path: "/id/*",
expectedError: errors.New("empty token value"),
},
}
for n, test := range tests {
Printf("\n\t#%d - %s ", n+1, test.path)
if test.expectedError != nil {
Printf("(error) ")
}
d := NewDecoder([]byte(test.path))
So(d, ShouldNotBeNil)
tokens, err := d.Tokens()
if test.expectedError != nil {
So(err, ShouldNotBeNil)
So(
err.Error(),
ShouldEqual,
test.expectedError.Error(),
)
} else {
So(err, ShouldBeNil)
So(tokens, ShouldNotBeNil)
So(
tokens.String(),
ShouldResemble,
test.expectedPath,
)
}
}
})
}