-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathassert_match.go
59 lines (50 loc) · 1.33 KB
/
assert_match.go
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
package actually
import (
"fmt"
"regexp"
"testing"
)
// Match method asserts that test data you got match expected value as regexp.
/*
actually.Got("target string").Expect(`.ing$`).Match(t) // pass
*/
func (a *testingA) Match(t *testing.T, testNames ...string) *testingA {
invalidCall(a)
a.name = a.naming(testNames...)
a.t = t
a.t.Helper()
var r *regexp.Regexp
if rr, ok := a.expect.(*regexp.Regexp); ok {
r = rr
} else {
r = regexp.MustCompile(fmt.Sprint(a.expect))
}
target := fmt.Sprint(a.got)
if !r.MatchString(target) {
wi := a.wi().Message(message_label_Regexp, r.String()).Message(message_label_Target, target)
return a.fail(wi, reason_NotMatch)
}
return a
}
// NotMatch method asserts that test data you got don't match expected value as regexp.
/*
actually.Got("target string").Expect(`^[a-z]+$`).NotMatch(t) // pass
*/
func (a *testingA) NotMatch(t *testing.T, testNames ...string) *testingA {
invalidCall(a)
a.name = a.naming(testNames...)
a.t = t
a.t.Helper()
var r *regexp.Regexp
if rr, ok := a.expect.(*regexp.Regexp); ok {
r = rr
} else {
r = regexp.MustCompile(fmt.Sprint(a.expect))
}
target := fmt.Sprint(a.got)
if r.MatchString(target) {
wi := a.wi().Message(message_label_Regexp, r.String()).Message(message_label_Target, target)
return a.fail(wi, reason_UnexpectedlyMatch)
}
return a
}