Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ authors = ["Takafumi Arakaki <[email protected]>", "Jan Weidner <[email protected]
version = "0.1.37"

[deps]
ArgCheck = "dce04be8-c92d-5529-be00-80e4d2c0e197"
CompositionsBase = "a33af91c-f02d-484b-be07-31d278c5ca2b"
ConstructionBase = "187b0558-2788-49d3-abe0-74a17ed4e7c9"
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
Expand All @@ -12,7 +13,6 @@ LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
MacroTools = "1914dd2f-81c6-5fcd-8719-6d5c9610ff09"
Markdown = "d6f4376e-aef5-505a-96c1-9c027394607a"
Requires = "ae029012-a4dd-5104-9daa-d747884805df"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[weakdeps]
AxisKeys = "94b1ba4f-4ee9-5380-92f1-94cde586c3c5"
Expand All @@ -30,6 +30,7 @@ AccessorsStructArraysExt = "StructArrays"
AccessorsUnitfulExt = "Unitful"

[compat]
ArgCheck = "2"
AxisKeys = "0.2"
CompositionsBase = "0.1"
ConstructionBase = "1.5"
Expand All @@ -42,7 +43,6 @@ Markdown = "1"
Requires = "0.5, 1.0"
StaticArrays = "1"
StructArrays = "0.6"
Test = "1"
Unitful = "1"
julia = "1.6"

Expand Down
57 changes: 0 additions & 57 deletions ext/AccessorsTestExt.jl

This file was deleted.

1 change: 0 additions & 1 deletion src/Accessors.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ include("testing.jl")
# always included for now
include("../ext/AccessorsDatesExt.jl")
include("../ext/AccessorsLinearAlgebraExt.jl")
include("../ext/AccessorsTestExt.jl")

function __init__()
@static if !isdefined(Base, :get_extension)
Expand Down
58 changes: 52 additions & 6 deletions src/testing.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,52 @@
# placeholders only
# actual definitions in ext/AccessorsTestExt.jl
function test_getset_laws end
function test_modify_law end
function test_getsetall_laws end
function test_insertdelete_laws end
using ArgCheck: @argcheck

function test_getset_laws(lens, obj, val1, val2; cmp=(==))
# set ⨟ get
val = lens(obj)
@argcheck cmp(set(obj, lens, val), obj)

# get ⨟ set
obj1 = set(obj, lens, val1)
@argcheck cmp(lens(obj1), val1)

# set idempotent
obj12 = set(obj1, lens, val2)
obj2 = set(obj12, lens, val2)
@argcheck cmp(obj12, obj2)

test_modify_law(identity, lens, obj; cmp)
end

function test_modify_law(f, lens, obj; cmp=(==))
obj_modify = modify(f, obj, lens)
old_vals = getall(obj, lens)
vals = map(f, old_vals)
obj_setfget = setall(obj, lens, vals)
@argcheck cmp(obj_modify, obj_setfget)
end

function test_insertdelete_laws(lens, obj, val; cmp=(==))
obj1 = insert(obj, lens, val)
@argcheck cmp(lens(obj1), val)
obj2 = set(obj1, lens, val)
@argcheck cmp(obj1, obj2)
obj3 = delete(obj1, lens)
@argcheck cmp(obj, obj3)
end

function test_getsetall_laws(optic, obj, vals1, vals2; cmp=(==))
# setall ⨟ getall
vals = getall(obj, optic)
@argcheck cmp(setall(obj, optic, vals), obj)

# getall ⨟ setall
obj1 = setall(obj, optic, vals1)
@argcheck cmp(collect(getall(obj1, optic)), collect(vals1))

# setall idempotent
obj12 = setall(obj1, optic, vals2)
obj2 = setall(obj12, optic, vals2)
@argcheck obj12 == obj2

test_modify_law(identity, optic, obj; cmp)
end