Skip to content

Commit 6a2f79c

Browse files
rebase
1 parent 84f5253 commit 6a2f79c

File tree

4 files changed

+19
-22
lines changed

4 files changed

+19
-22
lines changed

src/Functors.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module Functors
22

33
using ConstructionBase: constructorof
4-
export @functor, @flexiblefunctor, fmap, fmapstructure, fcollect
4+
export @functor, @flexiblefunctor, fmap, fmapstructure, fcollect, @leaf
55

66
include("functor.jl")
77
include("walks.jl")

test/basics.jl

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,25 @@ struct Bar{T}; x::T; end
88
struct 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)
2831
end
2932

@@ -97,8 +100,8 @@ end
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
@@ -181,7 +184,7 @@ end
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])
@@ -238,9 +241,7 @@ end
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)
244245
end
245246

246247
@testset "old test update.jl" begin
@@ -303,11 +304,7 @@ end
303304
end
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

test/flexiblefunctors.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ struct FFoo
6161
@test all(fcollect(m4, exclude = x -> x isa Array) .=== [m4, m3])
6262
@test all(fcollect(m4, exclude = x -> x isa FFoo) .=== [m4])
6363

64-
m0 = NoChildren2(:a, :b)
64+
m0 = NoChild2(:a, :b)
6565
m1 = [1, 2, 3]
6666
m2 = FBar(m1, ())
6767
m3 = FFoo(m2, m0, (:x, :y,))

test/runtests.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ using StaticArrays
99
include("base.jl")
1010
include("flexiblefunctors.jl")
1111

12-
# if VERSION < v"1.6" # || VERSION > v"1.7-"
12+
# if VERSION >= v"1.7"
1313
# @warn "skipping doctests, on Julia $VERSION"
1414
# else
1515
# using Documenter

0 commit comments

Comments
 (0)