diff --git a/ext/AccessorsTestExt.jl b/ext/AccessorsTestExt.jl index ac0e06fe..c6edc8d7 100644 --- a/ext/AccessorsTestExt.jl +++ b/ext/AccessorsTestExt.jl @@ -18,12 +18,12 @@ function Accessors.test_getset_laws(lens, obj, val1, val2; cmp=(==)) @test cmp(obj12, obj2) end -function Accessors.test_modify_law(f, lens, obj) +function Accessors.test_modify_law(f, lens, obj; cmp=(==)) obj_modify = modify(f, obj, lens) - old_val = lens(obj) - val = f(old_val) - obj_setfget = set(obj, lens, val) - @test obj_modify == obj_setfget + old_vals = getall(obj, lens) + vals = map(f, old_vals) + setall(obj, lens, vals) + @test cmp(obj_modify, obj_setfget) end function Accessors.test_insertdelete_laws(lens, obj, val; cmp=(==)) diff --git a/test/test_getsetall.jl b/test/test_getsetall.jl index 5424e668..aeef5931 100644 --- a/test/test_getsetall.jl +++ b/test/test_getsetall.jl @@ -1,7 +1,7 @@ module TestGetSetAll using Test using Accessors -using Accessors: test_getsetall_laws +using Accessors: test_getsetall_laws, test_modify_law using StaticNumbers using StaticArrays @@ -155,14 +155,15 @@ end @test_broken ([1, 2], [3.0, 4.0, 5.0], ("6",)) == @inferred setall(obj, @optic(_ |> Elements() |> Elements()), (1, 2, 3., 4., 5., "6")) end -@testset "getall/setall consistency" begin +@testset "getall-setall laws" begin for (optic, obj, vals1, vals2) in [ - (Elements(), (1, "2"), (2, 3), (4, 5)), - (Properties(), (a=1, b="2"), (2, 3), (4, 5)), + (Elements(), (1, false), (2, 3), (4, 5)), + (Properties(), (a=1, b=false), (2, 3), (4, 5)), (If(x -> x isa Number) ∘ Properties(), (a=1, b="2"), (2,), (4,)), (@optic(_.b |> Elements() |> Properties() |> _ * 3), (a=1, b=((c=3, d=4), (c=5, d=6))), 1:4, (-9, -12, -15, -18)), ] test_getsetall_laws(optic, obj, vals1, vals2) + test_modify_law(x -> x + 1, optic, obj) end end