mirror of
https://github.com/json-iterator/go.git
synced 2025-01-29 19:14:05 +02:00
fix bool test
This commit is contained in:
parent
a743df1b8a
commit
919a2eff5c
@ -25,9 +25,7 @@ func (any *objectLazyAny) LastError() error {
|
||||
}
|
||||
|
||||
func (any *objectLazyAny) ToBool() bool {
|
||||
iter := any.cfg.BorrowIterator(any.buf)
|
||||
defer any.cfg.ReturnIterator(iter)
|
||||
return iter.ReadObject() != ""
|
||||
return true
|
||||
}
|
||||
|
||||
func (any *objectLazyAny) ToInt() int {
|
||||
|
@ -35,7 +35,7 @@ func (any *stringAny) LastError() error {
|
||||
|
||||
func (any *stringAny) ToBool() bool {
|
||||
str := any.ToString()
|
||||
if str == "false" {
|
||||
if str == "0" {
|
||||
return false
|
||||
}
|
||||
for _, c := range str {
|
||||
|
@ -1,8 +1,9 @@
|
||||
package jsoniter
|
||||
|
||||
import (
|
||||
"github.com/json-iterator/go/require"
|
||||
"testing"
|
||||
|
||||
"github.com/json-iterator/go/require"
|
||||
)
|
||||
|
||||
func Test_read_string_as_any(t *testing.T) {
|
||||
@ -13,7 +14,7 @@ func Test_read_string_as_any(t *testing.T) {
|
||||
any = Get([]byte(`" "`))
|
||||
should.False(any.ToBool())
|
||||
any = Get([]byte(`"false"`))
|
||||
should.False(any.ToBool())
|
||||
should.True(any.ToBool())
|
||||
any = Get([]byte(`"123"`))
|
||||
should.Equal(123, any.ToInt())
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user