Skip to content

Commit 124baaa

Browse files
authored
Merge pull request #38 from c42f/caf/juliasyntax-fixes
Accommodate JuliaSyntax in tests
2 parents f38002a + 553c498 commit 124baaa

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)