提交 3e4a0694 作者: Christian Couder

parse_test: fix and test sameWords()

License: MIT
Signed-off-by: 's avatarChristian Couder <chriscool@tuxfamily.org>
上级 2a5b2f2f
...@@ -11,6 +11,9 @@ type kvs map[string]interface{} ...@@ -11,6 +11,9 @@ type kvs map[string]interface{}
type words []string type words []string
func sameWords(a words, b words) bool { func sameWords(a words, b words) bool {
if len(a) != len(b) {
return false
}
for i, w := range a { for i, w := range a {
if w != b[i] { if w != b[i] {
return false return false
...@@ -31,6 +34,33 @@ func sameKVs(a kvs, b kvs) bool { ...@@ -31,6 +34,33 @@ func sameKVs(a kvs, b kvs) bool {
return true 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) { func TestOptionParsing(t *testing.T) {
subCmd := &commands.Command{} subCmd := &commands.Command{}
cmd := &commands.Command{ cmd := &commands.Command{
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论