github.com/zhongdalu/gf@v1.0.0/g/internal/empty/empty_test.go (about)

     1  // Copyright 2019 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 empty_test
     8  
     9  import (
    10  	"github.com/zhongdalu/gf/g"
    11  	"github.com/zhongdalu/gf/g/internal/empty"
    12  	"github.com/zhongdalu/gf/g/test/gtest"
    13  	"github.com/zhongdalu/gf/g/util/gconv"
    14  	"testing"
    15  )
    16  
    17  type TestPerson interface {
    18  	Say() string
    19  }
    20  type TestWoman struct {
    21  }
    22  
    23  func (woman TestWoman) Say() string {
    24  	return "nice"
    25  }
    26  
    27  func TestIsEmpty(t *testing.T) {
    28  	gtest.Case(t, func() {
    29  		tmpT1 := "0"
    30  		tmpT2 := func() {}
    31  		tmpT2 = nil
    32  		tmpT3 := make(chan int, 0)
    33  		var tmpT4 TestPerson = nil
    34  		var tmpT5 *TestPerson = nil
    35  		tmpF1 := "1"
    36  		tmpF2 := func(a string) string { return "1" }
    37  		tmpF3 := make(chan int, 1)
    38  		tmpF3 <- 1
    39  		var tmpF4 TestPerson = TestWoman{}
    40  		tmpF5 := &tmpF4
    41  		// true
    42  		gtest.Assert(empty.IsEmpty(nil), true)
    43  		gtest.Assert(empty.IsEmpty(gconv.Int(tmpT1)), true)
    44  		gtest.Assert(empty.IsEmpty(gconv.Int8(tmpT1)), true)
    45  		gtest.Assert(empty.IsEmpty(gconv.Int16(tmpT1)), true)
    46  		gtest.Assert(empty.IsEmpty(gconv.Int32(tmpT1)), true)
    47  		gtest.Assert(empty.IsEmpty(gconv.Int64(tmpT1)), true)
    48  		gtest.Assert(empty.IsEmpty(gconv.Uint64(tmpT1)), true)
    49  		gtest.Assert(empty.IsEmpty(gconv.Uint(tmpT1)), true)
    50  		gtest.Assert(empty.IsEmpty(gconv.Uint16(tmpT1)), true)
    51  		gtest.Assert(empty.IsEmpty(gconv.Uint32(tmpT1)), true)
    52  		gtest.Assert(empty.IsEmpty(gconv.Uint64(tmpT1)), true)
    53  		gtest.Assert(empty.IsEmpty(gconv.Float32(tmpT1)), true)
    54  		gtest.Assert(empty.IsEmpty(gconv.Float64(tmpT1)), true)
    55  		gtest.Assert(empty.IsEmpty(false), true)
    56  		gtest.Assert(empty.IsEmpty([]byte("")), true)
    57  		gtest.Assert(empty.IsEmpty(""), true)
    58  		gtest.Assert(empty.IsEmpty(g.Map{}), true)
    59  		gtest.Assert(empty.IsEmpty(g.Slice{}), true)
    60  		gtest.Assert(empty.IsEmpty(g.Array{}), true)
    61  		gtest.Assert(empty.IsEmpty(tmpT2), true)
    62  		gtest.Assert(empty.IsEmpty(tmpT3), true)
    63  		gtest.Assert(empty.IsEmpty(tmpT3), true)
    64  		gtest.Assert(empty.IsEmpty(tmpT4), true)
    65  		gtest.Assert(empty.IsEmpty(tmpT5), true)
    66  		// false
    67  		gtest.Assert(empty.IsEmpty(gconv.Int(tmpF1)), false)
    68  		gtest.Assert(empty.IsEmpty(gconv.Int8(tmpF1)), false)
    69  		gtest.Assert(empty.IsEmpty(gconv.Int16(tmpF1)), false)
    70  		gtest.Assert(empty.IsEmpty(gconv.Int32(tmpF1)), false)
    71  		gtest.Assert(empty.IsEmpty(gconv.Int64(tmpF1)), false)
    72  		gtest.Assert(empty.IsEmpty(gconv.Uint(tmpF1)), false)
    73  		gtest.Assert(empty.IsEmpty(gconv.Uint8(tmpF1)), false)
    74  		gtest.Assert(empty.IsEmpty(gconv.Uint16(tmpF1)), false)
    75  		gtest.Assert(empty.IsEmpty(gconv.Uint32(tmpF1)), false)
    76  		gtest.Assert(empty.IsEmpty(gconv.Uint64(tmpF1)), false)
    77  		gtest.Assert(empty.IsEmpty(gconv.Float32(tmpF1)), false)
    78  		gtest.Assert(empty.IsEmpty(gconv.Float64(tmpF1)), false)
    79  		gtest.Assert(empty.IsEmpty(true), false)
    80  		gtest.Assert(empty.IsEmpty(tmpT1), false)
    81  		gtest.Assert(empty.IsEmpty([]byte("1")), false)
    82  		gtest.Assert(empty.IsEmpty(g.Map{"a": 1}), false)
    83  		gtest.Assert(empty.IsEmpty(g.Slice{"1"}), false)
    84  		gtest.Assert(empty.IsEmpty(g.Array{"1"}), false)
    85  		gtest.Assert(empty.IsEmpty(tmpF2), false)
    86  		gtest.Assert(empty.IsEmpty(tmpF3), false)
    87  		gtest.Assert(empty.IsEmpty(tmpF4), false)
    88  		gtest.Assert(empty.IsEmpty(tmpF5), false)
    89  	})
    90  }