Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: move repn tests to own module #519

Merged
merged 1 commit into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) |] |}]
;;
Loading