Browse Source

Test that a RegEx Capture `pos` corresponds to its `groups`

Feoramund 1 year ago
parent
commit
cd8272557f
1 changed files with 7 additions and 0 deletions
  1. 7 0
      tests/core/text/regex/test_core_text_regex.odin

+ 7 - 0
tests/core/text/regex/test_core_text_regex.odin

@@ -44,6 +44,13 @@ check_expression_with_flags :: proc(t: ^testing.T, pattern: string, flags: regex
 	} else {
 	} else {
 		log.infof("match groups were: %v", capture.groups, location = loc)
 		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) {
 check_expression :: proc(t: ^testing.T, pattern, haystack: string, needles: ..string, extra_flags: regex.Flags = {}, loc := #caller_location) {