forked from elves/elvish
-
Notifications
You must be signed in to change notification settings - Fork 0
/
parse_test.go
43 lines (40 loc) · 1.01 KB
/
parse_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
package glob
import (
"reflect"
"testing"
)
var parseCases = []struct {
src string
want []Segment
}{
{``, []Segment{}},
{`foo`, []Segment{Literal{"foo"}}},
{`*foo*bar`, []Segment{
Wild{Star, false, nil}, Literal{"foo"},
Wild{Star, false, nil}, Literal{"bar"}}},
{`foo**bar`, []Segment{
Literal{"foo"}, Wild{StarStar, false, nil}, Literal{"bar"}}},
{`/usr/a**b/c`, []Segment{
Slash{}, Literal{"usr"}, Slash{}, Literal{"a"},
Wild{StarStar, false, nil}, Literal{"b"}, Slash{}, Literal{"c"}}},
{`??b`, []Segment{
Wild{Question, false, nil}, Wild{Question, false, nil}, Literal{"b"}}},
// Multiple slashes should be parsed as one.
{`//a//b`, []Segment{
Slash{}, Literal{"a"}, Slash{}, Literal{"b"}}},
// Escaping.
{`\*\?b`, []Segment{
Literal{"*?b"},
}},
{`abc\`, []Segment{
Literal{"abc"},
}},
}
func TestParse(t *testing.T) {
for _, tc := range parseCases {
p := Parse(tc.src)
if !reflect.DeepEqual(p.Segments, tc.want) {
t.Errorf("Parse(%q) => %v, want %v", tc.src, p, tc.want)
}
}
}