@@ -14,6 +14,7 @@ struct NoChildren2; x; y; end
1414
1515struct NoChild{T}; x:: T ; end
1616
17+
1718# ##
1819# ## Basic functionality
1920# ##
5657 m1p = fmapstructure (identity, m1; prune = nothing )
5758 @test m1p == (x = [1 , 2 , 3 ], y = (x = [1 , 2 , 3 ], y = (x = nothing , y = [1 , 2 , 3 ])))
5859
59- # A non- leaf node can also be repeated :
60+ # The cache applies only to leaf nodes, so that "4" is not shared :
6061 m2 = Foo (Foo (shared, 4 ), Foo (shared, 4 ))
6162 @test m2. x === m2. y
6263 m2f = fmap (float, m2)
6364 @test m2f. x. x === m2f. y. x
6465 m2p = fmapstructure (identity, m2; prune = Bar (0 ))
65- @test m2p == (x = (x = [1 , 2 , 3 ], y = 4 ), y = Bar ( 0 ))
66+ @test m2p == (x = (x = [1 , 2 , 3 ], y = 4 ), y = (x = Bar {Int64} ( 0 ), y = 4 ))
6667
6768 # Repeated isbits types should not automatically be regarded as shared:
6869 m3 = Foo (Foo (shared, 1 : 3 ), Foo (1 : 3 , shared))
7576 @test_skip 0 == @allocated fmap (float, (x= 1 , y= (2 , 3 ), z= 4 : 5 ))
7677
7778 @testset " usecache" begin
79+ # Leaf types:
7880 @test usecache ([1 ,2 ])
79- @test usecache (Ref (3 ))
80-
8181 @test ! usecache (4.0 )
82+ @test usecache (NoChild ([1 ,2 ]))
83+ @test ! usecache (NoChild ((3 ,4 )))
84+
85+ # Not leaf by default, but `exclude` can change that:
86+ @test usecache (Ref (3 ))
8287 @test ! usecache ((5 , 6.0 ))
8388 @test ! usecache ((a = 2pi , b = missing ))
8489
85- @test usecache (Bar ([1 ,2 ]))
86- @test ! usecache (Bar ((3 ,4 )))
90+ @test usecache ((x = [1 ,2 ,3 ], y = 4 ))
8791 end
8892end
8993
0 commit comments