From 7cbdd5faf9ea0956b8d7d3e956cfac46201edd39 Mon Sep 17 00:00:00 2001 From: Stephane Glondu Date: Thu, 3 Aug 2023 13:23:04 +0200 Subject: [PATCH] Add a test of named groups in test_pcre --- lib_test/test_pcre.ml | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib_test/test_pcre.ml b/lib_test/test_pcre.ml index 308de047..d18966aa 100644 --- a/lib_test/test_pcre.ml +++ b/lib_test/test_pcre.ml @@ -41,13 +41,21 @@ let group_split2 _ = let sp = full_split ~rex "testxyyy" in assert_equal ~printer sp [Text "test"; Delim "x"; NoGroup; Text "yyy"] +let rex = regexp "(?x+)" + +let named_groups _ = + let s = exec ~rex "testxxxyyy" in + assert_equal (get_named_substring rex "many_x" s) "xxx" + let test_fixtures = "test pcre features" >::: [ "test [:blank:] class" >:: test_blank_class ; "test splitting empty string" >:: split_empty ; "test split with max of 1" >:: split_max_1 ; "test group split 1" >:: group_split1 - ; "test group split 2 - NoGroup" >:: group_split2] + ; "test group split 2 - NoGroup" >:: group_split2 + ; "test named groups" >:: named_groups + ] let _ = run_test_tt_main test_fixtures