|
396 | 396 | @test_throws ArgumentError set(" abc def ", @optic(split(_, ' ')), [" ", "y"]) |
397 | 397 | end |
398 | 398 |
|
| 399 | +VERSION ≥ v"1.11" && @testset "AnnotatedStrings" begin |
| 400 | + using Base: AnnotatedChar, AnnotatedString, annotations |
| 401 | + |
| 402 | + s = Base.AnnotatedString("good bad", [(region=1:4, label=:sentiment, value=+1), (region=6:8, label=:sentiment, value=-1)]) |
| 403 | + |
| 404 | + @test (@delete annotations(s))::String == "good bad" |
| 405 | + |
| 406 | + snew = @delete annotations(s)[2] |
| 407 | + @test String(snew) == "good bad" |
| 408 | + @test annotations(snew) == [(region=1:4, label=:sentiment, value=+1)] |
| 409 | + |
| 410 | + snew = (@set Base.annotations(s)[1].region = 2:6) |
| 411 | + @test String(snew) == "good bad" |
| 412 | + @test annotations(snew) == [(region=2:6, label=:sentiment, value=+1), (region=6:8, label=:sentiment, value=-1)] |
| 413 | + |
| 414 | + test_getset_laws((@o annotations(_)[2].region), s, 5:5, 1:3) |
| 415 | + test_getset_laws((@o annotations(_)[2].label), s, :abc, :def) |
| 416 | + test_getset_laws((@o annotations(_)[2].value), s, "sad", +2) |
| 417 | + test_insertdelete_laws((@o annotations(_)[2]), s, (region=2:2, label=:mylabel, value=+1)) |
| 418 | +end |
| 419 | + |
399 | 420 | @testset "custom binary function" begin |
400 | 421 | ↑(x, y) = x - y |
401 | 422 | Accessors.set(x, f::Base.Fix1{typeof(↑)}, y) = f.x - y |
|
0 commit comments