mirror of
https://gitee.com/johng/gf.git
synced 2024-12-05 05:37:55 +08:00
43 lines
1.2 KiB
Go
43 lines
1.2 KiB
Go
// Copyright GoFrame Author(https://goframe.org). All Rights Reserved.
|
|
//
|
|
// This Source Code Form is subject to the terms of the MIT License.
|
|
// If a copy of the MIT was not distributed with this file,
|
|
// You can obtain one at https://github.com/gogf/gf.
|
|
|
|
package gconv_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/gogf/gf/v2/test/gtest"
|
|
"github.com/gogf/gf/v2/util/gconv"
|
|
)
|
|
|
|
type boolStruct struct {
|
|
}
|
|
|
|
func Test_Bool(t *testing.T) {
|
|
gtest.C(t, func(t *gtest.T) {
|
|
var any interface{} = nil
|
|
t.AssertEQ(gconv.Bool(any), false)
|
|
t.AssertEQ(gconv.Bool(false), false)
|
|
t.AssertEQ(gconv.Bool(nil), false)
|
|
t.AssertEQ(gconv.Bool(0), false)
|
|
t.AssertEQ(gconv.Bool("0"), false)
|
|
t.AssertEQ(gconv.Bool(""), false)
|
|
t.AssertEQ(gconv.Bool("false"), false)
|
|
t.AssertEQ(gconv.Bool("off"), false)
|
|
t.AssertEQ(gconv.Bool([]byte{}), false)
|
|
t.AssertEQ(gconv.Bool([]string{}), false)
|
|
t.AssertEQ(gconv.Bool([]interface{}{}), false)
|
|
t.AssertEQ(gconv.Bool([]map[int]int{}), false)
|
|
|
|
t.AssertEQ(gconv.Bool("1"), true)
|
|
t.AssertEQ(gconv.Bool("on"), true)
|
|
t.AssertEQ(gconv.Bool(1), true)
|
|
t.AssertEQ(gconv.Bool(123.456), true)
|
|
t.AssertEQ(gconv.Bool(boolStruct{}), true)
|
|
t.AssertEQ(gconv.Bool(&boolStruct{}), true)
|
|
})
|
|
}
|