@@ -8,22 +8,25 @@ struct Bar{T}; x::T; end
88struct OneChild3; x; y; z; end
99@functor OneChild3 (y,)
1010
11- struct NoChildren2 ; x; y; end
12- @functor NoChildren2 ()
11+ struct NoChild2 ; x; y; end
12+ @functor NoChild2 ()
1313
14- struct NoChild{T}; x:: T ; end
15- @functor NoChild ()
14+ struct NoChild1{T}; x:: T ; end
15+ @functor NoChild1 ()
16+
17+ struct LeafType{T}; x:: T ; end
18+ @leaf LeafType
1619
1720# ##
1821# ## Basic functionality
1922# ##
2023
21- @testset " Children and Leaves " begin
22- no_children = NoChildren2 (1 , 2 )
24+ @testset " NoChild is not a leaf " begin
25+ no_children = NoChild2 (1 , 2 )
2326 has_children = Foo (1 , 2 )
24- @test Functors. isleaf (no_children)
27+ @test ! Functors. isleaf (no_children)
2528 @test ! Functors. isleaf (has_children)
26- @test Functors. children (no_children) === Functors . NoChildren ( )
29+ @test Functors. children (no_children) === (; )
2730 @test Functors. children (has_children) == (x= 1 , y= 2 )
2831end
2932
97100 # Leaf types:
98101 @test usecache (d, [1 ,2 ])
99102 @test ! usecache (d, 4.0 )
100- @test usecache (d, NoChild ([1 ,2 ]))
101- @test ! usecache (d, NoChild ((3 ,4 )))
103+ @test usecache (d, LeafType ([1 ,2 ]))
104+ @test ! usecache (d, LeafType ((3 ,4 )))
102105
103106 # Not leaf:
104107 @test usecache (d, Ref (3 )) # mutable container
181184
182185 m1 = [1 , 2 , 3 ]
183186 m2 = Bar (m1)
184- m0 = NoChildren2 (:a , :b )
187+ m0 = NoChild2 (:a , :b )
185188 m3 = Foo (m2, m0)
186189 m4 = Bar (m3)
187190 @test all (fcollect (m4) .=== [m4, m3, m2, m1, m0])
238241 @test z4. x === z4. z
239242
240243 @test fmap (+ , foo1, m1, n1) isa Foo
241- @static if VERSION >= v " 1.6" # fails on Julia 1.0
242- @test fmap (.* , m1, foo1, n1) == (x = [4 * 7 , 2 * 5 * 8 ], y = 3 * 6 * 9 )
243- end
244+ @test fmap (.* , m1, foo1, n1) == (x = [4 * 7 , 2 * 5 * 8 ], y = 3 * 6 * 9 )
244245end
245246
246247@testset " old test update.jl" begin
303304end
304305
305306@testset " @leaf" begin
306- struct A; x; end
307- @functor A
308- a = A (1 )
309- @test Functors. children (a) === (x = 1 ,)
310- Functors. @leaf A
307+ a = LeafType (1 )
311308 children, re = Functors. functor (a)
312309 @test children == Functors. NoChildren ()
313310 @test re (children) === a
0 commit comments