assert

package module
v0.2.14 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 20, 2019 License: MIT Imports: 13 Imported by: 14

README

assert

assert for go


func a1() error {
	return KTry(func() {
		SWrap(errors.New("sbhbhbh"), func(m *M) {
			m.Msg("test shhh")
			m.M["ss"] = 1
			m.M["input"] = 1
		})

		TT(true, func(m *M) {
			m.Msg("好东西%d", 1)
		})
	})
}

func TestName(t *testing.T) {
	P(IfEquals(1, 2, 34))
	P(IfEquals(nil, nil))
	P(IfEquals(0, ""))
	P(IfEquals("", ""))

	fmt.Println(IsNil(a1()))

	P(KTry(func() {
		Throw(KTry(func() {
			SWrap(KTry(func() {
				SWrap(a1(), func(m *M) {
					m.Msg("ok111")
					m.Tag("test tag")
				})
			}), func(m *M) {
				m.Msg("test 123")
			})
		}))
	}))
}

func TestType(t *testing.T) {
	var ss map[string]interface{}
	var s interface{}
	for _, i := range ObjOf("1", 0, errors.New(""), nil, []string{}, ss, s) {
		fmt.Println(IsNil(i))
	}
}

func TestTry(t *testing.T) {
	P(Try(func() {
		T(true, "sss")
	}))

	P(KTry(func() {
		T(true, "sss")
	}))
}

func TestIf(t *testing.T) {
	fmt.Println(If(true, 1, "ss").(int))
	fmt.Println(If(true, FnOf(ToInt, "2"), "ss").(int))
	fmt.Println(If(true, FnOf(ToInt, "2"), "ss").(int))
	fmt.Println(reflect.TypeOf(FnOf(ToInt, "2")).Name())
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Cfg = struct {
	Debug bool
}{
	Debug: false,
}
View Source
var ErrTag = struct {
	UnknownErr string
}{
	UnknownErr: "unknown_error",
}

Functions

func AssertFn added in v0.1.20

func AssertFn(fn interface{})

func Debug added in v0.2.12

func Debug()

func ErrHandle added in v0.2.8

func ErrHandle(err interface{}, fn func(err *KErr))

func ErrWrap added in v0.1.4

func ErrWrap(err interface{}, msg string, args ...interface{})

func FnCost added in v0.1.17

func FnCost(f func()) time.Duration

func If added in v0.0.4

func If(b bool, t, f interface{}) interface{}

func IfEquals added in v0.0.4

func IfEquals(args ...interface{}) bool

func IfIn added in v0.0.4

func IfIn(a interface{}, args ...interface{}) bool

func IfNotIn added in v0.0.4

func IfNotIn(a interface{}, args ...interface{}) bool

func IsAllNil added in v0.1.15

func IsAllNil(args ...interface{}) bool

func IsAllNotNil added in v0.1.15

func IsAllNotNil(args ...interface{}) bool

func IsErr added in v0.1.20

func IsErr(p interface{}) bool

func IsNil added in v0.1.15

func IsNil(p interface{}) (b bool)

func IsPtr added in v0.1.20

func IsPtr(p interface{}) bool

func KTry added in v0.1.15

func KTry(fn interface{}, args ...interface{}) error

func ObjOf added in v0.1.15

func ObjOf(args ...interface{}) []interface{}

func P

func P(d ...interface{})

func Panic added in v0.2.10

func Panic(fn func(m *M))

func Resp added in v0.2.14

func Resp(fn func(err *KErr))

func SWrap added in v0.1.13

func SWrap(err interface{}, fn func(m *M))

func StrOf added in v0.1.15

func StrOf(args ...string) []string

func T added in v0.1.13

func T(b bool, msg string, args ...interface{})

func TT added in v0.1.21

func TT(b bool, fn func(m *M))

func Throw added in v0.1.12

func Throw(err interface{})

func ToInt added in v0.1.15

func ToInt(p string) int

func ToTime added in v0.2.14

func ToTime(t string) time.Time

func Try added in v0.1.15

func Try(fn interface{}, args ...interface{}) (r interface{})

func Wrap added in v0.1.29

func Wrap(err error, msg string, args ...interface{}) error

Types

type FnT added in v0.1.15

type FnT func() []reflect.Value

func FnOf added in v0.1.15

func FnOf(fn interface{}, args ...interface{}) FnT

type KErr added in v0.0.13

type KErr struct {
	// contains filtered or unexported fields
}

func (*KErr) Caller added in v0.1.12

func (t *KErr) Caller(caller string)

func (*KErr) Err added in v0.1.6

func (t *KErr) Err() error

func (*KErr) Error added in v0.0.13

func (t *KErr) Error() string

func (*KErr) P added in v0.1.4

func (t *KErr) P()

func (*KErr) StackTrace added in v0.1.11

func (t *KErr) StackTrace() interface{}

func (*KErr) Tag added in v0.1.12

func (t *KErr) Tag() string

type M added in v0.1.12

type M struct {
	M map[string]interface{}
	// contains filtered or unexported fields
}

func (*M) Msg added in v0.1.12

func (t *M) Msg(format string, args ...interface{})

func (*M) Tag added in v0.1.12

func (t *M) Tag(tag string)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL