1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
|
// Copyright 2014 by caixw, All rights reserved.
// Use of this source code is governed by a MIT
// license that can be found in the LICENSE file.
package assert
import "testing"
// Assertion 是对 testing.TB 进行了简单的封装。
// 可以以对象的方式调用包中的各个断言函数。
type Assertion struct {
t testing.TB
}
// New 返回 Assertion 对象。
func New(t testing.TB) *Assertion {
return &Assertion{t: t}
}
// TB 返回 testing.TB 接口
func (a *Assertion) TB() testing.TB {
return a.t
}
// True 参照 assert.True() 函数
func (a *Assertion) True(expr bool, msg ...interface{}) *Assertion {
True(a.t, expr, msg...)
return a
}
// False 参照 assert.False() 函数
func (a *Assertion) False(expr bool, msg ...interface{}) *Assertion {
False(a.t, expr, msg...)
return a
}
// Nil 参照 assert.Nil() 函数
func (a *Assertion) Nil(expr interface{}, msg ...interface{}) *Assertion {
Nil(a.t, expr, msg...)
return a
}
// NotNil 参照 assert.NotNil() 函数
func (a *Assertion) NotNil(expr interface{}, msg ...interface{}) *Assertion {
NotNil(a.t, expr, msg...)
return a
}
// Equal 参照 assert.Equal() 函数
func (a *Assertion) Equal(v1, v2 interface{}, msg ...interface{}) *Assertion {
Equal(a.t, v1, v2, msg...)
return a
}
// NotEqual 参照 assert.NotEqual() 函数
func (a *Assertion) NotEqual(v1, v2 interface{}, msg ...interface{}) *Assertion {
NotEqual(a.t, v1, v2, msg...)
return a
}
// Empty 参照 assert.Empty() 函数
func (a *Assertion) Empty(expr interface{}, msg ...interface{}) *Assertion {
Empty(a.t, expr, msg...)
return a
}
// NotEmpty 参照 assert.NotEmpty() 函数
func (a *Assertion) NotEmpty(expr interface{}, msg ...interface{}) *Assertion {
NotEmpty(a.t, expr, msg...)
return a
}
// Error 参照 assert.Error() 函数
func (a *Assertion) Error(expr interface{}, msg ...interface{}) *Assertion {
Error(a.t, expr, msg...)
return a
}
// ErrorString 参照 assert.ErrorString() 函数
func (a *Assertion) ErrorString(expr interface{}, str string, msg ...interface{}) *Assertion {
ErrorString(a.t, expr, str, msg...)
return a
}
// ErrorType 参照 assert.ErrorType() 函数
func (a *Assertion) ErrorType(expr interface{}, typ error, msg ...interface{}) *Assertion {
ErrorType(a.t, expr, typ, msg...)
return a
}
// NotError 参照 assert.NotError() 函数
func (a *Assertion) NotError(expr interface{}, msg ...interface{}) *Assertion {
NotError(a.t, expr, msg...)
return a
}
// FileExists 参照 assert.FileExists() 函数
func (a *Assertion) FileExists(path string, msg ...interface{}) *Assertion {
FileExists(a.t, path, msg...)
return a
}
// FileNotExists 参照 assert.FileNotExists() 函数
func (a *Assertion) FileNotExists(path string, msg ...interface{}) *Assertion {
FileNotExists(a.t, path, msg...)
return a
}
// Panic 参照 assert.Panic() 函数
func (a *Assertion) Panic(fn func(), msg ...interface{}) *Assertion {
Panic(a.t, fn, msg...)
return a
}
// PanicString 参照 assert.PanicString() 函数
func (a *Assertion) PanicString(fn func(), str string, msg ...interface{}) *Assertion {
PanicString(a.t, fn, str, msg...)
return a
}
// PanicType 参照 assert.PanicType() 函数
func (a *Assertion) PanicType(fn func(), typ interface{}, msg ...interface{}) *Assertion {
PanicType(a.t, fn, typ, msg...)
return a
}
// NotPanic 参照 assert.NotPanic() 函数
func (a *Assertion) NotPanic(fn func(), msg ...interface{}) *Assertion {
NotPanic(a.t, fn, msg...)
return a
}
// Contains 参照 assert.Contains() 函数
func (a *Assertion) Contains(container, item interface{}, msg ...interface{}) *Assertion {
Contains(a.t, container, item, msg...)
return a
}
// NotContains 参照 assert.NotContains() 函数
func (a *Assertion) NotContains(container, item interface{}, msg ...interface{}) *Assertion {
NotContains(a.t, container, item, msg...)
return a
}
|