fix nested files

This commit is contained in:
Eyal Posener 2017-05-13 00:40:26 +03:00
parent f580110640
commit bc5d682221
5 changed files with 21 additions and 10 deletions

View File

@ -81,11 +81,11 @@ func TestCompleter_Complete(t *testing.T) {
},
{
args: "sub2 ",
want: []string{"./", "./dir/", "./readme.md", "-flag2", "-flag3", "-h", "-global1", "-o"},
want: []string{"./", "./dir/", "./outer/", "./readme.md", "-flag2", "-flag3", "-h", "-global1", "-o"},
},
{
args: "sub2 ./",
want: []string{"./", "./readme.md", "./dir/"},
want: []string{"./", "./readme.md", "./dir/", "./outer/"},
},
{
args: "sub2 re",
@ -93,7 +93,7 @@ func TestCompleter_Complete(t *testing.T) {
},
{
args: "sub2 -flag2 ",
want: []string{"./", "./dir/", "./readme.md", "-flag2", "-flag3", "-h", "-global1", "-o"},
want: []string{"./", "./dir/", "./outer/", "./readme.md", "-flag2", "-flag3", "-h", "-global1", "-o"},
},
{
args: "sub1 -fl",
@ -129,7 +129,7 @@ func TestCompleter_Complete(t *testing.T) {
},
{
args: "-o ",
want: append(testTXTFiles, "./", "./dir/"),
want: append(testTXTFiles, "./", "./dir/", "./outer/"),
},
{
args: "-o ./no-su",
@ -137,7 +137,7 @@ func TestCompleter_Complete(t *testing.T) {
},
{
args: "-o ./",
want: append(testTXTFiles, "./", "./dir/"),
want: append(testTXTFiles, "./", "./dir/", "./outer/"),
},
{
args: "-o ./read",

View File

@ -5,7 +5,6 @@ import "github.com/posener/complete"
var (
ellipsis = complete.PredictSet("./...")
mainPackages = predictPackages("main")
anyPackage = predictPackages("")
goFiles = complete.PredictFiles("*.go")
anyFile = complete.PredictFiles("*")

View File

@ -107,7 +107,7 @@ func listFiles(dir, pattern string, allowFiles bool) []string {
if dirs, err := ioutil.ReadDir(dir); err == nil {
for _, d := range dirs {
if d.IsDir() {
m[d.Name()] = true
m[filepath.Join(dir, d.Name())] = true
}
}
}

View File

@ -60,7 +60,7 @@ func TestPredicate(t *testing.T) {
{
name: "files/txt",
p: PredictFiles("*.txt"),
want: []string{"./", "./dir/", "./a.txt", "./b.txt", "./c.txt", "./.dot.txt"},
want: []string{"./", "./dir/", "./outer/", "./a.txt", "./b.txt", "./c.txt", "./.dot.txt"},
},
{
name: "files/txt",
@ -84,7 +84,7 @@ func TestPredicate(t *testing.T) {
name: "files/md",
p: PredictFiles("*.md"),
argList: []string{"", ".", "./"},
want: []string{"./", "./dir/", "./readme.md"},
want: []string{"./", "./dir/", "./outer/", "./readme.md"},
},
{
name: "dirs",
@ -102,7 +102,19 @@ func TestPredicate(t *testing.T) {
name: "root directories",
p: PredictDirs("*"),
argList: []string{"", ".", "./"},
want: []string{"./", "./dir/"},
want: []string{"./", "./dir/", "./outer/"},
},
{
name: "nested directories",
p: PredictDirs("*.md"),
argList: []string{"ou", "./ou", "./outer", "./outer/"},
want: []string{"./outer/", "./outer/inner/"},
},
{
name: "nested inner directory",
p: PredictFiles("*.md"),
argList: []string{"outer/i"},
want: []string{"./outer/inner/", "./outer/inner/readme.md"},
},
}

View File