-
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* allow editor arguments * use strings.Fields
- Loading branch information
1 parent
14601be
commit 8a04d0f
Showing
4 changed files
with
73 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package editor | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestGetCommandAndArgs(t *testing.T) { | ||
testcases := []struct { | ||
name string | ||
editor string | ||
file string | ||
expectedCommand string | ||
expectedArgs []string | ||
}{ | ||
{ | ||
name: "single word editor vim", | ||
editor: "vim", | ||
file: "some-file.txt", | ||
expectedCommand: "vim", | ||
expectedArgs: []string{"some-file.txt"}, | ||
}, | ||
{ | ||
name: "single word editor code", | ||
editor: "code", | ||
file: "some-file.txt", | ||
expectedCommand: "code", | ||
expectedArgs: []string{"some-file.txt"}, | ||
}, | ||
{ | ||
name: "code with arguments", | ||
editor: "code --wait", | ||
file: "some-file.txt", | ||
expectedCommand: "code", | ||
expectedArgs: []string{"--wait", "some-file.txt"}, | ||
}, | ||
{ | ||
name: "code with arguments and inconsistent spacing", | ||
editor: "code --wait", | ||
file: "some-file.txt", | ||
expectedCommand: "code", | ||
expectedArgs: []string{"--wait", "some-file.txt"}, | ||
}, | ||
} | ||
|
||
for _, tc := range testcases { | ||
t.Run(tc.name, func(t *testing.T) { | ||
command, args := getCommandAndArgs(tc.editor, tc.file) | ||
assert.Equal(t, tc.expectedCommand, command) | ||
assert.Equal(t, tc.expectedArgs, args) | ||
}) | ||
} | ||
} |