|
258 | 258 | write(aio, Base.AnnotatedString("hello", [(1:5, :tag, 1)])) |
259 | 259 | @test sprint(show, aio) == "Base.AnnotatedIOBuffer(5 bytes, 1 annotation)" |
260 | 260 | end |
| 261 | + |
| 262 | +@testset "Eachregion" begin |
| 263 | + annregions(str::String, annots::Vector{<:Tuple{UnitRange{Int}, Symbol, <:Any}}) = |
| 264 | + [(s, Tuple.(a)) for (s, a) in Base.eachregion(Base.AnnotatedString(str, annots))] |
| 265 | + # Regions that do/don't extend to the left/right edges |
| 266 | + @test annregions(" abc ", [(2:4, :face, :bold)]) == |
| 267 | + [(" ", []), |
| 268 | + ("abc", [(:face, :bold)]), |
| 269 | + (" ", [])] |
| 270 | + @test annregions(" x ", [(2:2, :face, :bold)]) == |
| 271 | + [(" ", []), |
| 272 | + ("x", [(:face, :bold)]), |
| 273 | + (" ", [])] |
| 274 | + @test annregions(" x", [(2:2, :face, :bold)]) == |
| 275 | + [(" ", []), |
| 276 | + ("x", [(:face, :bold)])] |
| 277 | + @test annregions("x ", [(1:1, :face, :bold)]) == |
| 278 | + [("x", [(:face, :bold)]), |
| 279 | + (" ", [])] |
| 280 | + @test annregions("x", [(1:1, :face, :bold)]) == |
| 281 | + [("x", [(:face, :bold)])] |
| 282 | + # Overlapping/nested regions |
| 283 | + @test annregions(" abc ", [(2:4, :face, :bold), (3:3, :face, :italic)]) == |
| 284 | + [(" ", []), |
| 285 | + ("a", [(:face, :bold)]), |
| 286 | + ("b", [(:face, :bold), (:face, :italic)]), |
| 287 | + ("c", [(:face, :bold)]), |
| 288 | + (" ", [])] |
| 289 | + @test annregions("abc-xyz", [(1:7, :face, :bold), (1:3, :face, :green), (4:4, :face, :yellow), (4:7, :face, :italic)]) == |
| 290 | + [("abc", [(:face, :bold), (:face, :green)]), |
| 291 | + ("-", [(:face, :bold), (:face, :yellow), (:face, :italic)]), |
| 292 | + ("xyz", [(:face, :bold), (:face, :italic)])] |
| 293 | + # Preserving annotation order |
| 294 | + @test annregions("abcd", [(1:3, :face, :red), (2:2, :face, :yellow), (2:3, :face, :green), (2:4, :face, :blue)]) == |
| 295 | + [("a", [(:face, :red)]), |
| 296 | + ("b", [(:face, :red), (:face, :yellow), (:face, :green), (:face, :blue)]), |
| 297 | + ("c", [(:face, :red), (:face, :green), (:face, :blue)]), |
| 298 | + ("d", [(:face, :blue)])] |
| 299 | + @test annregions("abcd", [(2:4, :face, :blue), (1:3, :face, :red), (2:3, :face, :green), (2:2, :face, :yellow)]) == |
| 300 | + [("a", [(:face, :red)]), |
| 301 | + ("b", [(:face, :blue), (:face, :red), (:face, :green), (:face, :yellow)]), |
| 302 | + ("c", [(:face, :blue), (:face, :red), (:face, :green)]), |
| 303 | + ("d", [(:face, :blue)])] |
| 304 | + # Region starting after a character spanning multiple codepoints. |
| 305 | + @test annregions("𝟏x", [(1:4, :face, :red)]) == |
| 306 | + [("𝟏", [(:face, :red)]), |
| 307 | + ("x", [])] |
| 308 | +end |
0 commit comments