...
1 package jwriter
2
3 import (
4 "testing"
5
6 "github.com/stretchr/testify/assert"
7 "github.com/stretchr/testify/require"
8 )
9
10 func TestObjectState(t *testing.T) {
11 w := NewWriter()
12 o := w.Object()
13
14 o.Name("prop1").Bool(true)
15 o.Maybe("prop2", true).Bool(true)
16 o.Maybe("shouldNotWriteThis", false).Bool(true)
17
18 oa := o.Name("nestedArray").Array()
19 oa.Int(1)
20 oa.End()
21
22 oo := o.Name("nestedObject").Object()
23 oo.Name("eleven").Int(11)
24 oo.End()
25
26 o.End()
27
28 require.NoError(t, w.Error())
29 expected := `{"prop1":true,"prop2":true,"nestedArray":[1],"nestedObject":{"eleven":11}}`
30 assert.JSONEq(t, expected, string(w.Bytes()))
31 }
32
View as plain text