Ejemplo n.º 1
0
	// Output capture
	{"put (put lorem ipsum)", strs("lorem", "ipsum"), nomore},

	// Boolean capture
	{"put ?(true) ?(false)",
		[]Value{Bool(true), Bool(false)}, 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},

	// Wildcard.
	{"put /*", strs(util.FullNames("/")...), nomore},

	// Tilde.
	{"h=$E:HOME; E:HOME=/foo; put ~ ~/src; E:HOME=$h",
		strs("/foo", "/foo/src"), nomore},

	// Closure
	// Basics
	{"[]{ }", noout, 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",
Ejemplo n.º 2
0
	{"l*m", []string{"lorem"}},
	{"d*", []string{"d1", "d2", "dX", "dXY"}},
	{"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", "dXY"}},
	{"?", []string{"a", "b", "c"}},
	{"??", []string{"d1", "d2", "dX"}},

	// Nonexistent paths.
	{"xxxx", []string{}},
	{"xxxx/*", []string{}},
	{"a/*/", []string{}},

	// Absolute paths.
	// NOTE: If / or /usr changes during testing, this case will fail.
	{"/*", util.FullNames("/")},
	{"/usr/*", util.FullNames("/usr/")},

	// TODO Test cases against dotfiles.
}

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 append(mkdirs, mkdirDots...) {
		err := os.Mkdir(dir, 0755)