Skip to content

Commit

Permalink
Merge pull request #7 from JuliaObjects/compat
Browse files Browse the repository at this point in the history
compat
  • Loading branch information
jw3126 authored Oct 3, 2020
2 parents ffaab29 + 3708b8e commit 4e83983
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 45 deletions.
7 changes: 4 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ jobs:
fail-fast: false
matrix:
version:
- 1 # Supporting < 1.5 is a bit awkward since \bbsemi is missing
- 1.3 # Supporting < 1.3 is awkward since we can't do var"\bbsemi"
- 1
- 'nightly'
os:
- ubuntu-latest
- macOS-latest
# - macOS-latest
- windows-latest
arch:
- x64
Expand Down Expand Up @@ -43,7 +44,7 @@ jobs:
- uses: actions/checkout@v2
- uses: julia-actions/setup-julia@v1
with:
version: 'nightly' # TODO stable
version: 1
- run: |
julia --project=docs -e '
using Pkg
Expand Down
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ ConstructionBase = "0.1, 1.0"
MacroTools = "0.4.4, 0.5"
Requires = "0.5, 1.0"
StaticNumbers = "0.3"
julia = "1.5"
julia = "1.3"

[extras]
BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf"
Expand Down
43 changes: 20 additions & 23 deletions src/optics.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export @optic
export set, modify
export ,
export , opcompose, var"⨟"
export Elements, Recursive, If, Properties
export setproperties
export constructorof
Expand Down Expand Up @@ -66,13 +66,26 @@ julia> lens(obj)
1
```
"""
opcompose

const BASE_COMPOSED_FUNCTION_HAS_SHOW = VERSION >= v"1.6.0-DEV.85"
const BASE_COMPOSED_FUNCTION_IS_PUBLIC = VERSION >= v"1.6.0-DEV.1037"
if !BASE_COMPOSED_FUNCTION_IS_PUBLIC
using Compat: ComposedFunction
end
if !BASE_COMPOSED_FUNCTION_HAS_SHOW
function show_composed_function(io::IO, c::ComposedFunction)
show(io, c.outer)
print(io, "")
show(io, c.inner)
end
function Base.show(io::IO, c::ComposedFunction)
show_composed_function(io, c)
end
function Base.show(io::IO, ::MIME"text/plain", c::ComposedFunction)
show_composed_function(io, c)
end
end

const ComposedOptic{Outer, Inner} = ComposedFunction{Outer, Inner}
outertype(::Type{ComposedOptic{Outer, Inner}}) where {Outer, Inner} = Outer
Expand Down Expand Up @@ -158,23 +171,13 @@ Access all elements of a collection that implements `map`.
```jldoctest
julia> using Accessors
julia> obj = [1,2,3]
3-element Vector{Int64}:
1
2
3
julia> obj = (1,2,3);
julia> set(obj, Elements(), 0)
3-element Vector{Int64}:
0
0
0
(0, 0, 0)
julia> modify(x -> 2x, obj, Elements())
3-element Vector{Int64}:
2
4
6
(2, 4, 6)
```
$EXPERIMENTAL
"""
Expand All @@ -193,16 +196,10 @@ Restric access to locations for which `modify_condition` holds.
```jldoctest
julia> using Accessors
julia> obj = 1:6;
julia> obj = (1,2,3,4,5,6);
julia> @set obj |> Elements() |> If(iseven) *= 10
6-element Vector{Int64}:
1
20
3
40
5
60
(1, 20, 3, 40, 5, 60)
```
$EXPERIMENTAL
Expand Down
4 changes: 2 additions & 2 deletions test/perf.jl
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ is_fast_composition_order(lens::ComposedOptic{<:ComposedOptic, <:ComposedOptic})
@assert is_fast_composition_order((first, last, eltype))
@assert is_fast_composition_order((first last) eltype)
@assert !is_fast_composition_order(first (last eltype))
@test is_fast_composition_order((eltype, last, first))
@test_broken is_fast_composition_order(first last eltype)
@test is_fast_composition_order(opcompose(eltype, last, first))
# @test_broken is_fast_composition_order(first ⨟ last ⨟ eltype)
@test is_fast_composition_order(first last eltype)
@test is_fast_composition_order(@optic _)
@test is_fast_composition_order(@optic _ |> first |> last |> eltype)
Expand Down
11 changes: 6 additions & 5 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
module TestAccessors
import PerformanceTestTools
import Accessors

using Documenter: doctest
if VERSION >= v"1.5" # ⨟ needs to be defined
doctest(Accessors)
else
@info "Skipping doctests, on old VERSION = $VERSION"
end

include("test_optics.jl")
include("test_examples.jl")
Expand All @@ -13,10 +19,5 @@ include("test_core.jl")
include("test_functionlenses.jl")
PerformanceTestTools.@include("perf.jl")

if Accessors.BASE_COMPOSED_FUNCTION_HAS_SHOW
doctest(Accessors)
else
@info "Skipping doctests, on old VERSION = $VERSION"
end

end # module
23 changes: 12 additions & 11 deletions test/test_core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -349,9 +349,10 @@ end
@testset "|>" begin
lbc = @optic _.b.c
@test @optic(_ |> lbc) === lbc
@test @optic(_.a |> lbc) === @optic(_.a) lbc
@test @optic((_.a |> lbc).d) === (@optic(_.a), lbc , @optic(_.d))
@test @optic(_.a |> lbc |> (@optic _[1]) |> lbc) === (@optic(_.a), lbc, @optic(_[1]), lbc)
@test @optic(_.a |> lbc) === opcompose(@optic(_.a), lbc)
@test @optic((_.a |> lbc).d) === opcompose(@optic(_.a), lbc , @optic(_.d))
@test @optic(_.a |> lbc |> (@optic _[1]) |> lbc) ===
opcompose(@optic(_.a), lbc, @optic(_[1]), lbc)

@test @optic(_ |> _) === identity
@test (@optic _ |> _[1]) === (@optic _[1])
Expand All @@ -377,18 +378,18 @@ else
@test occursin("I define text/plain.", sprint(show, "text/plain", lens))
end
@testset for lens in [
(@optic _.a) LensIfTextPlain()
LensIfTextPlain() (@optic _.b)
(@optic _.a) LensIfTextPlain() (@optic _.b)
@optic _.a |> LensIfTextPlain()
@optic _ |> LensIfTextPlain() |> _.b
@optic _.a |> LensIfTextPlain() |> @optic _.b
]
@test_broken occursin("I define text/plain.", sprint(show, "text/plain", lens))
end

@testset for lens in [
UserDefinedLens()
(@optic _.a) UserDefinedLens()
UserDefinedLens() (@optic _.b)
(@optic _.a) UserDefinedLens() (@optic _.b)
@optic _.a |> UserDefinedLens()
@optic _ |> UserDefinedLens() |> _.b
@optic _.a |> UserDefinedLens() |> _.b
]
@test sprint(show, lens) == sprint(show, "text/plain", lens)
end
Expand All @@ -411,8 +412,8 @@ else
@optic _ |> UserDefinedLens()
@optic UserDefinedLens()(_)
@optic _ |> ((x -> x)(first))
(@optic _.a) UserDefinedLens()
UserDefinedLens() (@optic _.b)
@optic _.a |> UserDefinedLens()
@optic _ |> UserDefinedLens() |> _.b
(@optic _.a) UserDefinedLens() (@optic _.b)
(@optic _.a) LensIfTextPlain() (@optic _.b)
]
Expand Down

0 comments on commit 4e83983

Please sign in to comment.