@@ -4,6 +4,10 @@ using Accessors
4
4
using StaticNumbers
5
5
using StaticArrays
6
6
7
+ @static if VERSION < v " 1.9-"
8
+ # for StaticArrays constructorof: ConstructionBase itself only supports it through 1.9 extension
9
+ using ConstructionBaseExtras
10
+ end
7
11
8
12
if VERSION >= v " 1.6" # for ComposedFunction
9
13
@testset " getall" begin
@@ -37,17 +41,16 @@ if VERSION >= v"1.6" # for ComposedFunction
37
41
@test (2 , 5 , 10 , 17 , 26 , 37 ) === @inferred getall (obj, @optic _ |> _[:] |> Elements () |> Elements () |> _[:] |> Elements () |> Elements () |> _[1 ]^ 2 + 1 |> only)
38
42
39
43
# trickier types for Elements():
40
- obj = (a= (" ab" , " c" ), b= ([1 2 ; 3 4 ],), c= (SVector (1 ), SVector (2 , 3 )))
44
+ obj = (a= (" ab" , " c" ), b= ([1 2 ; 3 4 ],), c= (SVector (1. ), SVector (2 , 3 )))
41
45
@test [' b' , ' c' , ' d' ] == @inferred getall (obj, @optic _. a |> Elements () |> Elements () |> _ + 1 )
42
46
@test [2 , 4 , 3 , 5 ] == @inferred getall (obj, @optic _. b |> Elements () |> Elements () |> _ + 1 )
43
- @test SVector (1 , 2 , 3 ) === @inferred getall (obj, @optic _. c |> Elements () |> Elements ())
44
- @test [2 , 3 , 4 ] == @inferred getall (obj, @optic _. c |> Elements () |> Elements () |> _ + 1 )
45
- @test_broken SVector (2 , 3 , 4 ) === getall (obj, @optic _. c |> Elements () |> Elements () |> _ + 1 )
47
+ @test (1. , 2 , 3 ) === @inferred getall (obj, @optic _. c |> Elements () |> Elements ())
48
+ @test (2. , 3 , 4 ) === @inferred getall (obj, @optic _. c |> Elements () |> Elements () |> _ + 1 )
46
49
47
50
# composition order should not matter:
48
- @test [ 2 , 3 , 4 ] == @inferred getall (obj, (@optic (_ + 1 ) ∘ Elements () ∘ Elements ()) ∘ @optic (_. c))
49
- @test [ 2 , 3 , 4 ] == @inferred getall (obj, (@optic (_ + 1 ) ∘ Elements ()) ∘ (Elements () ∘ @optic (_. c)))
50
- @test [ 2 , 3 , 4 ] == @inferred getall (obj, @optic (_ + 1 ) ∘ (Elements () ∘ Elements () ∘ @optic (_. c)))
51
+ @test ( 2. , 3 , 4 ) = == @inferred getall (obj, (@optic (_ + 1 ) ∘ Elements () ∘ Elements ()) ∘ @optic (_. c))
52
+ @test ( 2. , 3 , 4 ) = == @inferred getall (obj, (@optic (_ + 1 ) ∘ Elements ()) ∘ (Elements () ∘ @optic (_. c)))
53
+ @test ( 2. , 3 , 4 ) = == @inferred getall (obj, @optic (_ + 1 ) ∘ (Elements () ∘ Elements () ∘ @optic (_. c)))
51
54
52
55
obj = ()
53
56
@test () === @inferred getall (obj, @optic _ |> Elements () |> _ + 1 )
114
117
@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 ])
115
118
@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 ])
116
119
120
+ # SVectors and nested Elements:
121
+ obj = (c= (SVector (1. ), SVector (2 , 3 )),)
122
+ @test setall (obj. c[1 ], Elements (), (5 , 6 )) === SVector (5 , 6 )
123
+ @test setall (obj. c[1 ], Elements (), (5 ,)) === SVector (5 )
124
+ @test setall (obj. c[1 ], Elements (), [5 , 6 ]) === SVector (5 , 6 )
125
+ @test setall (obj. c[1 ], Elements (), [5 ]) === SVector (5 )
126
+ @testset for o in (
127
+ (@optic _. c |> Elements () |> Elements ()),
128
+ (@optic _. c |> Elements () |> Elements () |> _ + 1 ),
129
+ )
130
+ @test setall (obj, o, getall (obj, o)) === obj
131
+ @test setall (obj, o, collect (getall (obj, o))) === obj
132
+ end
133
+
117
134
obj = ([1 , 2 ], 3 : 5 , (6 ,))
118
135
@test obj == setall (obj, @optic (_ |> Elements () |> Elements ()), 1 : 6 )
119
136
@test ([2 , 3 ], 4 : 6 , (7 ,)) == setall (obj, @optic (_ |> Elements () |> Elements () |> _ - 1 ), 1 : 6 )
0 commit comments