Ejemplo n.º 1
0
	pattern string
	want    []string
}{
	{"*", []string{"a", "b", "c", "d1", "d2", "dX", "lorem", "ipsum"}},
	{"*/", []string{"a/", "b/", "c/", "d1/", "d2/"}},
	{"**", append(mkdirs, creates...)},
	{"*/X", []string{"a/X", "b/X"}},
	{"**X", []string{"a/X", "b/X", "dX", "d1/e/f/g/X", "d2/e/f/g/X"}},
	{"*/*/*", []string{"d1/e/f", "d2/e/f"}},
	{"l*m", []string{"lorem"}},
	{"d*", []string{"d1", "d2", "dX"}},
	{"d*/", []string{"d1/", "d2/"}},
	{"d**", []string{"d1", "d1/e", "d1/e/f", "d1/e/f/g", "d1/e/f/g/X",
		"d2", "d2/e", "d2/e/f", "d2/e/f/g", "d2/e/f/g/X", "dX"}},
	// NOTE: If / changes during testing, this case will fail.
	{"/*", osutil.RootNames()},
}

func TestGlob(t *testing.T) {
	tmpdir, err := ioutil.TempDir("", "glob-test")
	if err != nil {
		panic(err)
	}
	defer os.RemoveAll(tmpdir)
	os.Chdir(tmpdir)

	for _, dir := range mkdirs {
		err := os.Mkdir(dir, 0755)
		if err != nil {
			panic(err)
		}
Ejemplo n.º 2
0
			Error{errors.New("1")})}, nomore},

	// Variable and compounding
	{"x='SHELL'\nput 'WOW, SUCH '$x', MUCH COOL'\n",
		strs("WOW, SUCH SHELL, MUCH COOL"), nomore},
	// Splicing
	{"x=[elvish rules]; put $@x", strs("elvish", "rules"), nomore},

	// List element assignment
	{"li=[foo bar]; li[0]=233; put-all $li", strs("233", "bar"), nomore},
	// Map element assignment
	{"di=[&k v]; di[k]=lorem; di[k2]=ipsum; put $di[k] $di[k2]",
		strs("lorem", "ipsum"), nomore},

	// Wildcard.
	{"put /*", strs(osutil.RootNames()...), nomore},

	// Closure
	// Basics
	{"[]{ }", strs(), nomore},
	{"[x]{put $x} foo", strs("foo"), nomore},
	// Variable capture
	{"x=lorem; []{x=ipsum}; put $x", strs("ipsum"), nomore},
	{"x=lorem; []{ put $x; x=ipsum }; put $x",
		strs("lorem", "ipsum"), nomore},
	// Shadowing
	{"x=ipsum; []{ local:x=lorem; put $x }; put $x",
		strs("lorem", "ipsum"), nomore},
	// Shadowing by argument
	{"x=ipsum; [x]{ put $x; x=BAD } lorem; put $x",
		strs("lorem", "ipsum"), nomore},