diff --git a/Project.toml b/Project.toml index 76fb1dfd..38500aa6 100644 --- a/Project.toml +++ b/Project.toml @@ -16,6 +16,7 @@ Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" [weakdeps] AxisKeys = "94b1ba4f-4ee9-5380-92f1-94cde586c3c5" IntervalSets = "8197267c-284f-5f27-9208-e0e47529a953" +Requires = "ae029012-a4dd-5104-9daa-d747884805df" StaticArrays = "90137ffa-7385-5640-81b9-e52037218182" StructArrays = "09ab397b-f2b6-538f-b94a-2f83cf4a842a" diff --git a/docs/Project.toml b/docs/Project.toml index dad41733..88b2acb3 100644 --- a/docs/Project.toml +++ b/docs/Project.toml @@ -2,3 +2,8 @@ Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4" Literate = "98b081ad-f1c9-55d3-8b20-4c87d4299306" StaticArrays = "90137ffa-7385-5640-81b9-e52037218182" + +[compat] +Documenter = "0.27" +Literate = "2" +StaticArrays = "1" diff --git a/ext/AccessorsStructArraysExt.jl b/ext/AccessorsStructArraysExt.jl index c9817542..95a3bf8e 100644 --- a/ext/AccessorsStructArraysExt.jl +++ b/ext/AccessorsStructArraysExt.jl @@ -3,11 +3,11 @@ using Accessors using StructArrays # set: all eltypes -Accessors.set(x::StructArray, o::Accessors.PropertyLens, v) = set(x, o ∘ StructArrays.components, v) +Accessors.set(x::StructArray, o::PropertyLens, v) = set(x, o ∘ StructArrays.components, v) # insert, delete: only (named)tuples -Accessors.insert(x::StructArray{<:Union{Tuple, NamedTuple}}, o::Accessors.PropertyLens, v) = insert(x, o ∘ StructArrays.components, v) -Accessors.delete(x::StructArray{<:Union{Tuple, NamedTuple}}, o::Accessors.PropertyLens) = delete(x, o ∘ StructArrays.components) +Accessors.insert(x::StructArray{<:Union{Tuple, NamedTuple}}, o::PropertyLens, v) = insert(x, o ∘ StructArrays.components, v) +Accessors.delete(x::StructArray{<:Union{Tuple, NamedTuple}}, o::PropertyLens) = delete(x, o ∘ StructArrays.components) # (named)tuple eltypes: only component arrays themselves are needed in the constructor # can change component number/names diff --git a/test/Project.toml b/test/Project.toml index 4fbe43f9..7f6291ca 100644 --- a/test/Project.toml +++ b/test/Project.toml @@ -20,9 +20,9 @@ Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d" [compat] Aqua = "0.6" AxisKeys = "0.2" +BenchmarkTools = "1.3" ConstructionBase = "1.5" ConstructionBaseExtras = "0.1" -BenchmarkTools = "1.3" IntervalSets = "0.7" InverseFunctions = "0.1.5" MacroTools = "0.4.4, 0.5" diff --git a/test/runtests.jl b/test/runtests.jl index 2c5aa7ab..88071e24 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -2,10 +2,7 @@ module TestAccessors import PerformanceTestTools import Accessors import Aqua -Aqua.test_all(Accessors, - stale_deps=false, - project_toml_formatting=false, -) +VERSION ≥ v"1.9-" && Aqua.test_all(Accessors) PerformanceTestTools.@include("perf.jl") include("test_examples.jl") diff --git a/test/test_core.jl b/test/test_core.jl index ba2246eb..7a64324e 100644 --- a/test/test_core.jl +++ b/test/test_core.jl @@ -222,21 +222,21 @@ end @testset "IndexLens" begin l = @optic _[] - @test l isa Accessors.IndexLens + @test l isa IndexLens x = randn() obj = Ref(x) @test l(obj) == x l = @optic _[][] - @test l.outer isa Accessors.IndexLens - @test l.inner isa Accessors.IndexLens + @test l.outer isa IndexLens + @test l.inner isa IndexLens inner = Ref(x) obj = Base.RefValue{typeof(inner)}(inner) @test l(obj) == x obj = (1,2,3) l = @optic _[1] - @test l isa Accessors.IndexLens + @test l isa IndexLens @test l(obj) == 1 @test set(obj, l, 6) == (6,2,3) @@ -257,7 +257,7 @@ end nt = (a=1, b=2, c=3) l = @optic _[(:a, :c)] - @test l isa Accessors.IndexLens + @test l isa IndexLens VERSION >= v"1.7" && @test l(nt) === (a=1, c=3) @test set(nt, l, ('1', '2')) === (a='1', b=2, c='2') @test set(nt, l, (c='2', a='1')) === (a='1', b=2, c='2') @@ -588,14 +588,14 @@ end @test strip(string(@doc(my_x))) == "Documentation for my_x" @test (@set my_x(s) = 456) === MyStruct(456) @test (@set +s = 456) === MyStruct((a=5-456,)) - Accessors.test_getset_laws(my_x, s, 456, "1") - Accessors.test_getset_laws(+, s, 456, 1.0) + test_getset_laws(my_x, s, 456, "1") + test_getset_laws(+, s, 456, 1.0) s = MyStruct((1, 2.0)) - Accessors.test_getset_laws(Int, s, 1, 2) - Accessors.test_getset_laws(Float64, s, 1., 2.) + test_getset_laws(Int, s, 1, 2) + test_getset_laws(Float64, s, 1., 2.) - Accessors.test_getset_laws(MyStruct(2), MyStruct(1), 1, 2) + test_getset_laws(MyStruct(2), MyStruct(1), 1, 2) end end diff --git a/test/test_extensions.jl b/test/test_extensions.jl index 5126a69f..3708a4d6 100644 --- a/test/test_extensions.jl +++ b/test/test_extensions.jl @@ -1,6 +1,7 @@ module TestExtensions using Test using Accessors +using Accessors: test_getset_laws using AxisKeys using IntervalSets using StaticArrays, StaticNumbers @@ -54,16 +55,16 @@ VERSION >= v"1.9-" && @testset "IntervalSets" begin @test Interval{:open, :closed}(-2, 5) === @set leftendpoint(int) = -2 @test Interval{:open, :closed}(1, 2) === @set rightendpoint(int) = 2 @test Interval{:closed, :closed}(1, 5) === @set first(closedendpoints(int)) = true - Accessors.test_getset_laws(endpoints, int, (10, 11), (-3, 2)) - Accessors.test_getset_laws(closedendpoints, int, (true, true), (true, false)) - Accessors.test_getset_laws(leftendpoint, int, 2, 3) - Accessors.test_getset_laws(rightendpoint, int, 2, 3) + test_getset_laws(endpoints, int, (10, 11), (-3, 2)) + test_getset_laws(closedendpoints, int, (true, true), (true, false)) + test_getset_laws(leftendpoint, int, 2, 3) + test_getset_laws(rightendpoint, int, 2, 3) @test 1 === @set 2 |> mod(_, 0..3) = 1 @test 31 === @set 32 |> mod(_, 0..3) = 1 @test 2 === @set 2 |> mod(_, 20..23) = 20 @test 33 === @set 32 |> mod(_, 20..23) = 21 - Accessors.test_getset_laws(@optic(mod(_, 5..8)), 20, 6, 5) + test_getset_laws(@optic(mod(_, 5..8)), 20, 6, 5) end @testset "StaticArrays" begin diff --git a/test/test_functionlenses.jl b/test/test_functionlenses.jl index 1e33ab95..ccfd8e29 100644 --- a/test/test_functionlenses.jl +++ b/test/test_functionlenses.jl @@ -44,8 +44,8 @@ end @test set("абв", @optic(first(_, 2)), "xж") == "xжв" @test_throws DimensionMismatch set("абв", @optic(first(_, 2)), "x") - Accessors.test_getset_laws(first, obj, 123, "456") - Accessors.test_getset_laws(first, "abc", 'x', ' ') + test_getset_laws(first, obj, 123, "456") + test_getset_laws(first, "abc", 'x', ' ') end @testset "last" begin @@ -65,8 +65,8 @@ end @test set("абв", @optic(last(_, 2)), "xж") == "аxж" @test_throws DimensionMismatch set("абв", @optic(last(_, 2)), "x") - Accessors.test_getset_laws(last, obj, 123, "456") - Accessors.test_getset_laws(last, "abc", 'x', ' ') + test_getset_laws(last, obj, 123, "456") + test_getset_laws(last, "abc", 'x', ' ') end @testset "front, tail" begin @@ -74,8 +74,8 @@ end @test (@set Base.front(obj) = ("5", 6)) === ("5", 6, '3') @test set(obj, Base.tail, ("5", 6)) === (1, "5", 6) - Accessors.test_getset_laws(Base.front, obj, (), ("456", 7)) - Accessors.test_getset_laws(Base.tail, obj, (123,), ("456", 7)) + test_getset_laws(Base.front, obj, (), ("456", 7)) + test_getset_laws(Base.tail, obj, (123,), ("456", 7)) end @testset "change types" begin @@ -232,8 +232,8 @@ end @test @inferred(modify(x -> -2x, "3", @optic parse(Int, _))) == "-6" @test_throws ErrorException modify(log10, "100", @optic parse(Int, _)) @test modify(log10, "100", @optic parse(Float64, _)) == "2.0" - Accessors.test_getset_laws(@optic(parse(Int, _)), "3", -10, 123) - Accessors.test_getset_laws(@optic(parse(Float64, _)), "3.0", -10., 123.) + test_getset_laws(@optic(parse(Int, _)), "3", -10, 123) + test_getset_laws(@optic(parse(Float64, _)), "3.0", -10., 123.) end # setting inverse @@ -266,15 +266,15 @@ end l = @optic DateTime(_, dateformat"yyyy_mm_dd") @test @inferred(set("2020_03_04", month ∘ l, 10)) == "2020_10_04" - Accessors.test_getset_laws(month ∘ l, "2020_03_04", 10, 11) + test_getset_laws(month ∘ l, "2020_03_04", 10, 11) l = @optic Date(_, dateformat"yyyy/mm/dd") @test set("2020/03/04", day ∘ l, 10) == "2020/03/10" - Accessors.test_getset_laws(day ∘ l, "2020/03/04", 10, 11) + test_getset_laws(day ∘ l, "2020/03/04", 10, 11) @test_throws ArgumentError set("2020_03_04", month ∘ l, 10) l = @optic Time(_, dateformat"HH:MM") - Accessors.test_getset_laws(hour ∘ l, "12:34", 10, 11) + test_getset_laws(hour ∘ l, "12:34", 10, 11) end @testset "strings" begin diff --git a/test/test_getsetall.jl b/test/test_getsetall.jl index 5314d9ca..6518d122 100644 --- a/test/test_getsetall.jl +++ b/test/test_getsetall.jl @@ -1,6 +1,7 @@ module TestGetSetAll using Test using Accessors +using Accessors: test_getsetall_laws using StaticNumbers using StaticArrays @@ -145,7 +146,7 @@ end (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)), ] - Accessors.test_getsetall_laws(optic, obj, vals1, vals2) + test_getsetall_laws(optic, obj, vals1, vals2) end end