Browse Source

Add explicit test case for Capture `pos`

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

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

@@ -499,6 +499,31 @@ test_word_boundaries :: proc(t: ^testing.T) {
 	}
 }
 
+@test
+test_pos_index_explicitly :: proc(t: ^testing.T) {
+	STR :: "This is an island."
+	EXPR :: `\bis\b`
+
+	rex, err := regex.create(EXPR, { .Global })
+	if !testing.expect_value(t, err, nil) {
+		return
+	}
+	defer regex.destroy(rex)
+
+	capture, success := regex.match(rex, STR)
+	log.info(capture, success)
+	if !testing.expect(t, success) {
+		return
+	}
+	defer regex.destroy(capture)
+
+	if !testing.expect_value(t, len(capture.pos), 1) {
+		return
+	}
+	testing.expect_value(t, capture.pos[0][0], 5)
+	testing.expect_value(t, capture.pos[0][1], 7)
+}
+
 @test
 test_non_word_boundaries :: proc(t: ^testing.T) {
 	{