File: regexp_options_test.go

package info (click to toggle)
golang-github-dlclark-regexp2 1.2.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 560 kB
  • sloc: makefile: 3
file content (43 lines) | stat: -rw-r--r-- 1,086 bytes parent folder | download | duplicates (2)
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")
	}
}