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

add bool convert test map

This commit is contained in:
Xargin 2017-07-03 19:10:49 +08:00
parent 8700644196
commit a743df1b8a

View File

@ -1,12 +1,44 @@
package jsoniter package jsoniter
import ( import (
"github.com/json-iterator/go/require" "fmt"
"testing" "testing"
"github.com/json-iterator/go/require"
) )
var boolConvertMap = map[string]bool{
"true": true,
"false": false,
`"true"`: true,
`"false"`: true,
"123": true,
"0": false,
`"0"`: false,
"-1": true,
"1.1": true,
"0.0": false,
"-1.1": true,
`""`: false,
"[1,2]": true,
"[]": false,
"{}": true,
`{"abc":1}`: true,
}
func Test_read_bool_as_any(t *testing.T) { func Test_read_bool_as_any(t *testing.T) {
should := require.New(t) should := require.New(t)
any := Get([]byte("true"))
should.True(any.ToBool()) var any Any
for k, v := range boolConvertMap {
any = Get([]byte(k))
if v {
should.True(any.ToBool(), fmt.Sprintf("origin val is %v", k))
} else {
should.False(any.ToBool(), fmt.Sprintf("origin val is %v", k))
}
}
} }