aboutsummaryrefslogtreecommitdiffstats
path: root/client/go/internal/slime/json_format_test.go
diff options
context:
space:
mode:
authorArne Juul <arnej@yahooinc.com>2023-05-24 17:04:46 +0000
committerArne Juul <arnej@yahooinc.com>2023-05-24 18:38:35 +0000
commit801b46f85d04fbfee38b88312419393e20340571 (patch)
treed94e4daba396d0cc57fbfabb51a06821042f34c5 /client/go/internal/slime/json_format_test.go
parent1d445d46f6c4662d64ff77c81b068163d4077479 (diff)
add minimal port of Slime APIarnej/golang-slime-port-1
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"))
+}