-
Notifications
You must be signed in to change notification settings - Fork 1
/
regexp_test.go
93 lines (87 loc) · 1.81 KB
/
regexp_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
package commander
import (
"github.com/WindomZ/testify/assert"
"testing"
)
func TestRegexp_RegexpCommand(t *testing.T) {
assert.Equal(t,
regexpCommand("new <name>"),
[]string{"new"},
)
assert.Equal(t,
regexpCommand("ship <name> move <x> <y>"),
[]string{"ship"},
)
assert.Equal(t,
regexpCommand("(set|remove) <x> <y> [--moored|--drifting]"),
[]string{"set", "remove"},
)
}
func TestRegexp_RegexpArgument(t *testing.T) {
assert.Equal(t,
regexpArgument("new <name>"),
[]string{"<name>"},
)
assert.Equal(t,
regexpArgument("ship <name> move <x> <y>"),
[]string{"<name>", "<x>", "<y>"},
)
assert.Equal(t,
regexpArgument("(set|remove) <x> <y> [--moored|--drifting]"),
[]string{"<x>", "<y>"},
)
}
func TestRegexp_RegexpOption(t *testing.T) {
assert.Equal(t,
regexpOption("new <name>"),
[]string(nil),
)
assert.Equal(t,
regexpOption("-p <x-y>"),
[]string{"-p"},
)
assert.Equal(t,
regexpOption("-p"),
[]string{"-p"},
)
assert.Equal(t,
regexpOption("-p, --pepper"),
[]string{"-p", "--pepper"},
)
assert.Equal(t,
regexpOption("--pepper"),
[]string{"--pepper"},
)
assert.Equal(t,
regexpOption("(set|remove) <x> <y> [--not-ss | -a | --moored|--drifting]"),
[]string{"--not-ss", "-a", "--moored", "--drifting"},
)
}
func TestRegexp_ReplaceCommand(t *testing.T) {
assert.Equal(t,
replaceCommand("new <name>", "new", "(new|n)"),
"(new|n) <name>",
)
assert.Equal(t,
replaceCommand("(new|n) <name>", "(new|n)", "(new|n|add)"),
"(new|n|add) <name>",
)
}
func TestRegexp_FirstParameter(t *testing.T) {
assert.Equal(t,
firstParameter("new <name>"),
"new",
)
assert.Equal(t,
firstParameter("(new|n|add) <name>"),
"(new|n|add)",
)
assert.Equal(t,
firstParameter("<hello> <world>"),
"<hello>",
)
assert.Equal(t,
firstParameter("--hello=<world>"),
"--hello",
)
}