Test that a RegEx Capture pos corresponds to its groups

This commit is contained in:
Feoramund
2024-08-04 18:33:36 -04:00
parent 6252712363
commit cd8272557f

View File

@@ -44,6 +44,13 @@ check_expression_with_flags :: proc(t: ^testing.T, pattern: string, flags: regex
} else {
log.infof("match groups were: %v", capture.groups, location = loc)
}
for pos, g in capture.pos {
pos_str := haystack[pos[0]:pos[1]]
if !testing.expectf(t, pos_str == capture.groups[g], "position string %v %q does not correspond to group string %q", pos, pos_str, capture.groups[g]) {
break
}
}
}
check_expression :: proc(t: ^testing.T, pattern, haystack: string, needles: ..string, extra_flags: regex.Flags = {}, loc := #caller_location) {