1
0
mirror of https://github.com/json-iterator/go.git synced 2024-11-24 08:22:14 +02:00
json-iterator/jsoniter_any_bool_test.go
2017-07-03 19:10:49 +08:00

45 lines
724 B
Go

package jsoniter
import (
"fmt"
"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) {
should := require.New(t)
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))
}
}
}