Skip to content

Commit

Permalink
test: move repn tests to own module
Browse files Browse the repository at this point in the history
  • Loading branch information
rgrinberg committed Oct 3, 2024
1 parent f7fbc8f commit e87e198
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 58 deletions.
58 changes: 0 additions & 58 deletions lib_test/expect/test_re.ml
Original file line number Diff line number Diff line change
@@ -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" =
Expand Down Expand Up @@ -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) |] |}];
Expand Down
59 changes: 59 additions & 0 deletions lib_test/expect/test_repn.ml
Original file line number Diff line number Diff line change
@@ -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) |] |}]
;;

0 comments on commit e87e198

Please sign in to comment.