-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtokenize_test.go
72 lines (65 loc) · 1.26 KB
/
tokenize_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
package main
import (
"testing"
)
func TestTokenizeCommands(t *testing.T) {
tests := []struct {
name string
input string
output []string
}{
{
name: "empty",
input: "",
output: []string{},
},
{
name: "single",
input: "x/test/",
output: []string{"x/test/"},
},
{
name: "double",
input: "x/test/ y/blort/",
output: []string{"x/test/", "y/blort/"},
},
{
name: "x, y then p",
input: "x/test/ y/blort/ p",
output: []string{"x/test/", "y/blort/", "p"},
},
{
name: "no space between",
input: "x/test/y/blort/",
output: []string{"x/test/", "y/blort/"},
},
{
name: "extra spaces",
input: "x/test/ y/blort/",
output: []string{"x/test/", "y/blort/"},
},
{
name: "n command",
input: "x/test/ n[1:3]",
output: []string{"x/test/", "n[1:3]"},
},
{
name: "escape",
input: `x/\//`,
output: []string{`x/\//`},
},
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
cmds := tokenizeCommands(tc.input)
if len(cmds) != len(tc.output) {
t.Fatalf("Expected %#v but got %#v'", tc.output, cmds)
}
for i, c := range tc.output {
if c != cmds[i] {
t.Fatalf("Expected %#v but got %#v'", tc.output, cmds)
}
}
})
}
}