From 919a2eff5c5fc6173ef0e26aa7be8a91f9dddb75 Mon Sep 17 00:00:00 2001 From: Xargin Date: Mon, 3 Jul 2017 19:40:12 +0800 Subject: [PATCH] fix bool test --- feature_any_object.go | 4 +--- feature_any_string.go | 2 +- jsoniter_any_string_test.go | 5 +++-- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/feature_any_object.go b/feature_any_object.go index 7382233..dd2bf41 100644 --- a/feature_any_object.go +++ b/feature_any_object.go @@ -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 { diff --git a/feature_any_string.go b/feature_any_string.go index e3dcd6a..e76c275 100644 --- a/feature_any_string.go +++ b/feature_any_string.go @@ -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 { diff --git a/jsoniter_any_string_test.go b/jsoniter_any_string_test.go index f17a111..1567bdc 100644 --- a/jsoniter_any_string_test.go +++ b/jsoniter_any_string_test.go @@ -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()) }