mirror of https://github.com/stretchr/testify.git
Merge pull request #122 from stretchr/issues/120
Fixed regexp messages. Resolves #120.pull/88/merge
commit
fe50b6aa5a
|
@ -751,12 +751,12 @@ func matchRegexp(rx interface{}, str interface{}) bool {
|
||||||
// assert.Regexp(t, "start...$", "it's not starting")
|
// assert.Regexp(t, "start...$", "it's not starting")
|
||||||
//
|
//
|
||||||
// Returns whether the assertion was successful (true) or not (false).
|
// Returns whether the assertion was successful (true) or not (false).
|
||||||
func Regexp(t TestingT, rx interface{}, str interface{}) bool {
|
func Regexp(t TestingT, rx interface{}, str interface{}, msgAndArgs ...interface{}) bool {
|
||||||
|
|
||||||
match := matchRegexp(rx, str)
|
match := matchRegexp(rx, str)
|
||||||
|
|
||||||
if !match {
|
if !match {
|
||||||
Fail(t, "Expect \"%v\" to match \"%v\"", str, rx)
|
Fail(t, fmt.Sprintf("Expect \"%v\" to match \"%v\"", str, rx), msgAndArgs...)
|
||||||
}
|
}
|
||||||
|
|
||||||
return match
|
return match
|
||||||
|
@ -768,11 +768,11 @@ func Regexp(t TestingT, rx interface{}, str interface{}) bool {
|
||||||
// assert.NotRegexp(t, "^start", "it's not starting")
|
// assert.NotRegexp(t, "^start", "it's not starting")
|
||||||
//
|
//
|
||||||
// Returns whether the assertion was successful (true) or not (false).
|
// Returns whether the assertion was successful (true) or not (false).
|
||||||
func NotRegexp(t TestingT, rx interface{}, str interface{}) bool {
|
func NotRegexp(t TestingT, rx interface{}, str interface{}, msgAndArgs ...interface{}) bool {
|
||||||
match := matchRegexp(rx, str)
|
match := matchRegexp(rx, str)
|
||||||
|
|
||||||
if match {
|
if match {
|
||||||
Fail(t, "Expect \"%v\" to NOT match \"%v\"", str, rx)
|
Fail(t, fmt.Sprintf("Expect \"%v\" to NOT match \"%v\"", str, rx), msgAndArgs...)
|
||||||
}
|
}
|
||||||
|
|
||||||
return !match
|
return !match
|
||||||
|
|
|
@ -237,8 +237,8 @@ func (a *Assertions) EqualError(theError error, errString string, msgAndArgs ...
|
||||||
// assert.Regexp(t, "start...$", "it's not starting")
|
// assert.Regexp(t, "start...$", "it's not starting")
|
||||||
//
|
//
|
||||||
// Returns whether the assertion was successful (true) or not (false).
|
// Returns whether the assertion was successful (true) or not (false).
|
||||||
func (a *Assertions) Regexp(rx interface{}, str interface{}) bool {
|
func (a *Assertions) Regexp(rx interface{}, str interface{}, msgAndArgs ...interface{}) bool {
|
||||||
return Regexp(a.t, rx, str)
|
return Regexp(a.t, rx, str, msgAndArgs...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// NotRegexp asserts that a specified regexp does not match a string.
|
// NotRegexp asserts that a specified regexp does not match a string.
|
||||||
|
@ -247,6 +247,6 @@ func (a *Assertions) Regexp(rx interface{}, str interface{}) bool {
|
||||||
// assert.NotRegexp(t, "^start", "it's not starting")
|
// assert.NotRegexp(t, "^start", "it's not starting")
|
||||||
//
|
//
|
||||||
// Returns whether the assertion was successful (true) or not (false).
|
// Returns whether the assertion was successful (true) or not (false).
|
||||||
func (a *Assertions) NotRegexp(rx interface{}, str interface{}) bool {
|
func (a *Assertions) NotRegexp(rx interface{}, str interface{}, msgAndArgs ...interface{}) bool {
|
||||||
return NotRegexp(a.t, rx, str)
|
return NotRegexp(a.t, rx, str, msgAndArgs...)
|
||||||
}
|
}
|
||||||
|
|
|
@ -198,14 +198,14 @@ func (a *Assertions) EqualError(theError error, errString string, msgAndArgs ...
|
||||||
//
|
//
|
||||||
// require.Regexp(t, regexp.MustCompile("start"), "it's starting")
|
// require.Regexp(t, regexp.MustCompile("start"), "it's starting")
|
||||||
// require.Regexp(t, "start...$", "it's not starting")
|
// require.Regexp(t, "start...$", "it's not starting")
|
||||||
func (a *Assertions) Regexp(rx interface{}, str interface{}) {
|
func (a *Assertions) Regexp(rx interface{}, str interface{}, msgAndArgs ...interface{}) {
|
||||||
Regexp(a.t, rx, str)
|
Regexp(a.t, rx, str, msgAndArgs...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// NotRegexp asserts that a specified regexp does not match a string.
|
// NotRegexp asserts that a specified regexp does not match a string.
|
||||||
//
|
//
|
||||||
// require.NotRegexp(t, regexp.MustCompile("starts"), "it's starting")
|
// require.NotRegexp(t, regexp.MustCompile("starts"), "it's starting")
|
||||||
// require.NotRegexp(t, "^start", "it's not starting")
|
// require.NotRegexp(t, "^start", "it's not starting")
|
||||||
func (a *Assertions) NotRegexp(rx interface{}, str interface{}) {
|
func (a *Assertions) NotRegexp(rx interface{}, str interface{}, msgAndArgs ...interface{}) {
|
||||||
NotRegexp(a.t, rx, str)
|
NotRegexp(a.t, rx, str, msgAndArgs...)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
package require
|
package require
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
type TestingT interface {
|
type TestingT interface {
|
||||||
|
@ -202,8 +203,8 @@ func InEpsilon(t TestingT, expected, actual interface{}, epsilon float64, msgAnd
|
||||||
//
|
//
|
||||||
// require.Regexp(t, regexp.MustCompile("start"), "it's starting")
|
// require.Regexp(t, regexp.MustCompile("start"), "it's starting")
|
||||||
// require.Regexp(t, "start...$", "it's not starting")
|
// require.Regexp(t, "start...$", "it's not starting")
|
||||||
func Regexp(t TestingT, rx interface{}, str interface{}) {
|
func Regexp(t TestingT, rx interface{}, str interface{}, msgAndArgs ...interface{}) {
|
||||||
if !assert.Regexp(t, rx, str) {
|
if !assert.Regexp(t, rx, str, msgAndArgs...) {
|
||||||
t.FailNow()
|
t.FailNow()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -212,8 +213,8 @@ func Regexp(t TestingT, rx interface{}, str interface{}) {
|
||||||
//
|
//
|
||||||
// require.NotRegexp(t, regexp.MustCompile("starts"), "it's starting")
|
// require.NotRegexp(t, regexp.MustCompile("starts"), "it's starting")
|
||||||
// require.NotRegexp(t, "^start", "it's not starting")
|
// require.NotRegexp(t, "^start", "it's not starting")
|
||||||
func NotRegexp(t TestingT, rx interface{}, str interface{}) {
|
func NotRegexp(t TestingT, rx interface{}, str interface{}, msgAndArgs ...interface{}) {
|
||||||
if !assert.NotRegexp(t, rx, str) {
|
if !assert.NotRegexp(t, rx, str, msgAndArgs...) {
|
||||||
t.FailNow()
|
t.FailNow()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue