diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2019-11-11 14:37:37 +0100 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2019-11-11 21:55:16 +0100 |
commit | a2670bf460e10ed5de69f90abbe7c4e2b32068cf (patch) | |
tree | 3af0c55190257a9db49b91f5068429de03972e72 /tpl/collections/collections_test.go | |
parent | 1a36ce9b0903e02a5068aed5f807ed9d21f48ece (diff) |
tpl/collections: Allow dict to create nested structures
Fixes #6497
Diffstat (limited to 'tpl/collections/collections_test.go')
-rw-r--r-- | tpl/collections/collections_test.go | 31 |
1 files changed, 19 insertions, 12 deletions
diff --git a/tpl/collections/collections_test.go b/tpl/collections/collections_test.go index 3830a7505..cfbcd312b 100644 --- a/tpl/collections/collections_test.go +++ b/tpl/collections/collections_test.go @@ -182,7 +182,6 @@ func TestDelimit(t *testing.T) { } func TestDictionary(t *testing.T) { - t.Parallel() c := qt.New(t) ns := New(&deps.Deps{}) @@ -192,22 +191,30 @@ func TestDictionary(t *testing.T) { expect interface{} }{ {[]interface{}{"a", "b"}, map[string]interface{}{"a": "b"}}, + {[]interface{}{[]string{"a", "b"}, "c"}, map[string]interface{}{"a": map[string]interface{}{"b": "c"}}}, + {[]interface{}{[]string{"a", "b"}, "c", []string{"a", "b2"}, "c2", "b", "c"}, + map[string]interface{}{"a": map[string]interface{}{"b": "c", "b2": "c2"}, "b": "c"}}, {[]interface{}{"a", 12, "b", []int{4}}, map[string]interface{}{"a": 12, "b": []int{4}}}, // errors {[]interface{}{5, "b"}, false}, {[]interface{}{"a", "b", "c"}, false}, } { - errMsg := qt.Commentf("[%d] %v", i, test.values) - - result, err := ns.Dictionary(test.values...) - - if b, ok := test.expect.(bool); ok && !b { - c.Assert(err, qt.Not(qt.IsNil), errMsg) - continue - } - - c.Assert(err, qt.IsNil, errMsg) - c.Assert(result, qt.DeepEquals, test.expect, errMsg) + i := i + test := test + c.Run(fmt.Sprint(i), func(c *qt.C) { + c.Parallel() + errMsg := qt.Commentf("[%d] %v", i, test.values) + + result, err := ns.Dictionary(test.values...) + + if b, ok := test.expect.(bool); ok && !b { + c.Assert(err, qt.Not(qt.IsNil), errMsg) + return + } + + c.Assert(err, qt.IsNil, errMsg) + c.Assert(result, qt.DeepEquals, test.expect, qt.Commentf(fmt.Sprint(result))) + }) } } |