jsoniter_any_string_test.go 547 B

12345678910111213141516171819202122232425
  1. package jsoniter
  2. import (
  3. "github.com/json-iterator/go/require"
  4. "testing"
  5. )
  6. func Test_read_string_as_any(t *testing.T) {
  7. should := require.New(t)
  8. any := Get([]byte(`"hello"`))
  9. should.Equal("hello", any.ToString())
  10. should.True(any.ToBool())
  11. any = Get([]byte(`" "`))
  12. should.False(any.ToBool())
  13. any = Get([]byte(`"false"`))
  14. should.False(any.ToBool())
  15. any = Get([]byte(`"123"`))
  16. should.Equal(123, any.ToInt())
  17. }
  18. func Test_wrap_string(t *testing.T) {
  19. should := require.New(t)
  20. any := WrapString("123")
  21. should.Equal(123, any.ToInt())
  22. }