...

Source file src/github.com/dlclark/regexp2/regexp_options_test.go

Documentation: github.com/dlclark/regexp2

     1  package regexp2
     2  
     3  import "testing"
     4  
     5  func TestIgnoreCase_Simple(t *testing.T) {
     6  	r := MustCompile("aaamatch thisbbb", IgnoreCase)
     7  	m, err := r.FindStringMatch("AaAMatch thisBBb")
     8  	if err != nil {
     9  		t.Fatalf("unexpected error: %v", err)
    10  	}
    11  	if m == nil {
    12  		t.Fatalf("no match when one was expected")
    13  	}
    14  	if want, got := "AaAMatch thisBBb", m.String(); want != got {
    15  		t.Fatalf("group 0 wanted '%v', got '%v'", want, got)
    16  	}
    17  }
    18  
    19  func TestIgnoreCase_Inline(t *testing.T) {
    20  	r := MustCompile("aaa(?i:match this)bbb", 0)
    21  	m, err := r.FindStringMatch("aaaMaTcH ThIsbbb")
    22  	if err != nil {
    23  		t.Fatalf("unexpected error: %v", err)
    24  	}
    25  	if m == nil {
    26  		t.Fatalf("no match when one was expected")
    27  	}
    28  	if want, got := "aaaMaTcH ThIsbbb", m.String(); want != got {
    29  		t.Fatalf("group 0 wanted '%v', got '%v'", want, got)
    30  	}
    31  }
    32  
    33  func TestIgnoreCase_Revert(t *testing.T) {
    34  
    35  	r := MustCompile("aaa(?-i:match this)bbb", IgnoreCase)
    36  	m, err := r.FindStringMatch("AaAMatch thisBBb")
    37  	if err != nil {
    38  		t.Fatalf("unexpected error: %v", err)
    39  	}
    40  	if m != nil {
    41  		t.Fatalf("had a match but expected no match")
    42  	}
    43  }
    44  

View as plain text