Skip to content

Commit 553c498

Browse files
committed
Accommodate JuliaSyntax in tests
JuliaSyntax generates more consistent syntax trees for obscure versions of long and short form anonymous function argument lists. For the cases which are different and lead to errors, adjust the tests to use explicit `Expr`s here so that we're testing ExprTools code rather than the Julia parser itself. * `function (x)::Integer; x end` is now parsed correctly * Use an explicit Expr for the old `(;) -> nothing` syntax
1 parent f38002a commit 553c498

File tree

1 file changed

+28
-8
lines changed

1 file changed

+28
-8
lines changed

test/function.jl

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -483,12 +483,24 @@ function_form(short::Bool) = string(short ? "short" : "long", "-form")
483483
@testset "block expression ($(function_form(short)) anonymous function)" for short in (true, false)
484484
@testset "(;)" begin
485485
# The `(;)` syntax was deprecated in 1.4.0-DEV.585 (ce29ec547e) but we can still
486-
# test the behavior with `begin end`.
487-
f, expr = if short
488-
@audit (begin end) -> nothing
489-
else
490-
@audit function (begin end) nothing end
491-
end
486+
# test the behavior with an explicit Expr
487+
expr = if short
488+
# `(;) -> nothing`
489+
Expr(
490+
:->,
491+
Expr(:block),
492+
Expr(:block, LineNumberNode(@__LINE__, @__FILE__), :nothing),
493+
)
494+
else
495+
# `function (;) nothing end`
496+
Expr(
497+
:function,
498+
Expr(:block),
499+
Expr(:block, LineNumberNode(@__LINE__, @__FILE__), :nothing),
500+
)
501+
end
502+
f = eval(expr)
503+
492504
@test length(methods(f)) == 1
493505
@test f() === nothing
494506

@@ -788,8 +800,16 @@ function_form(short::Bool) = string(short ? "short" : "long", "-form")
788800

789801
@testset "return-type (long-form anonymous function)" begin
790802
@testset "(x)::Integer" begin
791-
# Interpreted as `function (x::Integer); x end`
792-
f, expr = @audit function (x)::Integer; x end
803+
# Older parsers interpret
804+
# `function (x)::Integer; x end`
805+
# as
806+
# `function (x::Integer); x end`
807+
expr = Expr(
808+
:function,
809+
Expr(:tuple, Expr(:(::), :x, :Integer)),
810+
Expr(:block, LineNumberNode(@__LINE__, @__FILE__), :x),
811+
)
812+
f = eval(expr)
793813
@test length(methods(f)) == 1
794814
@test f(0) == 0
795815
@test_throws MethodError f(0.0)

0 commit comments

Comments
 (0)