@@ -17,13 +17,22 @@ function test_parse(production, input, output)
1717 else
1818 opts = NamedTuple()
1919 end
20- @test parse_to_sexpr_str(production, input; opts...) == output
20+ parsed = parse_to_sexpr_str(production, input; opts...)
21+ if output isa Regex # Could be AbstractPattern, but that type was added in Julia 1.6.
22+ @test match(output, parsed) !== nothing
23+ else
24+ @test parsed == output
25+ end
2126end
2227
2328function test_parse(inout::Pair)
2429 test_parse(JuliaSyntax.parse_toplevel, inout...)
2530end
2631
32+ const PARSE_ERROR = r"\(error-t "
33+
34+ with_version(v::VersionNumber, (i,o)::Pair) = ((;v=v), i) => o
35+
2736# TODO:
2837# * Extract the following test cases from the source itself.
2938# * Use only the green tree to generate the S-expressions
@@ -435,7 +444,7 @@ tests = [
435444 "x\"s\"in" => """(macrocall @x_str (string-r "s") "in")"""
436445 "x\"s\"2" => """(macrocall @x_str (string-r "s") 2)"""
437446 "x\"s\"10.0" => """(macrocall @x_str (string-r "s") 10.0)"""
438- #
447+ #
439448 ],
440449 JuliaSyntax.parse_resword => [
441450 # In normal_context
@@ -934,6 +943,26 @@ tests = [
934943 "10.0e1000'" => "(ErrorNumericOverflow)"
935944 "10.0f100'" => "(ErrorNumericOverflow)"
936945 ],
946+ JuliaSyntax.parse_stmts => with_version.(v"1.11", [
947+ "function f(public)\n public + 3\nend" => "(function (call f public) (block (call-i public + 3)))"
948+ "public A, B" => "(public A B)"
949+ "if true \n public *= 4 \n end" => "(if true (block (*= public 4)))"
950+ "module Mod\n public A, B \n end" => "(module Mod (block (public A B)))"
951+ "module Mod2\n a = 3; b = 6; public a, b\n end" => "(module Mod2 (block (= a 3) (= b 6) (public a b)))"
952+ "a = 3; b = 6; public a, b" => "(toplevel-; (= a 3) (= b 6) (public a b))"
953+ "begin \n public A, B \n end" => PARSE_ERROR
954+ "if true \n public A, B \n end" => PARSE_ERROR
955+ "public export=true foo, bar" => PARSE_ERROR # but these may be
956+ "public experimental=true foo, bar" => PARSE_ERROR # supported soon ;)
957+ "public(x::String) = false" => "(= (call public (::-i x String)) false)"
958+ "module M; export @a; end" => "(module M (block (export @a)))"
959+ "module M; public @a; end" => "(module M (block (public @a)))"
960+ "module M; export ⤈; end" => "(module M (block (export ⤈)))"
961+ "module M; public ⤈; end" => "(module M (block (public ⤈)))"
962+ "public = 4" => "(= public 4)"
963+ "public[7] = 5" => "(= (ref public 7) 5)"
964+ "public() = 6" => "(= (call public) 6)"
965+ ]),
937966 JuliaSyntax.parse_docstring => [
938967 """ "notdoc" ] """ => "(string \"notdoc\")"
939968 """ "notdoc" \n] """ => "(string \"notdoc\")"
0 commit comments