ConstructionBase.jl icon indicating copy to clipboard operation
ConstructionBase.jl copied to clipboard

add testing helpers

Open aplavin opened this issue 1 year ago • 0 comments

Some helpers to test constructof laws would be nice, similar to what we have in Accessors (https://github.com/JuliaObjects/Accessors.jl/blob/master/ext/AccessorsTestExt.jl). Basically,

function test_constructorof_laws(obj, args; cmp=(==))
    ctor = constructorof(typeof(obj))
    reconstructed = ctor(getfields(obj)...)
    @test cmp(obj, reconstructed)
    @test typeof(obj) == typeof(reconstructed)
    @test getfields(ctor(args...)) == args
end

Best to put into a Test extension, so this should wait until https://github.com/JuliaObjects/ConstructionBase.jl/pull/86 -related issues get resolved.

aplavin avatar Jul 16 '24 16:07 aplavin