1
0
mirror of https://github.com/json-iterator/go.git synced 2025-04-04 21:34:16 +02:00
json-iterator/jsoniter_any_bool_test.go

48 lines
781 B
Go
Raw Normal View History

2017-06-17 21:32:48 +08:00
package jsoniter
import (
2017-07-03 19:10:49 +08:00
"fmt"
2017-06-19 23:43:53 +08:00
"testing"
2017-07-03 19:10:49 +08:00
"github.com/json-iterator/go/require"
2017-06-17 21:32:48 +08:00
)
2017-07-03 19:10:49 +08:00
var boolConvertMap = map[string]bool{
2017-07-04 17:02:46 +08:00
"null": false,
2017-07-03 19:10:49 +08:00
"true": true,
"false": false,
`"true"`: true,
`"false"`: true,
2017-07-04 15:41:28 +08:00
"123": true,
`"123"`: true,
"0": false,
`"0"`: false,
"-1": true,
`"-1"`: true,
2017-07-03 19:10:49 +08:00
"1.1": true,
"0.0": false,
"-1.1": true,
`""`: false,
"[1,2]": true,
"[]": false,
"{}": true,
`{"abc":1}`: true,
}
2017-06-17 21:32:48 +08:00
func Test_read_bool_as_any(t *testing.T) {
should := require.New(t)
2017-07-03 19:10:49 +08:00
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))
}
}
2017-06-17 21:32:48 +08:00
}