assert

package module
v0.1.29 Latest Latest
Warning

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

Go to latest
Published: May 31, 2019 License: MIT Imports: 11 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

This section is empty.

Functions

func AssertFn added in v0.1.20

func AssertFn(fn interface{})

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{}) (err error)

func ObjOf added in v0.1.15

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

func P

func P(d ...interface{})

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 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 {
	Tag    string                 `json:"tag,omitempty"`
	M      map[string]interface{} `json:"m,omitempty"`
	Err    error                  `json:"err,omitempty"`
	Msg    string                 `json:"msg,omitempty"`
	Caller string                 `json:"caller,omitempty"`
	Sub    *KErr                  `json:"sub,omitempty"`
}

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) Panic added in v0.1.3

func (t *KErr) Panic()

func (*KErr) StackTrace added in v0.1.11

func (t *KErr) StackTrace() 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