Skip to content

Commit cac5ed0

Browse files
committed
add test_getsetall_laws
1 parent c590a3e commit cac5ed0

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

src/testing.jl

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,19 @@ function test_modify_law(f, lens, obj)
2222
obj_setfget = set(obj, lens, val)
2323
@test obj_modify == obj_setfget
2424
end
25+
26+
function test_getsetall_laws(optic, obj, vals1, vals2; cmp=(==))
27+
28+
# setall ⨟ getall
29+
vals = getall(obj, optic)
30+
@test cmp(setall(obj, optic, vals), obj)
31+
32+
# getall ⨟ setall
33+
obj1 = setall(obj, optic, vals1)
34+
@test cmp(collect(getall(obj1, optic)), collect(vals1))
35+
36+
# setall idempotent
37+
obj12 = setall(obj1, optic, vals2)
38+
obj2 = setall(obj12, optic, vals2)
39+
@test obj12 == obj2
40+
end

test/test_getsetall.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,16 @@ end
9696
@test_broken obj == @inferred setall(obj, @optic(_ |> Elements() |> Elements()), 1:6)
9797
@test_broken ([2, 3], 4:6, (7,)) == @inferred setall(obj, @optic(_ |> Elements() |> Elements() |> _ - 1), 1:6)
9898
end
99+
100+
@testset "getall/setall consistency" begin
101+
for (optic, obj, vals1, vals2) in [
102+
(Elements(), (1, "2"), (2, 3), (4, 5)),
103+
(Properties(), (a=1, b="2"), (2, 3), (4, 5)),
104+
(@optic(_.b |> Elements() |> Properties() |> _ * 3), (a=1, b=((c=3, d=4), (c=5, d=6))), 1:4, (-9, -12, -15, -18)),
105+
]
106+
Accessors.test_getsetall_laws(optic, obj, vals1, vals2)
107+
end
108+
end
99109

100110
end
101111

0 commit comments

Comments
 (0)