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