Skip to content

Commit 896189e

Browse files
committed
Add test for when no capture group is used with inline option
1 parent 197dfc9 commit 896189e

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

regexp_MaintainCaptureOrder_test.go

+29-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@ func TestMaintainCaptureOrder_Enable_Inline(t *testing.T) {
106106
}
107107
text := "This is a \ntesting stuff"
108108
m, err := r.FindStringMatch(text)
109-
// t.Errorf(" groups: %#v\n", m)
110109
if err != nil {
111110
t.Errorf("unexpected match err: %v", err)
112111
}
@@ -143,6 +142,35 @@ func TestMaintainCaptureOrder_Enable_Inline(t *testing.T) {
143142
}
144143
}
145144

145+
func TestMaintainCaptureOrder_Inline_No_Capture_Groups(t *testing.T) {
146+
r, err := Compile("(?o)this.+?testing.+?stuff", 0)
147+
// t.Logf("code dump: %v", r.code.Dump())
148+
if err != nil {
149+
t.Errorf("unexpected compile err: %v", err)
150+
}
151+
text := `this is a testing stuff`
152+
m, err := r.FindStringMatch(text)
153+
if err != nil {
154+
t.Errorf("unexpected match err: %v", err)
155+
}
156+
if m == nil {
157+
t.Error("Nil match, expected success")
158+
} else {
159+
//t.Logf("Match: %v", m.dump())
160+
}
161+
162+
groups := m.Groups()
163+
if want, got := text, m.String(); want != got {
164+
t.Fatalf("Wanted '%v'\nGot '%v'", want, got)
165+
}
166+
if want, got := text, groups[0].String(); want != got {
167+
t.Fatalf("Wanted '%v'\nGot '%v'", want, got)
168+
}
169+
if want, got := 1, len(groups); want != got {
170+
t.Fatalf("Wanted '%v'\nGot '%v'", want, got)
171+
}
172+
}
173+
146174
func TestMaintainCaptureOrder_NestedCaptures(t *testing.T) {
147175
r, err := Compile(
148176
`(?<first>This)(?<second>(.)+?(?<test>testing)).+?(some.+?(other).+?(?<last>stuff)) (?<test>\k<test>)`, MaintainCaptureOrder)

0 commit comments

Comments
 (0)