forked from ggicci/owl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
directive_test.go
68 lines (61 loc) · 1.36 KB
/
directive_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
package owl_test
import (
"testing"
"github.com/ggicci/owl"
"github.com/stretchr/testify/assert"
)
func TestNewDirective(t *testing.T) {
assert := assert.New(t)
d1 := owl.NewDirective("form")
assert.Equal("form", d1.Name)
assert.Len(d1.Argv, 0)
d2 := owl.NewDirective("form", "page", "page_index")
assert.Equal("form", d2.Name)
assert.NotNil(d2.Argv)
assert.Len(d2.Argv, 2)
assert.Equal("page", d2.Argv[0])
assert.Equal("page_index", d2.Argv[1])
}
func TestParseDirective(t *testing.T) {
testcases := []struct {
content string
expected *owl.Directive
err error
}{
{
content: "form",
expected: owl.NewDirective("form"),
err: nil,
},
{
content: "form=page,page_index",
expected: owl.NewDirective("form", "page", "page_index"),
err: nil,
},
{
content: "header=x-api-token",
expected: owl.NewDirective("header", "x-api-token"),
err: nil,
},
{
content: "",
expected: nil,
err: owl.ErrInvalidDirectiveName,
},
{
content: "=name",
expected: nil,
err: owl.ErrInvalidDirectiveName,
},
{
content: " =name",
expected: nil,
err: owl.ErrInvalidDirectiveName,
},
}
for _, testcase := range testcases {
directive, err := owl.ParseDirective(testcase.content)
assert.Equal(t, testcase.expected, directive)
assert.ErrorIs(t, err, testcase.err)
}
}