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)
|
2017-06-18 22:21:54 +08:00
|
|
|
any := Get([]byte(`"hello"`))
|
2017-06-17 21:32:48 +08:00
|
|
|
should.Equal("hello", any.ToString())
|
|
|
|
should.True(any.ToBool())
|
2017-06-18 22:21:54 +08:00
|
|
|
any = Get([]byte(`" "`))
|
2017-06-17 21:32:48 +08:00
|
|
|
should.False(any.ToBool())
|
2017-06-18 22:21:54 +08:00
|
|
|
any = Get([]byte(`"false"`))
|
2017-06-17 21:32:48 +08:00
|
|
|
should.False(any.ToBool())
|
2017-06-18 22:21:54 +08:00
|
|
|
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
|
|
|
}
|