1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
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)
}
}
}
|