aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakob Unterwurzacher2016-10-09 20:54:40 +0200
committerJakob Unterwurzacher2016-10-09 20:54:40 +0200
commitb70d2ffd94805c139971ece3cd372dafea5c95f3 (patch)
treee82eeb733bc56db00a33b128dd94d7ac2ebd9972
parent2298726bc6cdebbf7c5c3e597c90b38b15adaebb (diff)
main: add tests for the "-o" parsing
-rw-r--r--cli_args_test.go52
1 files changed, 52 insertions, 0 deletions
diff --git a/cli_args_test.go b/cli_args_test.go
new file mode 100644
index 0000000..844a0b1
--- /dev/null
+++ b/cli_args_test.go
@@ -0,0 +1,52 @@
+package main
+
+import (
+ "reflect"
+ "testing"
+)
+
+type testcase struct {
+ // i is the input
+ i []string
+ // o is the expected output
+ o []string
+}
+
+func TestPrefixOArgs(t *testing.T) {
+ testcases := []testcase{
+ testcase{
+ i: nil,
+ o: nil,
+ },
+ testcase{
+ i: []string{"gocryptfs"},
+ o: []string{"gocryptfs"},
+ },
+ testcase{
+ i: []string{"gocryptfs", "-v"},
+ o: []string{"gocryptfs", "-v"},
+ },
+ testcase{
+ i: []string{"gocryptfs", "foo", "bar", "-v"},
+ o: []string{"gocryptfs", "foo", "bar", "-v"},
+ },
+ testcase{
+ i: []string{"gocryptfs", "foo", "bar", "-o", "a"},
+ o: []string{"gocryptfs", "-a", "foo", "bar"},
+ },
+ testcase{
+ i: []string{"gocryptfs", "foo", "bar", "-o", "a,b,xxxxx"},
+ o: []string{"gocryptfs", "-a", "-b", "-xxxxx", "foo", "bar"},
+ },
+ testcase{
+ i: []string{"gocryptfs", "foo", "bar", "-oooo", "a,b,xxxxx"},
+ o: []string{"gocryptfs", "foo", "bar", "-oooo", "a,b,xxxxx"},
+ },
+ }
+ for _, tc := range testcases {
+ o := prefixOArgs(tc.i)
+ if !reflect.DeepEqual(o, tc.o) {
+ t.Errorf("\n i=%q\nwant=%q\n got=%q", tc.i, tc.o, o)
+ }
+ }
+}