1
0
mirror of https://github.com/json-iterator/go.git synced 2025-06-18 22:57:33 +02:00

string any

This commit is contained in:
Tao Wen
2017-01-23 08:33:43 +08:00
parent d49ea1bc49
commit b9fe012eea
7 changed files with 206 additions and 18 deletions

View File

@ -59,12 +59,26 @@ func Test_read_exotic_string(t *testing.T) {
}
}
func Test_read_string_via_read(t *testing.T) {
func Test_read_string_as_interface(t *testing.T) {
should := require.New(t)
iter := ParseString(`"hello"`)
should.Equal("hello", iter.Read())
}
func Test_read_string_as_any(t *testing.T) {
should := require.New(t)
any, err := UnmarshalAnyFromString(`"hello"`)
should.Nil(err)
should.Equal("hello", any.ToString())
should.True(any.ToBool())
any, err = UnmarshalAnyFromString(`" "`)
should.False(any.ToBool())
any, err = UnmarshalAnyFromString(`"false"`)
should.False(any.ToBool())
any, err = UnmarshalAnyFromString(`"123"`)
should.Equal(123, any.ToInt())
}
func Test_write_string(t *testing.T) {
should := require.New(t)
str, err := MarshalToString("hello")