elvish/glob/parse_test.go

40 lines
952 B
Go
Raw Normal View History

2016-02-08 02:33:57 +08:00
package glob
import (
"reflect"
"testing"
)
var parseCases = []struct {
src string
want []Segment
2016-02-08 02:33:57 +08:00
}{
{``, []Segment{}},
{`foo`, []Segment{{Literal, "foo"}}},
{`*foo*bar`, []Segment{
{Star, ""}, {Literal, "foo"}, {Star, ""}, {Literal, "bar"}}},
{`foo**bar`, []Segment{
{Literal, "foo"}, {StarStar, ""}, {Literal, "bar"}}},
{`/usr/a**b/c`, []Segment{
2016-02-08 02:33:57 +08:00
{Slash, ""}, {Literal, "usr"}, {Slash, ""}, {Literal, "a"},
{StarStar, ""}, {Literal, "b"}, {Slash, ""}, {Literal, "c"}}},
{`??b`, []Segment{
{Question, ""}, {Question, ""}, {Literal, "b"}}},
2016-02-17 07:44:35 +08:00
// Multiple slashes should be parsed as one.
{`//a//b`, []Segment{
{Slash, ""}, {Literal, "a"}, {Slash, ""}, {Literal, "b"}}},
2016-02-17 07:44:35 +08:00
// Escaping.
{`\*\?b`, []Segment{
2016-02-17 07:44:35 +08:00
{Literal, "*?b"},
}},
2016-02-08 02:33:57 +08:00
}
func TestParse(t *testing.T) {
for _, tc := range parseCases {
p := Parse(tc.src)
if !reflect.DeepEqual(p.Segments, tc.want) {
2016-02-08 02:33:57 +08:00
t.Errorf("Parse(%q) => %v, want %v", p, tc.want)
}
}
}