| 1 |
package commands |
| 2 |
|
| 3 |
import ( |
| 4 |
"os" |
| 5 |
"testing" |
| 6 |
|
| 7 |
"github.com/stretchr/testify/assert" |
| 8 |
) |
| 9 |
|
| 10 |
func TestCompletePath(t *testing.T) { |
| 11 |
os.Chdir("testdata") |
| 12 |
defer os.Chdir("..") |
| 13 |
|
| 14 |
vectors := []struct { |
| 15 |
arg string |
| 16 |
onlyDirs bool |
| 17 |
fuzzyComplete bool |
| 18 |
expected []string |
| 19 |
}{ |
| 20 |
{ |
| 21 |
arg: "", |
| 22 |
expected: []string{"Foobar", "baz/", "foo.ini", "foo/"}, |
| 23 |
}, |
| 24 |
{ |
| 25 |
arg: "", |
| 26 |
onlyDirs: true, |
| 27 |
expected: []string{"baz/", "foo/"}, |
| 28 |
}, |
| 29 |
{ |
| 30 |
arg: ".", |
| 31 |
expected: []string{".hidden/", ".keep-me"}, |
| 32 |
}, |
| 33 |
{ |
| 34 |
arg: "fo", |
| 35 |
expected: []string{"Foobar", "foo.ini", "foo/"}, |
| 36 |
}, |
| 37 |
{ |
| 38 |
arg: "Fo", |
| 39 |
expected: []string{"Foobar"}, |
| 40 |
}, |
| 41 |
{ |
| 42 |
arg: "..", |
| 43 |
expected: []string{"../"}, |
| 44 |
}, |
| 45 |
{ |
| 46 |
arg: "../..", |
| 47 |
expected: []string{"../../"}, |
| 48 |
}, |
| 49 |
{ |
| 50 |
arg: "../testdata/", |
| 51 |
expected: []string{ |
| 52 |
"../testdata/Foobar", |
| 53 |
"../testdata/baz/", |
| 54 |
"../testdata/foo.ini", |
| 55 |
"../testdata/foo/", |
| 56 |
}, |
| 57 |
}, |
| 58 |
{ |
| 59 |
arg: "../testdata/f", |
| 60 |
onlyDirs: true, |
| 61 |
expected: []string{"../testdata/foo/"}, |
| 62 |
}, |
| 63 |
{ |
| 64 |
arg: "oo", |
| 65 |
expected: []string{}, |
| 66 |
}, |
| 67 |
{ |
| 68 |
arg: "oo", |
| 69 |
fuzzyComplete: true, |
| 70 |
expected: []string{"Foobar", "foo.ini", "foo/"}, |
| 71 |
}, |
| 72 |
{ |
| 73 |
arg: "../testdata/oo", |
| 74 |
expected: []string{}, |
| 75 |
}, |
| 76 |
{ |
| 77 |
arg: "../testdata/oo", |
| 78 |
fuzzyComplete: true, |
| 79 |
expected: []string{"../testdata/Foobar", "../testdata/foo.ini", "../testdata/foo/"}, |
| 80 |
}, |
| 81 |
} |
| 82 |
for _, vec := range vectors { |
| 83 |
t.Run(vec.arg, func(t *testing.T) { |
| 84 |
res := completePath(vec.arg, vec.onlyDirs, vec.fuzzyComplete) |
| 85 |
assert.Equal(t, vec.expected, res) |
| 86 |
}) |
| 87 |
} |
| 88 |
} |