From 3e4a06945f0af95f1ae99fe1a8478699be5ccc6d Mon Sep 17 00:00:00 2001
From: Christian Couder <chriscool@tuxfamily.org>
Date: Sat, 2 May 2015 22:47:03 +0200
Subject: [PATCH] parse_test: fix and test sameWords()

License: MIT
Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
 commands/cli/parse_test.go | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)

diff --git a/commands/cli/parse_test.go b/commands/cli/parse_test.go
index a1fbe13a3..286a39170 100644
--- a/commands/cli/parse_test.go
+++ b/commands/cli/parse_test.go
@@ -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{
-- 
GitLab