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

Accommodate JuliaSyntax in tests #38

Merged
merged 1 commit into from
Jun 22, 2023
Merged
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
36 changes: 28 additions & 8 deletions test/function.jl
Original file line number Diff line number Diff line change
Expand Up @@ -483,12 +483,24 @@ function_form(short::Bool) = string(short ? "short" : "long", "-form")
@testset "block expression ($(function_form(short)) anonymous function)" for short in (true, false)
@testset "(;)" begin
# The `(;)` syntax was deprecated in 1.4.0-DEV.585 (ce29ec547e) but we can still
# test the behavior with `begin end`.
f, expr = if short
@audit (begin end) -> nothing
else
@audit function (begin end) nothing end
end
# test the behavior with an explicit Expr
expr = if short
# `(;) -> nothing`
Expr(
:->,
Expr(:block),
Expr(:block, LineNumberNode(@__LINE__, @__FILE__), :nothing),
)
else
# `function (;) nothing end`
Expr(
:function,
Expr(:block),
Expr(:block, LineNumberNode(@__LINE__, @__FILE__), :nothing),
)
end
f = eval(expr)

@test length(methods(f)) == 1
@test f() === nothing

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

@testset "return-type (long-form anonymous function)" begin
@testset "(x)::Integer" begin
# Interpreted as `function (x::Integer); x end`
f, expr = @audit function (x)::Integer; x end
# Older parsers interpret
# `function (x)::Integer; x end`
# as
# `function (x::Integer); x end`
expr = Expr(
:function,
Expr(:tuple, Expr(:(::), :x, :Integer)),
Expr(:block, LineNumberNode(@__LINE__, @__FILE__), :x),
)
f = eval(expr)
@test length(methods(f)) == 1
@test f(0) == 0
@test_throws MethodError f(0.0)
Expand Down