1
0
mirror of https://github.com/json-iterator/go.git synced 2024-11-30 08:36:43 +02:00
json-iterator/jsoniter_bool_test.go

50 lines
1.0 KiB
Go
Raw Normal View History

2016-12-02 05:22:20 +02:00
package jsoniter
2017-01-07 16:08:45 +02:00
import (
"testing"
"bytes"
"github.com/json-iterator/go/require"
)
2016-12-02 05:22:20 +02:00
func Test_true(t *testing.T) {
2017-01-21 10:09:38 +02:00
should := require.New(t)
2016-12-02 05:22:20 +02:00
iter := ParseString(`true`)
2017-01-21 10:09:38 +02:00
should.True(iter.ReadBool())
iter = ParseString(`true`)
should.Equal(true, iter.Read())
2016-12-02 05:22:20 +02:00
}
func Test_false(t *testing.T) {
2017-01-21 10:09:38 +02:00
should := require.New(t)
2016-12-02 05:22:20 +02:00
iter := ParseString(`false`)
2017-01-21 10:09:38 +02:00
should.False(iter.ReadBool())
2016-12-02 05:22:20 +02:00
}
2017-01-07 16:08:45 +02:00
2017-01-23 02:45:57 +02:00
func Test_read_bool_as_any(t *testing.T) {
should := require.New(t)
any, err := UnmarshalAnyFromString("true")
should.Nil(err)
should.True(any.ToBool())
}
2017-01-07 16:08:45 +02:00
func Test_write_true_false(t *testing.T) {
should := require.New(t)
buf := &bytes.Buffer{}
stream := NewStream(buf, 4096)
stream.WriteTrue()
stream.WriteFalse()
stream.Flush()
should.Nil(stream.Error)
should.Equal("truefalse", buf.String())
2017-01-09 13:19:48 +02:00
}
func Test_write_val_bool(t *testing.T) {
should := require.New(t)
buf := &bytes.Buffer{}
stream := NewStream(buf, 4096)
stream.WriteVal(true)
stream.Flush()
should.Nil(stream.Error)
should.Equal("true", buf.String())
2017-01-07 16:08:45 +02:00
}