From e87e198aba97bf82067ab6f9b7d1fe46dc28b81f Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Thu, 3 Oct 2024 22:35:35 +0100 Subject: [PATCH] test: move repn tests to own module --- lib_test/expect/test_re.ml | 58 ----------------------------------- lib_test/expect/test_repn.ml | 59 ++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 58 deletions(-) create mode 100644 lib_test/expect/test_repn.ml diff --git a/lib_test/expect/test_re.ml b/lib_test/expect/test_re.ml index 23eace31..9e6da0df 100644 --- a/lib_test/expect/test_re.ml +++ b/lib_test/expect/test_re.ml @@ -1,18 +1,4 @@ open Import - -let%expect_test "fixed repetition" = - let re = Re.compile @@ Re.(repn (char 'a') 3 (Some 3)) in - let test s = printf "%b\n" (Re.execp re s) in - test ""; - [%expect {| false |}]; - test "aa"; - [%expect {| false |}]; - test "aaa"; - [%expect {| true |}]; - test "aaaa"; - [%expect {| true |}] -;; - open Re let%expect_test "str" = @@ -72,50 +58,6 @@ let%expect_test "rep" = [%expect {| [| (0, 0) |] |}] ;; -let%expect_test "rep1" = - test_re (rep1 (char 'a')) "a"; - [%expect {| [| (0, 1) |] |}]; - test_re (rep1 (char 'a')) "aa"; - [%expect {| [| (0, 2) |] |}]; - test_re (rep1 (char 'a')) ""; - [%expect {| Not_found |}]; - test_re (rep1 (char 'a')) "b"; - [%expect {| Not_found |}] -;; - -let%expect_test "repn" = - let a = char 'a' in - test_re (repn a 0 None) ""; - [%expect {| [| (0, 0) |] |}]; - test_re (repn a 2 None) "a"; - [%expect {| Not_found |}]; - test_re (repn a 2 None) "aa"; - [%expect {| [| (0, 2) |] |}]; - test_re (repn a 0 (Some 0)) ""; - [%expect {| [| (0, 0) |] |}]; - test_re (repn a 1 (Some 2)) "a"; - [%expect {| [| (0, 1) |] |}]; - test_re (repn a 1 (Some 2)) "aa"; - [%expect {| [| (0, 2) |] |}]; - test_re (repn a 1 (Some 2)) ""; - [%expect {| Not_found |}]; - test_re (repn a 1 (Some 2)) "aaa"; - [%expect {| [| (0, 2) |] |}]; - invalid_argument (fun () -> repn empty (-1) None); - [%expect {| Invalid_argument "Re.repn" |}]; - invalid_argument (fun () -> repn empty 1 (Some 0)); - [%expect {| Invalid_argument "Re.repn" |}]; - invalid_argument (fun () -> repn empty 4 (Some 3)); - [%expect {| Invalid_argument "Re.repn" |}] -;; - -let%expect_test "opt" = - test_re (opt (char 'a')) ""; - [%expect {| [| (0, 0) |] |}]; - test_re (opt (char 'a')) "a"; - [%expect {| [| (0, 1) |] |}] -;; - let%expect_test "bol" = test_re (seq [ bol; char 'a' ]) "ab"; [%expect {| [| (0, 1) |] |}]; diff --git a/lib_test/expect/test_repn.ml b/lib_test/expect/test_repn.ml new file mode 100644 index 00000000..c908e531 --- /dev/null +++ b/lib_test/expect/test_repn.ml @@ -0,0 +1,59 @@ +open Import +open Re + +let%expect_test "fixed repetition" = + let re = Re.compile @@ Re.(repn (char 'a') 3 (Some 3)) in + let test s = printf "%b\n" (Re.execp re s) in + test ""; + [%expect {| false |}]; + test "aa"; + [%expect {| false |}]; + test "aaa"; + [%expect {| true |}]; + test "aaaa"; + [%expect {| true |}] +;; + +let%expect_test "repn" = + let a = char 'a' in + test_re (repn a 0 None) ""; + [%expect {| [| (0, 0) |] |}]; + test_re (repn a 2 None) "a"; + [%expect {| Not_found |}]; + test_re (repn a 2 None) "aa"; + [%expect {| [| (0, 2) |] |}]; + test_re (repn a 0 (Some 0)) ""; + [%expect {| [| (0, 0) |] |}]; + test_re (repn a 1 (Some 2)) "a"; + [%expect {| [| (0, 1) |] |}]; + test_re (repn a 1 (Some 2)) "aa"; + [%expect {| [| (0, 2) |] |}]; + test_re (repn a 1 (Some 2)) ""; + [%expect {| Not_found |}]; + test_re (repn a 1 (Some 2)) "aaa"; + [%expect {| [| (0, 2) |] |}]; + invalid_argument (fun () -> repn empty (-1) None); + [%expect {| Invalid_argument "Re.repn" |}]; + invalid_argument (fun () -> repn empty 1 (Some 0)); + [%expect {| Invalid_argument "Re.repn" |}]; + invalid_argument (fun () -> repn empty 4 (Some 3)); + [%expect {| Invalid_argument "Re.repn" |}] +;; + +let%expect_test "rep1" = + test_re (rep1 (char 'a')) "a"; + [%expect {| [| (0, 1) |] |}]; + test_re (rep1 (char 'a')) "aa"; + [%expect {| [| (0, 2) |] |}]; + test_re (rep1 (char 'a')) ""; + [%expect {| Not_found |}]; + test_re (rep1 (char 'a')) "b"; + [%expect {| Not_found |}] +;; + +let%expect_test "opt" = + test_re (opt (char 'a')) ""; + [%expect {| [| (0, 0) |] |}]; + test_re (opt (char 'a')) "a"; + [%expect {| [| (0, 1) |] |}] +;;