-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtoken_test.go
54 lines (51 loc) · 1.32 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
package strparam
import (
"testing"
)
func TestToken_Equal(t *testing.T) {
tests := []struct {
name string
token1 Token
token2 Token
want bool
}{
{"", ConstToken("C"), ConstToken("C"), true},
{"", ConstToken("C"), ConstToken("c"), false},
{"", ConstToken("C"), SeparatorToken("C"), false},
{"", ConstToken("C"), SeparatorToken("c"), false},
{"", ParameterToken("C"), ParsedParameterToken("C", "val"), false},
{"", ParameterToken("C"), ParsedParameterToken("C", ""), false},
{"", StartToken, EndToken, false},
{"", EndToken, EndToken, true},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := tt.token1.Equal(tt.token2); got != tt.want {
t.Errorf("Token.Equal() = %v, want %v", got, tt.want)
}
})
}
}
func TestToken_ParamName(t *testing.T) {
tests := []struct {
name string
token Token
want string
}{
{"", ConstToken("C"), ""},
{"", SeparatorToken("C"), ""},
{"", ParameterToken("C"), "C"},
{"", ParameterToken("c"), "c"},
{"", ParsedParameterToken("c", "val"), "c"},
{"", ParsedParameterToken("C", "val"), "C"},
{"", EndToken, ""},
{"", StartToken, ""},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := tt.token.ParamName(); got != tt.want {
t.Errorf("Token.ParamName() = %v, want %v", got, tt.want)
}
})
}
}