...
1 package misc_tests
2
3 import (
4 "bytes"
5 "testing"
6
7 "github.com/json-iterator/go"
8 "github.com/stretchr/testify/require"
9 )
10
11 func Test_true(t *testing.T) {
12 should := require.New(t)
13 iter := jsoniter.ParseString(jsoniter.ConfigDefault, `true`)
14 should.True(iter.ReadBool())
15 iter = jsoniter.ParseString(jsoniter.ConfigDefault, `true`)
16 should.Equal(true, iter.Read())
17 }
18
19 func Test_false(t *testing.T) {
20 should := require.New(t)
21 iter := jsoniter.ParseString(jsoniter.ConfigDefault, `false`)
22 should.False(iter.ReadBool())
23 }
24
25 func Test_write_true_false(t *testing.T) {
26 should := require.New(t)
27 buf := &bytes.Buffer{}
28 stream := jsoniter.NewStream(jsoniter.ConfigDefault, buf, 4096)
29 stream.WriteTrue()
30 stream.WriteFalse()
31 stream.WriteBool(false)
32 stream.Flush()
33 should.Nil(stream.Error)
34 should.Equal("truefalsefalse", buf.String())
35 }
36
37 func Test_write_val_bool(t *testing.T) {
38 should := require.New(t)
39 buf := &bytes.Buffer{}
40 stream := jsoniter.NewStream(jsoniter.ConfigDefault, buf, 4096)
41 stream.WriteVal(true)
42 should.Equal(stream.Buffered(), 4)
43 stream.Flush()
44 should.Equal(stream.Buffered(), 0)
45 should.Nil(stream.Error)
46 should.Equal("true", buf.String())
47 }
48
View as plain text