summaryrefslogtreecommitdiffstats
path: root/tpl/encoding/encoding_test.go
diff options
context:
space:
mode:
authorCameron Moore <moorereason@gmail.com>2020-03-21 10:15:12 -0500
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2020-04-07 20:01:57 +0200
commit1bc93021e3dca6405628f6fdd2dc32cff9c9836c (patch)
tree37fb17cee4a3b601c1343e89bcb578bb9061e50b /tpl/encoding/encoding_test.go
parent7eba37ae9b8653be4fc21a0dbbc6f35ca5b9280e (diff)
tpl: Extend Jsonify to support optional indent parameter
Fixes #5040
Diffstat (limited to 'tpl/encoding/encoding_test.go')
-rw-r--r--tpl/encoding/encoding_test.go15
1 files changed, 10 insertions, 5 deletions
diff --git a/tpl/encoding/encoding_test.go b/tpl/encoding/encoding_test.go
index 2c1804dad..2f0988ff3 100644
--- a/tpl/encoding/encoding_test.go
+++ b/tpl/encoding/encoding_test.go
@@ -83,17 +83,22 @@ func TestJsonify(t *testing.T) {
ns := New()
for _, test := range []struct {
+ indent []interface{}
v interface{}
expect interface{}
}{
- {[]string{"a", "b"}, template.HTML(`["a","b"]`)},
- {tstNoStringer{}, template.HTML("{}")},
- {nil, template.HTML("null")},
+ {nil, []string{"a", "b"}, template.HTML(`["a","b"]`)},
+ {[]interface{}{" "}, []string{"a", "b"}, template.HTML("[\n \"a\",\n \"b\"\n]")},
+ {nil, tstNoStringer{}, template.HTML("{}")},
+ {nil, nil, template.HTML("null")},
// errors
- {math.NaN(), false},
+ {nil, math.NaN(), false},
+ {[]interface{}{tstNoStringer{}}, []string{"a", "b"}, false},
} {
- result, err := ns.Jsonify(test.v)
+ args := append(test.indent, test.v)
+
+ result, err := ns.Jsonify(args...)
if b, ok := test.expect.(bool); ok && !b {
c.Assert(err, qt.Not(qt.IsNil))