-
Notifications
You must be signed in to change notification settings - Fork 83
/
regexp_options_test.go
43 lines (38 loc) · 1.06 KB
/
regexp_options_test.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
package regexp2
import "testing"
func TestIgnoreCase_Simple(t *testing.T) {
r := MustCompile("aaamatch thisbbb", IgnoreCase)
m, err := r.FindStringMatch("AaAMatch thisBBb")
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if m == nil {
t.Fatalf("no match when one was expected")
}
if want, got := "AaAMatch thisBBb", m.String(); want != got {
t.Fatalf("group 0 wanted '%v', got '%v'", want, got)
}
}
func TestIgnoreCase_Inline(t *testing.T) {
r := MustCompile("aaa(?i:match this)bbb", 0)
m, err := r.FindStringMatch("aaaMaTcH ThIsbbb")
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if m == nil {
t.Fatalf("no match when one was expected")
}
if want, got := "aaaMaTcH ThIsbbb", m.String(); want != got {
t.Fatalf("group 0 wanted '%v', got '%v'", want, got)
}
}
func TestIgnoreCase_Revert(t *testing.T) {
r := MustCompile("aaa(?-i:match this)bbb", IgnoreCase)
m, err := r.FindStringMatch("AaAMatch thisBBb")
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if m != nil {
t.Fatalf("had a match but expected no match")
}
}