@@ -3,72 +3,6 @@ using MacroTools: splitstructdef, combinestructdef
33macro nothing_macro () end
44@test @expand (@nothing_macro ) === nothing
55
6- macro splitcombine (fundef) # should be a no-op
7- dict = splitdef (fundef)
8- esc (MacroTools. combinedef (dict))
9- end
10-
11- # Macros for testing that splitcombine doesn't break
12- # macrocalls in bodies
13- macro zeroarg ()
14- :(1 )
15- end
16- macro onearg (x)
17- :(1 + $ (esc (x)))
18- end
19-
20- let
21- # Ideally we'd compare the result against :(function f(x)::Int 10 end),
22- # but it fails because of :line and :block differences
23- @test longdef (:(f (x):: Int = 10 )). head == :function
24- @test longdef (:(f (x:: T ) where U where T = 2 )). head == :function
25- @test shortdef (:(function f (x):: Int 10 end )). head != :function
26- @test map (splitarg, (:(f (a= 2 , x:: Int = nothing , y, args... ))). args[2 : end ]) ==
27- [(:a , :Any , false , 2 ), (:x , :Int , false , :nothing ),
28- (:y , :Any , false , nothing ), (:args , :Any , true , nothing )]
29- @test splitarg (:(:: Int )) == (nothing , :Int , false , nothing )
30-
31- @splitcombine foo (x) = x+ 2
32- @test foo (10 ) == 12
33- @splitcombine add (a, b= 2 ; c= 3 , d= 4 ):: Float64 = a+ b+ c+ d
34- @test add (1 ; d= 10 ) === 16.0
35- @splitcombine fparam (a:: T ) where {T} = T
36- @test fparam ([]) == Vector{Any}
37- struct Orange end
38- @splitcombine (:: Orange )(x) = x+ 2
39- @test Orange ()(10 ) == 12
40- @splitcombine fwhere (a:: T ) where T = T
41- @test fwhere (10 ) == Int
42- @splitcombine manywhere (x:: T , y:: Vector{U} ) where T <: U where U = (T, U)
43- @test manywhere (1 , Number[2.0 ]) == (Int, Number)
44- @splitcombine fmacro0 () = @zeroarg
45- @test fmacro0 () == 1
46- @splitcombine fmacro1 () = @onearg 1
47- @test fmacro1 () == 2
48-
49- struct Foo{A, B}
50- a:: A
51- b:: B
52- end
53- # Parametric outer constructor
54- @splitcombine Foo {A} (a:: A ) where A = Foo {A, A} (a,a)
55- @test Foo {Int} (2 ) == Foo {Int, Int} (2 , 2 )
56-
57- @test (@splitcombine x -> x + 2 )(10 ) === 12
58- @test (@splitcombine (a, b= 2 ; c= 3 , d= 4 ) -> a+ b+ c+ d)(1 ; d= 10 ) === 16
59- @test (@splitcombine ((a, b):: Tuple{Int,Int} -> a + b))((1 , 2 )) == 3
60- @test (@splitcombine ((a:: T ) where {T}) -> T)([]) === Vector{Any}
61- @test (@splitcombine ((x:: T , y:: Vector{U} ) where T <: U where U) -> (T, U))(1 , Number[2.0 ]) ==
62- (Int, Number)
63- @test (@splitcombine () -> @zeroarg )() == 1
64- @test (@splitcombine () -> @onearg 1 )() == 2
65- @test (@splitcombine function (x) x + 2 end )(10 ) === 12
66- @test (@splitcombine function (a:: T ) where {T} T end )([]) === Vector{Any}
67- @test (@splitcombine function (x:: T , y:: Vector{U} ) where T <: U where U
68- (T, U)
69- end )(1 , Number[2.0 ]) == (Int, Number)
70- end
71-
726@testset " combinestructdef, splitstructdef" begin
737 ex = :(struct S end )
748 @test ex |> splitstructdef |> combinestructdef |> Base. remove_linenums! ==
0 commit comments