mirror of
https://github.com/go-sylixos/elvish.git
synced 2024-12-05 03:17:50 +08:00
4d567f406f
This fixes #134.
40 lines
952 B
Go
40 lines
952 B
Go
package glob
|
|
|
|
import (
|
|
"reflect"
|
|
"testing"
|
|
)
|
|
|
|
var parseCases = []struct {
|
|
src string
|
|
want []Segment
|
|
}{
|
|
{``, []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{
|
|
{Slash, ""}, {Literal, "usr"}, {Slash, ""}, {Literal, "a"},
|
|
{StarStar, ""}, {Literal, "b"}, {Slash, ""}, {Literal, "c"}}},
|
|
{`??b`, []Segment{
|
|
{Question, ""}, {Question, ""}, {Literal, "b"}}},
|
|
// Multiple slashes should be parsed as one.
|
|
{`//a//b`, []Segment{
|
|
{Slash, ""}, {Literal, "a"}, {Slash, ""}, {Literal, "b"}}},
|
|
// Escaping.
|
|
{`\*\?b`, []Segment{
|
|
{Literal, "*?b"},
|
|
}},
|
|
}
|
|
|
|
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", p, tc.want)
|
|
}
|
|
}
|
|
}
|