Skip to content

Commit ba3cd38

Browse files
committed
Add more tests for property interpolation
1 parent ac30135 commit ba3cd38

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

src/sugar.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,11 @@ julia> t = ("one", "two")
236236
237237
julia> set(t, (@lens _[1]), "1")
238238
("1", "two")
239+
240+
julia> # Indices are always evaluated in external scope; for properties, you can use interpolation:
241+
n, i = :a, 10
242+
@lens(_.\$n[i, i+1])
243+
(@lens _.a[10, 11])
239244
```
240245
241246
"""

test/test_core.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,8 +510,12 @@ end
510510
@test @lens(_.a $lbc) == @lens(_.a) lbc
511511
@test @lens(_.a $lbc _[1] $lbc) == @lens(_.a) lbc @lens(_[1]) lbc
512512

513+
# property interpolation
513514
name = :a
515+
fancy(name, suffix) = Symbol("fancy_", name, suffix)
514516
@test @lens(_.$name) == @lens(_.a)
517+
@test @lens(_.x[1, :].$name) == @lens(_.x[1, :].a)
518+
@test @lens(_.x[1, :].$(fancy(name, ""))) == @lens(_.x[1, :].var"fancy_a✨")
515519
end
516520

517521
end

0 commit comments

Comments
 (0)