gf/util/gutil/gutil_z_unit_test.go
2020-03-19 22:56:12 +08:00

67 lines
1.2 KiB
Go
Executable File

// Copyright 2019 gf Author(https://github.com/gogf/gf). All Rights Reserved.
//
// This Source Code Form is subject to the terms of the MIT License.
// If a copy of the MIT was not distributed with this file,
// You can obtain one at https://github.com/gogf/gf.
package gutil_test
import (
"testing"
"github.com/gogf/gf/test/gtest"
"github.com/gogf/gf/util/gutil"
)
func Test_Dump(t *testing.T) {
gtest.C(t, func(t *gtest.T) {
gutil.Dump(map[int]int{
100: 100,
})
})
gtest.C(t, func(t *gtest.T) {
gutil.Dump(map[string]interface{}{"": func() {}})
})
gtest.C(t, func(t *gtest.T) {
gutil.Dump([]byte("gutil Dump test"))
})
}
func Test_TryCatch(t *testing.T) {
gtest.C(t, func(t *gtest.T) {
gutil.TryCatch(func() {
panic("gutil TryCatch test")
})
})
gtest.C(t, func(t *gtest.T) {
gutil.TryCatch(func() {
panic("gutil TryCatch test")
}, func(err interface{}) {
t.Assert(err, "gutil TryCatch test")
})
})
}
func Test_IsEmpty(t *testing.T) {
gtest.C(t, func(t *gtest.T) {
t.Assert(gutil.IsEmpty(1), false)
})
}
func Test_Throw(t *testing.T) {
gtest.C(t, func(t *gtest.T) {
defer func() {
t.Assert(recover(), "gutil Throw test")
}()
gutil.Throw("gutil Throw test")
})
}