Skip to content

Commit

Permalink
test different eltypes
Browse files Browse the repository at this point in the history
  • Loading branch information
aplavin committed May 16, 2023
1 parent f2e8e19 commit 1170de3
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions test/test_getsetall.jl
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,16 @@ if VERSION >= v"1.6" # for ComposedFunction
@test (2, 5, 10, 17, 26, 37) === @inferred getall(obj, @optic _ |> _[:] |> Elements() |> Elements() |> _[:] |> Elements() |> Elements() |> _[1]^2 + 1 |> only)

# trickier types for Elements():
obj = (a=("ab", "c"), b=([1 2; 3 4],), c=(SVector(1), SVector(2, 3)))
obj = (a=("ab", "c"), b=([1 2; 3 4],), c=(SVector(1.), SVector(2, 3)))
@test ['b', 'c', 'd'] == @inferred getall(obj, @optic _.a |> Elements() |> Elements() |> _ + 1)
@test [2, 4, 3, 5] == @inferred getall(obj, @optic _.b |> Elements() |> Elements() |> _ + 1)
@test (1, 2, 3) === @inferred getall(obj, @optic _.c |> Elements() |> Elements())
@test (2, 3, 4) === @inferred getall(obj, @optic _.c |> Elements() |> Elements() |> _ + 1)
@test (1., 2, 3) === @inferred getall(obj, @optic _.c |> Elements() |> Elements())
@test (2., 3, 4) === @inferred getall(obj, @optic _.c |> Elements() |> Elements() |> _ + 1)

# composition order should not matter:
@test (2, 3, 4) === @inferred getall(obj, (@optic(_ + 1) Elements() Elements()) @optic(_.c))
@test (2, 3, 4) === @inferred getall(obj, (@optic(_ + 1) Elements()) (Elements() @optic(_.c)))
@test (2, 3, 4) === @inferred getall(obj, @optic(_ + 1) (Elements() Elements() @optic(_.c)))
@test (2., 3, 4) === @inferred getall(obj, (@optic(_ + 1) Elements() Elements()) @optic(_.c))
@test (2., 3, 4) === @inferred getall(obj, (@optic(_ + 1) Elements()) (Elements() @optic(_.c)))
@test (2., 3, 4) === @inferred getall(obj, @optic(_ + 1) (Elements() Elements() @optic(_.c)))

obj = ()
@test () === @inferred getall(obj, @optic _ |> Elements() |> _ + 1)
Expand Down Expand Up @@ -118,7 +118,7 @@ end
@test (a=1, b=((c=-3., d=-4.), (c=-5., d=-6.))) === @inferred setall(obj, @optic(_ * 3) (Properties() Elements() @optic(_.b)), [-9, -12, -15, -18])

# SVectors and nested Elements:
obj = (c=(SVector(1), SVector(2, 3)),)
obj = (c=(SVector(1.), SVector(2, 3)),)
@test setall(obj.c[1], Elements(), (5, 6)) === SVector(5, 6)
@test setall(obj.c[1], Elements(), (5,)) === SVector(5)
@test setall(obj.c[1], Elements(), [5, 6]) === SVector(5, 6)
Expand Down

0 comments on commit 1170de3

Please sign in to comment.