jsoniter_bool_test.go 1.0 KB

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