1
0
mirror of https://github.com/json-iterator/go.git synced 2025-03-23 21:09:11 +02:00
json-iterator/jsoniter_any_string_test.go

26 lines
547 B
Go
Raw Normal View History

2017-06-17 21:32:48 +08:00
package jsoniter
import (
"github.com/json-iterator/go/require"
2017-06-19 23:43:53 +08:00
"testing"
2017-06-17 21:32:48 +08:00
)
func Test_read_string_as_any(t *testing.T) {
should := require.New(t)
any := Get([]byte(`"hello"`))
2017-06-17 21:32:48 +08:00
should.Equal("hello", any.ToString())
should.True(any.ToBool())
any = Get([]byte(`" "`))
2017-06-17 21:32:48 +08:00
should.False(any.ToBool())
any = Get([]byte(`"false"`))
2017-06-17 21:32:48 +08:00
should.False(any.ToBool())
any = Get([]byte(`"123"`))
2017-06-17 21:32:48 +08:00
should.Equal(123, any.ToInt())
}
func Test_wrap_string(t *testing.T) {
should := require.New(t)
any := WrapString("123")
should.Equal(123, any.ToInt())
2017-06-19 23:43:53 +08:00
}