Skip to content

Commit 20e9d3a

Browse files
committed
test: anonymous function edgecases
1 parent f460b31 commit 20e9d3a

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

test/split.jl

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,38 @@ let
8383
@test (@splitcombine function (x::T, y::Vector{U}) where T <: U where U
8484
(T, U)
8585
end)(1, Number[2.0]) == (Int, Number)
86+
87+
# Test for lambda expressions with keyword arguments
88+
@test (@splitcombine (a::Int; b=2) -> a + b)(1) === 3
89+
@test (@splitcombine (a::Int; b::Float64=2.0) -> Float64(a) + b)(1) === 3.0
90+
@test (@splitcombine (a::Int, x; b=2, c=3) -> a + b + c + x)(1, 4) === 10
91+
@test (@splitcombine (a::Int, x=2) -> a + x)(1) === 3
92+
@test (@splitcombine (a::Int, x=2; y) -> a + x + y)(1; y=3) === 6
93+
@test (@splitcombine (a, x::Int=2; y) -> a + x + y)(1; y=3) === 6
94+
@test (@splitcombine (a::Int, x::Int=2; y) -> a + x + y)(1; y=3) === 6
95+
96+
# With tuple unpacking
97+
@test (@splitcombine (((a, b)::Tuple{Int, Int}, c; d=1) -> a + b + c + d))((1, 2), 3; d=4) === 10
98+
@test (@splitcombine ((c, (a, b); d=1) -> a + b + c + d))(3, (1, 2); d=4) === 10
99+
@test (@splitcombine ((c, (a, b); d) -> a + b + c + d))(3, (1, 2); d=4) === 10
100+
101+
# Test for single varargs argument in lambda
102+
@test splitdef(Meta.parse("(args...) -> 0"))[:args] == [:(args...)]
103+
@test (@splitcombine (args...) -> sum(args))(1, 2, 3) == 6
104+
@test (@splitcombine (args::Int...) -> sum(args))(1, 2, 3) == 6
105+
@test (@splitcombine (args::Int...; y=2) -> sum(args) + y)(1, 2, 3) == 8
106+
@test (@splitcombine (arg, args::Int...; y=2) -> arg + sum(args) + y)(1, 2, 3) == 8
107+
@test (@splitcombine (::Int...) -> 1)(1, 2, 3) === 1
108+
109+
# Splatted keyword arguments
110+
@test (@splitcombine (a::Int; kws...) -> a + sum(values(kws)))(1; b=2, c=3) == 6
111+
@test (@splitcombine (; kws...) -> sum(values(kws)))(b=2, c=3) == 5
112+
@test (@splitcombine (a::Int; b, kws...) -> a + b + sum(values(kws)))(1; b=2, c=3) == 6
113+
@test (@splitcombine (a::Int; b=2, kws...) -> a + b + sum(values(kws)))(1; c=3) == 6
114+
115+
# Both splatted positional and keyword arguments
116+
@test (@splitcombine (a::Int, args::Int...; kws...) -> a + sum(args) + sum(values(kws)))(1, 2, 3; b=4, c=5) == 15
117+
@test (@splitcombine (a, ::Int...; b, kws...) -> a + sum(values(kws)))(1, 2, 3; b=4, c=5) == 1 + 5
86118
end
87119

88120
@testset "combinestructdef, splitstructdef" begin

0 commit comments

Comments
 (0)