@@ -14,6 +14,7 @@ struct NoChildren2; x; y; end
14
14
15
15
struct NoChild{T}; x:: T ; end
16
16
17
+
17
18
# ##
18
19
# ## Basic functionality
19
20
# ##
56
57
m1p = fmapstructure (identity, m1; prune = nothing )
57
58
@test m1p == (x = [1 , 2 , 3 ], y = (x = [1 , 2 , 3 ], y = (x = nothing , y = [1 , 2 , 3 ])))
58
59
59
- # A non- leaf node can also be repeated :
60
+ # The cache applies only to leaf nodes, so that "4" is not shared :
60
61
m2 = Foo (Foo (shared, 4 ), Foo (shared, 4 ))
61
62
@test m2. x === m2. y
62
63
m2f = fmap (float, m2)
63
64
@test m2f. x. x === m2f. y. x
64
65
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 ))
66
67
67
68
# Repeated isbits types should not automatically be regarded as shared:
68
69
m3 = Foo (Foo (shared, 1 : 3 ), Foo (1 : 3 , shared))
75
76
@test_skip 0 == @allocated fmap (float, (x= 1 , y= (2 , 3 ), z= 4 : 5 ))
76
77
77
78
@testset " usecache" begin
79
+ # Leaf types:
78
80
@test usecache ([1 ,2 ])
79
- @test usecache (Ref (3 ))
80
-
81
81
@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 ))
82
87
@test ! usecache ((5 , 6.0 ))
83
88
@test ! usecache ((a = 2pi , b = missing ))
84
89
85
- @test usecache (Bar ([1 ,2 ]))
86
- @test ! usecache (Bar ((3 ,4 )))
90
+ @test usecache ((x = [1 ,2 ,3 ], y = 4 ))
87
91
end
88
92
end
89
93
0 commit comments