Skip to content

Commit 38a2feb

Browse files
committed
Better mapproperties test
1 parent 718e26c commit 38a2feb

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

test/test_optics.jl

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,20 @@ import ConstructionBase
1515
end
1616
res = @inferred mapproperties(x->2x, S(1, 2.0))
1717
@test res === S(2, 4.0)
18+
19+
# overloading
20+
struct AB
21+
a::Int
22+
b::Int
23+
_checksum::UInt
24+
AB(a,b) = new(a,b,hash(a,hash(b)))
25+
end
26+
27+
ConstructionBase.getproperties(o::AB) = (a=o.a, b=o.b)
28+
ConstructionBase.setproperties(o::AB, patch::NamedTuple) = AB(patch.a, patch.b)
29+
ab = AB(1,2)
30+
ab2 = @inferred mapproperties(x -> 2x, ab)
31+
@test ab2 === AB(2,4)
1832
end
1933

2034
@testset "Properties" begin
@@ -29,20 +43,6 @@ end
2943
pt = Point(1f0, 2e0, 3)
3044
pt2 = @inferred modify(x->2x, pt, Properties())
3145
@test pt2 === Point(2f0, 4e0, 6)
32-
33-
# overloading
34-
struct AB
35-
a::Int
36-
b::Int
37-
_checksum::Int
38-
AB(a,b) = new(a,b,a+b)
39-
end
40-
41-
ConstructionBase.getproperties(o::AB) = (a=o.a, b=o.b)
42-
ConstructionBase.setproperties(o::AB, patch::NamedTuple) = AB(patch.a, patch.b)
43-
ab = AB(1,2)
44-
ab2 = @inferred mapproperties(x -> 2x, ab)
45-
@test ab2 === AB(2,4)
4646
end
4747

4848
@testset "Elements" begin

0 commit comments

Comments
 (0)