Skip to content

Commit dc8af72

Browse files
rinchsanboyan-soubachov
authored andcommitted
add generated code for positive/negative assertion
1 parent 1544508 commit dc8af72

File tree

4 files changed

+166
-0
lines changed

4 files changed

+166
-0
lines changed

assert/assertion_format.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,17 @@ func LessOrEqualf(t TestingT, e1 interface{}, e2 interface{}, msg string, args .
441441
return LessOrEqual(t, e1, e2, append([]interface{}{msg}, args...)...)
442442
}
443443

444+
// Negativef asserts that the specified element is negative
445+
//
446+
// assert.Negativef(t, -1, "error message %s", "formatted")
447+
// assert.Negativef(t, -1.23, "error message %s", "formatted")
448+
func Negativef(t TestingT, e interface{}, msg string, args ...interface{}) bool {
449+
if h, ok := t.(tHelper); ok {
450+
h.Helper()
451+
}
452+
return Negative(t, e, append([]interface{}{msg}, args...)...)
453+
}
454+
444455
// Neverf asserts that the given condition doesn't satisfy in waitFor time,
445456
// periodically checking the target function each tick.
446457
//
@@ -647,6 +658,17 @@ func PanicsWithValuef(t TestingT, expected interface{}, f PanicTestFunc, msg str
647658
return PanicsWithValue(t, expected, f, append([]interface{}{msg}, args...)...)
648659
}
649660

661+
// Positivef asserts that the specified element is positive
662+
//
663+
// assert.Positivef(t, 1, "error message %s", "formatted")
664+
// assert.Positivef(t, 1.23, "error message %s", "formatted")
665+
func Positivef(t TestingT, e interface{}, msg string, args ...interface{}) bool {
666+
if h, ok := t.(tHelper); ok {
667+
h.Helper()
668+
}
669+
return Positive(t, e, append([]interface{}{msg}, args...)...)
670+
}
671+
650672
// Regexpf asserts that a specified regexp matches a string.
651673
//
652674
// assert.Regexpf(t, regexp.MustCompile("start"), "it's starting", "error message %s", "formatted")

assert/assertion_forward.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -871,6 +871,28 @@ func (a *Assertions) Lessf(e1 interface{}, e2 interface{}, msg string, args ...i
871871
return Lessf(a.t, e1, e2, msg, args...)
872872
}
873873

874+
// Negative asserts that the specified element is negative
875+
//
876+
// a.Negative(-1)
877+
// a.Negative(-1.23)
878+
func (a *Assertions) Negative(e interface{}, msgAndArgs ...interface{}) bool {
879+
if h, ok := a.t.(tHelper); ok {
880+
h.Helper()
881+
}
882+
return Negative(a.t, e, msgAndArgs...)
883+
}
884+
885+
// Negativef asserts that the specified element is negative
886+
//
887+
// a.Negativef(-1, "error message %s", "formatted")
888+
// a.Negativef(-1.23, "error message %s", "formatted")
889+
func (a *Assertions) Negativef(e interface{}, msg string, args ...interface{}) bool {
890+
if h, ok := a.t.(tHelper); ok {
891+
h.Helper()
892+
}
893+
return Negativef(a.t, e, msg, args...)
894+
}
895+
874896
// Never asserts that the given condition doesn't satisfy in waitFor time,
875897
// periodically checking the target function each tick.
876898
//
@@ -1283,6 +1305,28 @@ func (a *Assertions) Panicsf(f PanicTestFunc, msg string, args ...interface{}) b
12831305
return Panicsf(a.t, f, msg, args...)
12841306
}
12851307

1308+
// Positive asserts that the specified element is positive
1309+
//
1310+
// a.Positive(1)
1311+
// a.Positive(1.23)
1312+
func (a *Assertions) Positive(e interface{}, msgAndArgs ...interface{}) bool {
1313+
if h, ok := a.t.(tHelper); ok {
1314+
h.Helper()
1315+
}
1316+
return Positive(a.t, e, msgAndArgs...)
1317+
}
1318+
1319+
// Positivef asserts that the specified element is positive
1320+
//
1321+
// a.Positivef(1, "error message %s", "formatted")
1322+
// a.Positivef(1.23, "error message %s", "formatted")
1323+
func (a *Assertions) Positivef(e interface{}, msg string, args ...interface{}) bool {
1324+
if h, ok := a.t.(tHelper); ok {
1325+
h.Helper()
1326+
}
1327+
return Positivef(a.t, e, msg, args...)
1328+
}
1329+
12861330
// Regexp asserts that a specified regexp matches a string.
12871331
//
12881332
// a.Regexp(regexp.MustCompile("start"), "it's starting")

require/require.go

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1112,6 +1112,34 @@ func Lessf(t TestingT, e1 interface{}, e2 interface{}, msg string, args ...inter
11121112
t.FailNow()
11131113
}
11141114

