|
80 | 80 | @test @varname(A[1].b[i]) == @varname(A[1].b[1:10])
|
81 | 81 | @test @varname(A[j]) == @varname(A[2:2:5])
|
82 | 82 |
|
83 |
| - @test @varname(A[:, 1][1 + 1]) == @varname(A[:, 1][2]) |
| 83 | + @test @varname(A[:, 1][1+1]) == @varname(A[:, 1][2]) |
84 | 84 | @test(@varname(A[:, 1][2]) == VarName{:A}(@o(_[:, 1]) ⨟ @o(_[2])))
|
85 | 85 |
|
86 | 86 | # concretization
|
|
91 | 91 | @test test_equal(@varname(y[:], true), @varname(y[1:100]))
|
92 | 92 | @test test_equal(@varname(y[:, begin], true), @varname(y[1:10, 1]))
|
93 | 93 | @test getoptic(AbstractPPL.concretize(@varname(y[:]), y)).indices[1] ===
|
94 |
| - AbstractPPL.ConcretizedSlice(to_indices(y, (:,))[1]) |
| 94 | + AbstractPPL.ConcretizedSlice(to_indices(y, (:,))[1]) |
95 | 95 | @test test_equal(@varname(x.a[1:end, end][:], true), @varname(x.a[1:3, 2][1:3]))
|
96 | 96 | end
|
97 | 97 |
|
|
252 | 252 | @test string_to_varname(varname_to_string(vn)) == vn
|
253 | 253 | end
|
254 | 254 |
|
| 255 | + @testset "head, tail, init, last" begin |
| 256 | + @testset "specification" begin |
| 257 | + @test AbstractPPL._head(@o _.a.b.c) == @o _.a |
| 258 | + @test AbstractPPL._tail(@o _.a.b.c) == @o _.b.c |
| 259 | + @test AbstractPPL._init(@o _.a.b.c) == @o _.a.b |
| 260 | + @test AbstractPPL._last(@o _.a.b.c) == @o _.c |
| 261 | + |
| 262 | + @test AbstractPPL._head(@o _[1][2][3]) == @o _[1] |
| 263 | + @test AbstractPPL._tail(@o _[1][2][3]) == @o _[2][3] |
| 264 | + @test AbstractPPL._init(@o _[1][2][3]) == @o _[1][2] |
| 265 | + @test AbstractPPL._last(@o _[1][2][3]) == @o _[3] |
| 266 | + |
| 267 | + @test AbstractPPL._head(@o _.a) == @o _.a |
| 268 | + @test AbstractPPL._tail(@o _.a) == identity |
| 269 | + @test AbstractPPL._init(@o _.a) == identity |
| 270 | + @test AbstractPPL._last(@o _.a) == @o _.a |
| 271 | + |
| 272 | + @test AbstractPPL._head(@o _[1]) == @o _[1] |
| 273 | + @test AbstractPPL._tail(@o _[1]) == identity |
| 274 | + @test AbstractPPL._init(@o _[1]) == identity |
| 275 | + @test AbstractPPL._last(@o _[1]) == @o _[1] |
| 276 | + |
| 277 | + @test AbstractPPL._head(identity) == identity |
| 278 | + @test AbstractPPL._tail(identity) == identity |
| 279 | + @test AbstractPPL._init(identity) == identity |
| 280 | + @test AbstractPPL._last(identity) == identity |
| 281 | + end |
| 282 | + |
| 283 | + @testset "composition" begin |
| 284 | + varnames = (@varname(x), |
| 285 | + @varname(x[1]), |
| 286 | + @varname(x.a), |
| 287 | + @varname(x.a.b), |
| 288 | + @varname(x[1].a), |
| 289 | + ) |
| 290 | + for vn in varnames |
| 291 | + optic = getoptic(vn) |
| 292 | + @test AbstractPPL.normalise(AbstractPPL._last(optic) ∘ AbstractPPL._init(optic)) == optic |
| 293 | + @test AbstractPPL.normalise(AbstractPPL._tail(optic) ∘ AbstractPPL._head(optic)) == optic |
| 294 | + end |
| 295 | + end |
| 296 | + end |
| 297 | + |
| 298 | + |
255 | 299 | @testset "prefix and unprefix" begin
|
256 | 300 | @testset "basic cases" begin
|
257 | 301 | @test prefix(@varname(y), @varname(x)) == @varname(x.y)
|
|
0 commit comments