github.com/wangyougui/gf/v2@v2.6.5/util/gconv/gconv_z_unit_bool_test.go (about)

     1  // Copyright GoFrame Author(https://goframe.org). 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/wangyougui/gf.
     6  
     7  package gconv_test
     8  
     9  import (
    10  	"testing"
    11  
    12  	"github.com/wangyougui/gf/v2/test/gtest"
    13  	"github.com/wangyougui/gf/v2/util/gconv"
    14  )
    15  
    16  type boolStruct struct{}
    17  
    18  func Test_Bool(t *testing.T) {
    19  	gtest.C(t, func(t *gtest.T) {
    20  		var any interface{} = nil
    21  		t.AssertEQ(gconv.Bool(any), false)
    22  		t.AssertEQ(gconv.Bool(false), false)
    23  		t.AssertEQ(gconv.Bool(nil), false)
    24  		t.AssertEQ(gconv.Bool(0), false)
    25  		t.AssertEQ(gconv.Bool("0"), false)
    26  		t.AssertEQ(gconv.Bool(""), false)
    27  		t.AssertEQ(gconv.Bool("false"), false)
    28  		t.AssertEQ(gconv.Bool("off"), false)
    29  		t.AssertEQ(gconv.Bool([]byte{}), false)
    30  		t.AssertEQ(gconv.Bool([]string{}), false)
    31  		t.AssertEQ(gconv.Bool([]interface{}{}), false)
    32  		t.AssertEQ(gconv.Bool([]map[int]int{}), false)
    33  
    34  		t.AssertEQ(gconv.Bool("1"), true)
    35  		t.AssertEQ(gconv.Bool("on"), true)
    36  		t.AssertEQ(gconv.Bool(1), true)
    37  		t.AssertEQ(gconv.Bool(123.456), true)
    38  		t.AssertEQ(gconv.Bool(boolStruct{}), true)
    39  		t.AssertEQ(gconv.Bool(&boolStruct{}), true)
    40  	})
    41  }