aboutsummaryrefslogtreecommitdiffstats
path: root/client/go/internal/slime/json_format_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'client/go/internal/slime/json_format_test.go')
-rw-r--r--client/go/internal/slime/json_format_test.go34
1 files changed, 34 insertions, 0 deletions
diff --git a/client/go/internal/slime/json_format_test.go b/client/go/internal/slime/json_format_test.go
new file mode 100644
index 00000000000..f3e3ca61ccb
--- /dev/null
+++ b/client/go/internal/slime/json_format_test.go
@@ -0,0 +1,34 @@
+// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package slime
+
+import (
+ "os"
+ "testing"
+
+ "github.com/stretchr/testify/assert"
+)
+
+func TestPrintJson(t *testing.T) {
+ slime := NewSlime()
+ o := slime.SetObject()
+ o.SetBool("a", true)
+ o.SetBool("b", false)
+ o.SetLong("c", 42)
+ o.SetLong("d", 0)
+ o.SetLong("e", -123456)
+ o.SetDouble("f", 2.75)
+ o.SetString("g", "x with\nembedded \"stuff\" like \\n")
+ got := o.Field("g").AsString()
+ assert.Equal(t,
+ `x with
+embedded "stuff" like \n`, got)
+ a := o.SetArray("h")
+ assert.Equal(t, 0, a.Entries())
+ a.AddLong(17)
+ o2 := o.SetObject("j")
+ assert.Equal(t, 0, o2.Fields())
+ o2.SetLong("jj", 987654321)
+ os.Stderr.Write([]byte("test JsonEncodeTo:\n>>>\n"))
+ JsonEncodeTo(slime, os.Stderr)
+ os.Stderr.Write([]byte("\n<<<\ntest JsonEncodeTo\n"))
+}