jsoniter_any_string_test.go 627 B

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