mirror of
https://github.com/json-iterator/go.git
synced 2024-11-24 08:22:14 +02:00
add bool convert test map
This commit is contained in:
parent
8700644196
commit
a743df1b8a
@ -1,12 +1,44 @@
|
||||
package jsoniter
|
||||
|
||||
import (
|
||||
"github.com/json-iterator/go/require"
|
||||
"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)
|
||||
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))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user