1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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"))
}
|