@cryptotaxi247 / kubo / commits / 3e4a06945

parse_test: fix and test sameWords()

License: MIT Signed-off-by: Christian Couder <chriscool@tuxfamily.org>

Christian Couder committed May 2, 2015 at 22:47 UTC 3e4a06945f0af95f1ae99fe1a8478699be5ccc6d
1 file changed +30
commands/cli/parse_test.go
+30
@@ -11,6 +11,9 @@ type kvs map[string]interface{}
11 type words []string
12
13 func sameWords(a words, b words) bool {
14 + if len(a) != len(b) {
15 + return false
16 + }
17 for i, w := range a {
18 if w != b[i] {
19 return false
@@ -31,6 +34,33 @@ func sameKVs(a kvs, b kvs) bool {
34 return true
35 }
36
37 +func TestSameWords(t *testing.T) {
38 + a := []string{"v1", "v2"}
39 + b := []string{"v1", "v2", "v3"}
40 + c := []string{"v2", "v3"}
41 + d := []string{"v2"}
42 + e := []string{"v2", "v3"}
43 + f := []string{"v2", "v1"}
44 +
45 + test := func(a words, b words, v bool) {
46 + if sameWords(a, b) != v {
47 + t.Errorf("sameWords('%v', '%v') != %v", a, b, v)
48 + }
49 + }
50 +
51 + test(a, b, false)
52 + test(a, a, true)
53 + test(a, c, false)
54 + test(b, c, false)
55 + test(c, d, false)
56 + test(c, e, true)
57 + test(b, e, false)
58 + test(a, b, false)
59 + test(a, f, false)
60 + test(e, f, false)
61 + test(f, f, true)
62 +}
63 +
64 func TestOptionParsing(t *testing.T) {
65 subCmd := &commands.Command{}
66 cmd := &commands.Command{