github.com/zhongdalu/gf@v1.0.0/g/util/gconv/gconv_z_unit_bool_test.go (about) 1 // Copyright 2018 gf Author(https://github.com/zhongdalu/gf). All Rights Reserved. 2 // 3 // This Source Code Form is subject to the terms of the MIT License. 4 // If a copy of the MIT was not distributed with this file, 5 // You can obtain one at https://github.com/zhongdalu/gf. 6 7 package gconv_test 8 9 import ( 10 "github.com/zhongdalu/gf/g/test/gtest" 11 "github.com/zhongdalu/gf/g/util/gconv" 12 "testing" 13 ) 14 15 type boolStruct struct { 16 } 17 18 func Test_Bool(t *testing.T) { 19 gtest.Case(t, func() { 20 var i interface{} = nil 21 gtest.AssertEQ(gconv.Bool(i), false) 22 gtest.AssertEQ(gconv.Bool(false), false) 23 gtest.AssertEQ(gconv.Bool(nil), false) 24 gtest.AssertEQ(gconv.Bool(0), false) 25 gtest.AssertEQ(gconv.Bool("0"), false) 26 gtest.AssertEQ(gconv.Bool(""), false) 27 gtest.AssertEQ(gconv.Bool("false"), false) 28 gtest.AssertEQ(gconv.Bool("off"), false) 29 gtest.AssertEQ(gconv.Bool([]byte{}), false) 30 gtest.AssertEQ(gconv.Bool([]string{}), false) 31 gtest.AssertEQ(gconv.Bool([]interface{}{}), false) 32 gtest.AssertEQ(gconv.Bool([]map[int]int{}), false) 33 34 gtest.AssertEQ(gconv.Bool("1"), true) 35 gtest.AssertEQ(gconv.Bool("on"), true) 36 gtest.AssertEQ(gconv.Bool(1), true) 37 gtest.AssertEQ(gconv.Bool(123.456), true) 38 gtest.AssertEQ(gconv.Bool(boolStruct{}), true) 39 gtest.AssertEQ(gconv.Bool(&boolStruct{}), true) 40 }) 41 }