1115+
// Negative asserts that the specified element is negative
1116+
//
1117+
// assert.Negative(t, -1)
1118+
// assert.Negative(t, -1.23)
1119+
func Negative(t TestingT, e interface{}, msgAndArgs ...interface{}) {
1120+
if h, ok := t.(tHelper); ok {
1121+
h.Helper()
1122+
}
1123+
if assert.Negative(t, e, msgAndArgs...) {
1124+
return
1125+
}
1126+
t.FailNow()
1127+
}
1128+
1129+
// Negativef asserts that the specified element is negative
1130+
//
1131+
// assert.Negativef(t, -1, "error message %s", "formatted")
1132+
// assert.Negativef(t, -1.23, "error message %s", "formatted")
1133+
func Negativef(t TestingT, e interface{}, msg string, args ...interface{}) {
1134+
if h, ok := t.(tHelper); ok {
1135+
h.Helper()
1136+
}
1137+
if assert.Negativef(t, e, msg, args...) {
1138+
return
1139+
}
1140+
t.FailNow()
1141+
}
1142+
11151143
// Never asserts that the given condition doesn't satisfy in waitFor time,
11161144
// periodically checking the target function each tick.
11171145
//
@@ -1638,6 +1666,34 @@ func Panicsf(t TestingT, f assert.PanicTestFunc, msg string, args ...interface{}
16381666
t.FailNow()
16391667
}
16401668

1669+
// Positive asserts that the specified element is positive
1670+
//
1671+
// assert.Positive(t, 1)
1672+
// assert.Positive(t, 1.23)
1673+
func Positive(t TestingT, e interface{}, msgAndArgs ...interface{}) {
1674+
if h, ok := t.(tHelper); ok {
1675+
h.Helper()
1676+
}
1677+
if assert.Positive(t, e, msgAndArgs...) {
1678+
return
1679+
}
1680+
t.FailNow()
1681+
}
1682+
1683+
// Positivef asserts that the specified element is positive
1684+
//
1685+
// assert.Positivef(t, 1, "error message %s", "formatted")
1686+
// assert.Positivef(t, 1.23, "error message %s", "formatted")
1687+
func Positivef(t TestingT, e interface{}, msg string, args ...interface{}) {
1688+
if h, ok := t.(tHelper); ok {
1689+
h.Helper()
1690+
}
1691+
if assert.Positivef(t, e, msg, args...) {
1692+
return
1693+
}
1694+
t.FailNow()
1695+
}
1696+
16411697
// Regexp asserts that a specified regexp matches a string.
16421698
//
16431699
// assert.Regexp(t, regexp.MustCompile("start"), "it's starting")

require/require_forward.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -872,6 +872,28 @@ func (a *Assertions) Lessf(e1 interface{}, e2 interface{}, msg string, args ...i
872872
Lessf(a.t, e1, e2, msg, args...)
873873
}
874874

875+
// Negative asserts that the specified element is negative
876+
//
877+
// a.Negative(-1)
878+
// a.Negative(-1.23)
879+
func (a *Assertions) Negative(e interface{}, msgAndArgs ...interface{}) {
880+
if h, ok := a.t.(tHelper); ok {
881+
h.Helper()
882+
}
883+
Negative(a.t, e, msgAndArgs...)
884+
}
885+
886+
// Negativef asserts that the specified element is negative
887+
//
888+
// a.Negativef(-1, "error message %s", "formatted")
889+
// a.Negativef(-1.23, "error message %s", "formatted")
890+
func (a *Assertions) Negativef(e interface{}, msg string, args ...interface{}) {
891+
if h, ok := a.t.(tHelper); ok {
892+
h.Helper()
893+
}
894+
Negativef(a.t, e, msg, args...)
895+
}
896+
875897
// Never asserts that the given condition doesn't satisfy in waitFor time,
876898
// periodically checking the target function each tick.
877899
//
@@ -1284,6 +1306,28 @@ func (a *Assertions) Panicsf(f assert.PanicTestFunc, msg string, args ...interfa
12841306
Panicsf(a.t, f, msg, args...)
12851307
}
12861308

1309+
// Positive asserts that the specified element is positive
1310+
//
1311+
// a.Positive(1)
1312+
// a.Positive(1.23)
1313+
func (a *Assertions) Positive(e interface{}, msgAndArgs ...interface{}) {
1314+
if h, ok := a.t.(tHelper); ok {
1315+
h.Helper()
1316+
}
1317+
Positive(a.t, e, msgAndArgs...)
1318+
}
1319+
1320+
// Positivef asserts that the specified element is positive
1321+
//
1322+
// a.Positivef(1, "error message %s", "formatted")
1323+
// a.Positivef(1.23, "error message %s", "formatted")
1324+
func (a *Assertions) Positivef(e interface{}, msg string, args ...interface{}) {
1325+
if h, ok := a.t.(tHelper); ok {
1326+
h.Helper()
1327+
}
1328+
Positivef(a.t, e, msg, args...)
1329+
}
1330+
12871331
// Regexp asserts that a specified regexp matches a string.
12881332
//
12891333
// a.Regexp(regexp.MustCompile("start"), "it's starting")

0 commit comments

Comments
 (0)