forked from zaccone/spf
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtoken_test.go
52 lines (47 loc) · 1.01 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
package spf
import "testing"
func TestTokenSyntaxValidation(t *testing.T) {
type TokenTestCase struct {
token *token
delimiter rune
expected bool
}
tests := []TokenTestCase{
{nil, rune('='), false},
{
&token{
mechanism: tInclude, qualifier: qPlus, value: "matching.com",
}, rune(':'), true,
},
{
&token{
mechanism: tInclude, qualifier: qPlus, value: "",
}, rune(':'), false,
},
{
&token{
mechanism: tErr, qualifier: qErr, value: "",
}, rune('='), true,
},
{
&token{
mechanism: tAll, qualifier: qMinus, value: "matching.com",
}, rune(':'), true,
},
{
&token{
mechanism: tAll, qualifier: qMinus, value: "matching.com",
}, rune('='), false,
},
}
for _, test := range tests {
token := test.token
delimiter := test.delimiter
expected := test.expected
if checkTokenSyntax(token, delimiter) != expected {
t.Errorf(
"Error: For token %v, delimiter %v got result %v, expected %v\n",
*token, delimiter, !expected, expected)
}
}
}