github.com/zhongdalu/gf@v1.0.0/g/util/gutil/gutil_z_unit_test.go (about) 1 package gutil_test 2 3 import ( 4 "testing" 5 6 "github.com/zhongdalu/gf/g/test/gtest" 7 "github.com/zhongdalu/gf/g/util/gutil" 8 ) 9 10 func Test_Dump(t *testing.T) { 11 gtest.Case(t, func() { 12 gutil.Dump(map[int]int{ 13 100: 100, 14 }) 15 }) 16 17 gtest.Case(t, func() { 18 gutil.Dump(map[string]interface{}{"": func() {}}) 19 }) 20 21 gtest.Case(t, func() { 22 gutil.Dump([]byte("gutil Dump test")) 23 }) 24 } 25 26 func Test_PrintStack(t *testing.T) { 27 gtest.Case(t, func() { 28 gutil.PrintStack() 29 }) 30 } 31 32 func Test_TryCatch(t *testing.T) { 33 34 gtest.Case(t, func() { 35 gutil.TryCatch(func() { 36 panic("gutil TryCatch test") 37 }) 38 }) 39 40 gtest.Case(t, func() { 41 gutil.TryCatch(func() { 42 panic("gutil TryCatch test") 43 44 }, func(err interface{}) { 45 gtest.Assert(err, "gutil TryCatch test") 46 }) 47 }) 48 } 49 50 func Test_IsEmpty(t *testing.T) { 51 52 gtest.Case(t, func() { 53 gtest.Assert(gutil.IsEmpty(1), false) 54 }) 55 } 56 57 func Test_Throw(t *testing.T) { 58 59 gtest.Case(t, func() { 60 defer func() { 61 gtest.Assert(recover(), "gutil Throw test") 62 }() 63 64 gutil.Throw("gutil Throw test") 65 }) 66 }