Skip to content

Commit

Permalink
test: alternation parsing in various syntaxes
Browse files Browse the repository at this point in the history
  • Loading branch information
rgrinberg committed Oct 26, 2024
1 parent 3c286ec commit eea03e1
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib_test/expect/import.ml
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,5 @@ let rec sexp_of_dyn (t : Re_private.Dyn.t) : Base.Sexp.t =
| List [] -> None
| sexp -> Some (Base.Sexp.List [ Atom name; sexp ])))
;;

let print_dyn dyn = sexp_of_dyn dyn |> Base.Sexp.to_string_hum |> print_endline
48 changes: 48 additions & 0 deletions lib_test/expect/test_alternation.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
open Import
module Ast = Re_private.Ast

let test f string =
match f string with
| Ok res -> print_dyn (Ast.to_dyn res)
| Error _ -> assert false
;;

let%expect_test "pcre" =
test Re.Pcre.re_result "(a|b|c)";
[%expect
{|
(Group
(Set
(Cast (Alternative (Cast (Alternative (Cset 97) (Cset 98))) (Cset 99)))))
|}]
;;

let%expect_test "emacs" =
test Re.Emacs.re_result {|\(a\|b\|c\)|};
[%expect
{|
(Group
(Set
(Cast (Alternative (Cast (Alternative (Cset 97) (Cset 98))) (Cset 99)))))
|}]
;;

let%expect_test "perl" =
test Re.Perl.re_result "(a|b|c)";
[%expect
{|
(Group
(Set
(Cast (Alternative (Cast (Alternative (Cset 97) (Cset 98))) (Cset 99)))))
|}]
;;

let%expect_test "posix" =
test Re.Posix.re_result "(a|b|c)";
[%expect
{|
(Group
(Set
(Cast (Alternative (Cast (Alternative (Cset 97) (Cset 98))) (Cset 99)))))
|}]
;;

0 comments on commit eea03e1

Please sign in to comment.