github.com/wangyougui/gf/v2@v2.6.5/util/gutil/gutil_z_unit_is_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 gutil_test 8 9 import ( 10 "testing" 11 12 "github.com/wangyougui/gf/v2/test/gtest" 13 "github.com/wangyougui/gf/v2/util/gutil" 14 ) 15 16 func Test_IsEmpty(t *testing.T) { 17 gtest.C(t, func(t *gtest.T) { 18 t.Assert(gutil.IsEmpty(1), false) 19 }) 20 } 21 22 func Test_IsTypeOf(t *testing.T) { 23 gtest.C(t, func(t *gtest.T) { 24 t.Assert(gutil.IsTypeOf(1, 0), true) 25 t.Assert(gutil.IsTypeOf(1.1, 0.1), true) 26 t.Assert(gutil.IsTypeOf(1.1, 1), false) 27 t.Assert(gutil.IsTypeOf(true, false), true) 28 t.Assert(gutil.IsTypeOf(true, 1), false) 29 }) 30 gtest.C(t, func(t *gtest.T) { 31 type A struct { 32 Name string 33 } 34 type B struct { 35 Name string 36 } 37 t.Assert(gutil.IsTypeOf(1, A{}), false) 38 t.Assert(gutil.IsTypeOf(A{}, B{}), false) 39 t.Assert(gutil.IsTypeOf(A{Name: "john"}, &A{Name: "john"}), false) 40 t.Assert(gutil.IsTypeOf(A{Name: "john"}, A{Name: "john"}), true) 41 t.Assert(gutil.IsTypeOf(A{Name: "john"}, A{}), true) 42 t.Assert(gutil.IsTypeOf(&A{Name: "john"}, &A{}), true) 43 t.Assert(gutil.IsTypeOf(&A{Name: "john"}, &B{}), false) 44 t.Assert(gutil.IsTypeOf(A{Name: "john"}, B{Name: "john"}), false) 45 }) 46 }