/
masker_test.go
113 lines (105 loc) · 5.92 KB
/
masker_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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
package matcher
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestMasker(t *testing.T) {
tokens := Masker("run")
assert.Equal(t, tokens[0].Name, "run", "they should be equal")
assert.Equal(t, tokens[0].Required, true, "they should be equal")
assert.Equal(t, tokens[0].Type, "text", "they should be equal")
assert.Equal(t, tokens[0].ShortFlag, false, "they should be equal")
assert.Equal(t, tokens[0].LongFlag, false, "they should be equal")
assert.Equal(t, len(tokens), 1, "they should be equal")
}
func TestMaskerExtraSpaces(t *testing.T) {
tokens := Masker("run away ")
assert.Equal(t, tokens[0].Name, "run", "they should be equal")
assert.Equal(t, tokens[0].Required, true, "they should be equal")
assert.Equal(t, tokens[0].Type, "text", "they should be equal")
assert.Equal(t, tokens[0].ShortFlag, false, "they should be equal")
assert.Equal(t, tokens[0].LongFlag, false, "they should be equal")
assert.Equal(t, tokens[1].Name, "away", "they should be equal")
assert.Equal(t, tokens[1].Required, true, "they should be equal")
assert.Equal(t, tokens[1].Type, "text", "they should be equal")
assert.Equal(t, tokens[1].ShortFlag, false, "they should be equal")
assert.Equal(t, tokens[1].LongFlag, false, "they should be equal")
assert.Equal(t, len(tokens), 2, "they should be equal")
}
func TestMaskerFlags(t *testing.T) {
tokens := Masker("run <--fast> [-x]")
assert.Equal(t, tokens[0].Name, "run", "they should be equal")
assert.Equal(t, tokens[0].Required, true, "they should be equal")
assert.Equal(t, tokens[0].Type, "text", "they should be equal")
assert.Equal(t, tokens[0].ShortFlag, false, "they should be equal")
assert.Equal(t, tokens[0].LongFlag, false, "they should be equal")
assert.Equal(t, tokens[1].Name, "fast", "they should be equal")
assert.Equal(t, tokens[1].Required, true, "they should be equal")
assert.Equal(t, tokens[1].Type, "string", "they should be equal")
assert.Equal(t, tokens[1].ShortFlag, false, "they should be equal")
assert.Equal(t, tokens[1].LongFlag, true, "they should be equal")
assert.Equal(t, tokens[2].Name, "x", "they should be equal")
assert.Equal(t, tokens[2].Required, false, "they should be equal")
assert.Equal(t, tokens[2].Type, "string", "they should be equal")
assert.Equal(t, tokens[2].ShortFlag, true, "they should be equal")
assert.Equal(t, tokens[2].LongFlag, false, "they should be equal")
assert.Equal(t, len(tokens), 3, "they should be equal")
}
func TestMaskerQuotes(t *testing.T) {
tokens := Masker("run \"very far\" 'away and away'")
assert.Equal(t, tokens[0].Name, "run", "they should be equal")
assert.Equal(t, tokens[0].Required, true, "they should be equal")
assert.Equal(t, tokens[0].Type, "text", "they should be equal")
assert.Equal(t, tokens[0].ShortFlag, false, "they should be equal")
assert.Equal(t, tokens[0].LongFlag, false, "they should be equal")
assert.Equal(t, tokens[1].Name, "very far", "they should be equal")
assert.Equal(t, tokens[1].Required, true, "they should be equal")
assert.Equal(t, tokens[1].Type, "text", "they should be equal")
assert.Equal(t, tokens[1].ShortFlag, false, "they should be equal")
assert.Equal(t, tokens[1].LongFlag, false, "they should be equal")
assert.Equal(t, tokens[2].Name, "away and away", "they should be equal")
assert.Equal(t, tokens[2].Required, true, "they should be equal")
assert.Equal(t, tokens[2].Type, "text", "they should be equal")
assert.Equal(t, tokens[2].ShortFlag, false, "they should be equal")
assert.Equal(t, tokens[2].LongFlag, false, "they should be equal")
assert.Equal(t, len(tokens), 3, "they should be equal")
}
func TestMaskerRules(t *testing.T) {
tokens := Masker("run <speed> [distance] away")
assert.Equal(t, tokens[0].Name, "run", "they should be equal")
assert.Equal(t, tokens[0].Required, true, "they should be equal")
assert.Equal(t, tokens[0].Type, "text", "they should be equal")
assert.Equal(t, tokens[0].ShortFlag, false, "they should be equal")
assert.Equal(t, tokens[0].LongFlag, false, "they should be equal")
assert.Equal(t, tokens[1].Name, "speed", "they should be equal")
assert.Equal(t, tokens[1].Required, true, "they should be equal")
assert.Equal(t, tokens[1].Type, "string", "they should be equal")
assert.Equal(t, tokens[1].ShortFlag, false, "they should be equal")
assert.Equal(t, tokens[1].LongFlag, false, "they should be equal")
assert.Equal(t, tokens[2].Name, "distance", "they should be equal")
assert.Equal(t, tokens[2].Required, false, "they should be equal")
assert.Equal(t, tokens[2].Type, "string", "they should be equal")
assert.Equal(t, tokens[2].ShortFlag, false, "they should be equal")
assert.Equal(t, tokens[2].LongFlag, false, "they should be equal")
assert.Equal(t, tokens[3].Name, "away", "they should be equal")
assert.Equal(t, tokens[3].Required, true, "they should be equal")
assert.Equal(t, tokens[3].Type, "text", "they should be equal")
assert.Equal(t, tokens[3].ShortFlag, false, "they should be equal")
assert.Equal(t, tokens[3].LongFlag, false, "they should be equal")
assert.Equal(t, len(tokens), 4, "they should be equal")
}
func TestMaskerTypes(t *testing.T) {
tokens := Masker("run <speed(string)> [distance(int)] [enthusiasm(list:low,high)] [--jump(bool)]")
assert.Equal(t, tokens[0].Name, "run", "they should be equal")
assert.Equal(t, tokens[0].Type, "text", "they should be equal")
assert.Equal(t, tokens[1].Name, "speed", "they should be equal")
assert.Equal(t, tokens[1].Type, "string", "they should be equal")
assert.Equal(t, tokens[1].Valid, "*", "they should be equal")
assert.Equal(t, tokens[2].Name, "distance", "they should be equal")
assert.Equal(t, tokens[2].Type, "int", "they should be equal")
assert.Equal(t, tokens[3].Name, "enthusiasm", "they should be equal")
assert.Equal(t, tokens[3].Type, "list", "they should be equal")
assert.Equal(t, tokens[3].Valid, "low,high", "they should be equal")
assert.Equal(t, tokens[4].Name, "jump", "they should be equal")
assert.Equal(t, tokens[4].Type, "bool", "they should be equal")
}