Skip to content

Commit fc686f3

Browse files
committed
Explicitly test eachregion
While this is implicitly tested later on, I think it's nice to test for it explicitly. If nothing else, should any potentially buggy modifications be made in the future it will make it easier to pin down the root misbehaviour.
1 parent c417262 commit fc686f3

File tree

1 file changed

+45
-1
lines changed

1 file changed

+45
-1
lines changed

test/runtests.jl

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
using Test
44

55
using StyledStrings: StyledStrings, Legacy, SimpleColor, FACES, Face,
6-
@styled_str, styled, StyledMarkup, getface, addface!, loadface!, resetfaces!
6+
@styled_str, styled, StyledMarkup, eachregion, getface, addface!, loadface!, resetfaces!
77
using .StyledMarkup: MalformedStylingMacro
88
using Base: AnnotatedString, AnnotatedChar, AnnotatedIOBuffer, annotations
99

@@ -35,6 +35,50 @@ end
3535
# When tested as part of the stdlib, the package prefix can start appearing in show methods.
3636
choppkg(s::String) = chopprefix(s, "StyledStrings.")
3737

38+
@testset "Eachregion" begin
39+
annregions(str::String, annots::Vector{<:Tuple{UnitRange{Int}, <:Pair{Symbol, <:Any}}}) =
40+
collect(eachregion(AnnotatedString(str, annots)))
41+
# Regions that do/don't extend to the left/right edges
42+
@test annregions(" abc ", [(2:4, :face => :bold)]) ==
43+
[(" ", []),
44+
("abc", [:face => :bold]),
45+
(" ", [])]
46+
@test annregions(" x ", [(2:2, :face => :bold)]) ==
47+
[(" ", []),
48+
("x", [:face => :bold]),
49+
(" ", [])]
50+
@test annregions(" x", [(2:2, :face => :bold)]) ==
51+
[(" ", []),
52+
("x", [:face => :bold])]
53+
@test annregions("x ", [(1:1, :face => :bold)]) ==
54+
[("x", [:face => :bold]),
55+
(" ", [])]
56+
@test annregions("x", [(1:1, :face => :bold)]) ==
57+
[("x", [:face => :bold])]
58+
# Overlapping/nested regions
59+
@test annregions(" abc ", [(2:4, :face => :bold), (3:3, :face => :italic)]) ==
60+
[(" ", []),
61+
("a", [:face => :bold]),
62+
("b", [:face => :bold, :face => :italic]),
63+
("c", [:face => :bold]),
64+
(" ", [])]
65+
@test annregions("abc-xyz", [(1:7, :face => :bold), (1:3, :face => :green), (4:4, :face => :yellow), (4:7, :face => :italic)]) ==
66+
[("abc", [:face => :bold, :face => :green]),
67+
("-", [:face => :bold, :face => :yellow, :face => :italic]),
68+
("xyz", [:face => :bold, :face => :italic])]
69+
# Preserving annotation order
70+
@test annregions("abcd", [(1:3, :face => :red), (2:2, :face => :yellow), (2:3, :face => :green), (2:4, :face => :blue)]) ==
71+
[("a", [:face => :red]),
72+
("b", [:face => :red, :face => :yellow, :face => :green, :face => :blue]),
73+
("c", [:face => :red, :face => :green, :face => :blue]),
74+
("d", [:face => :blue])]
75+
@test annregions("abcd", [(2:4, :face => :blue), (1:3, :face => :red), (2:3, :face => :green), (2:2, :face => :yellow)]) ==
76+
[("a", [:face => :red]),
77+
("b", [:face => :blue, :face => :red, :face => :green, :face => :yellow]),
78+
("c", [:face => :blue, :face => :red, :face => :green]),
79+
("d", [:face => :blue])]
80+
end
81+
3882
@testset "SimpleColor" begin
3983
@test SimpleColor(:hey).value == :hey # no error
4084
@test SimpleColor(0x01, 0x02, 0x03).value == (r=0x01, g=0x02, b=0x03)

0 commit comments

Comments
 (0)