Commit 3e4a0694 authored by Christian Couder's avatar Christian Couder

parse_test: fix and test sameWords()

License: MIT
Signed-off-by: default avatarChristian Couder <chriscool@tuxfamily.org>
parent 2a5b2f2f
......@@ -11,6 +11,9 @@ type kvs map[string]interface{}
type words []string
func sameWords(a words, b words) bool {
if len(a) != len(b) {
return false
}
for i, w := range a {
if w != b[i] {
return false
......@@ -31,6 +34,33 @@ func sameKVs(a kvs, b kvs) bool {
return true
}
func TestSameWords(t *testing.T) {
a := []string{"v1", "v2"}
b := []string{"v1", "v2", "v3"}
c := []string{"v2", "v3"}
d := []string{"v2"}
e := []string{"v2", "v3"}
f := []string{"v2", "v1"}
test := func(a words, b words, v bool) {
if sameWords(a, b) != v {
t.Errorf("sameWords('%v', '%v') != %v", a, b, v)
}
}
test(a, b, false)
test(a, a, true)
test(a, c, false)
test(b, c, false)
test(c, d, false)
test(c, e, true)
test(b, e, false)
test(a, b, false)
test(a, f, false)
test(e, f, false)
test(f, f, true)
}
func TestOptionParsing(t *testing.T) {
subCmd := &commands.Command{}
cmd := &commands.Command{
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment