diff options
| author | Eyal Posener <[email protected]> | 2019-11-14 06:51:44 +0200 |
|---|---|---|
| committer | Eyal Posener <[email protected]> | 2019-11-18 01:05:47 +0200 |
| commit | 8724aaf18312e54750540a9578e00d61b1c545d8 (patch) | |
| tree | d3e736b4fb279975bbcc017ae1bad53e454c5773 /args_test.go | |
| parent | 05b68ffc813dd10c420993cb1cf927b346c057b8 (diff) | |
V2
Diffstat (limited to 'args_test.go')
| -rw-r--r-- | args_test.go | 213 |
1 files changed, 0 insertions, 213 deletions
diff --git a/args_test.go b/args_test.go deleted file mode 100644 index 3b42db0..0000000 --- a/args_test.go +++ /dev/null @@ -1,213 +0,0 @@ -package complete - -import ( - "fmt" - "strings" - "testing" - - "github.com/stretchr/testify/assert" -) - -func TestArgs(t *testing.T) { - t.Parallel() - tests := []struct { - line string - completed string - last string - lastCompleted string - }{ - { - line: "a b c", - completed: "b", - last: "c", - lastCompleted: "b", - }, - { - line: "a b ", - completed: "b", - last: "", - lastCompleted: "b", - }, - { - line: "", - completed: "", - last: "", - lastCompleted: "", - }, - { - line: "a", - completed: "", - last: "a", - lastCompleted: "", - }, - { - line: "a ", - completed: "", - last: "", - lastCompleted: "", - }, - } - - for _, tt := range tests { - t.Run(tt.line, func(t *testing.T) { - - a := newArgs(tt.line) - - if got, want := strings.Join(a.Completed, " "), tt.completed; got != want { - t.Errorf("%s failed: Completed = %q, want %q", t.Name(), got, want) - } - if got, want := a.Last, tt.last; got != want { - t.Errorf("Last = %q, want %q", got, want) - } - if got, want := a.LastCompleted, tt.lastCompleted; got != want { - t.Errorf("%s failed: LastCompleted = %q, want %q", t.Name(), got, want) - } - }) - } -} - -func TestArgs_From(t *testing.T) { - t.Parallel() - tests := []struct { - line string - from int - newLine string - newCompleted string - }{ - { - line: "a b c", - from: 0, - newLine: "b c", - newCompleted: "b", - }, - { - line: "a b c", - from: 1, - newLine: "c", - newCompleted: "", - }, - { - line: "a b c", - from: 2, - newLine: "", - newCompleted: "", - }, - { - line: "a b c", - from: 3, - newLine: "", - newCompleted: "", - }, - { - line: "a b c ", - from: 0, - newLine: "b c ", - newCompleted: "b c", - }, - { - line: "a b c ", - from: 1, - newLine: "c ", - newCompleted: "c", - }, - { - line: "a b c ", - from: 2, - newLine: "", - newCompleted: "", - }, - { - line: "", - from: 0, - newLine: "", - newCompleted: "", - }, - { - line: "", - from: 1, - newLine: "", - newCompleted: "", - }, - } - - for _, tt := range tests { - t.Run(fmt.Sprintf("%s/%d", tt.line, tt.from), func(t *testing.T) { - - a := newArgs("cmd " + tt.line) - n := a.from(tt.from) - - assert.Equal(t, tt.newLine, strings.Join(n.All, " ")) - assert.Equal(t, tt.newCompleted, strings.Join(n.Completed, " ")) - }) - } -} - -func TestArgs_Directory(t *testing.T) { - t.Parallel() - initTests() - - tests := []struct { - line string - directory string - }{ - { - line: "a b c", - directory: "./", - }, - { - line: "a b c /tm", - directory: "/", - }, - { - line: "a b c /tmp", - directory: "/tmp/", - }, - { - line: "a b c /tmp ", - directory: "./", - }, - { - line: "a b c ./", - directory: "./", - }, - { - line: "a b c ./dir", - directory: "./dir/", - }, - { - line: "a b c dir", - directory: "dir/", - }, - { - line: "a b c ./di", - directory: "./", - }, - { - line: "a b c ./dir ", - directory: "./", - }, - { - line: "a b c ./di", - directory: "./", - }, - { - line: "a b c ./a.txt", - directory: "./", - }, - { - line: "a b c ./a.txt/x", - directory: "./", - }, - } - - for _, tt := range tests { - t.Run(tt.line, func(t *testing.T) { - - a := newArgs(tt.line) - - if got, want := a.Directory(), tt.directory; got != want { - t.Errorf("%s failed: directory = %q, want %q", t.Name(), got, want) - } - }) - } -} |
