Skip to content

Commit 9a23e9e

Browse files
committed
Test the display of parsing errors
1 parent 1d7f42a commit 9a23e9e

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

test/runtests.jl

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ using Test
55
using StyledStrings: StyledStrings, Legacy, SimpleColor, FACES, Face,
66
@styled_str, styled, StyledMarkup, getface, addface!, loadface!, resetfaces!
77
using .StyledMarkup: MalformedStylingMacro
8-
using Base: AnnotatedString, AnnotatedChar, AnnotatedIOBuffer
8+
using Base: AnnotatedString, AnnotatedChar, AnnotatedIOBuffer, annotations
99

1010
# For output testing
1111

@@ -388,6 +388,24 @@ end
388388
@test_throws MalformedStylingMacro styled("{(weight=invalid):}")
389389
@test_throws MalformedStylingMacro styled("{(slant=invalid):}")
390390
@test_throws MalformedStylingMacro styled("{(invalid=):}")
391+
# Test the error printing too
392+
aio = AnnotatedIOBuffer()
393+
try
394+
styled("{")
395+
catch err
396+
showerror(aio, err)
397+
end
398+
errstr = read(seekstart(aio), AnnotatedString)
399+
Base.annotatedstring_optimize!(errstr) # Remove when julialang/julia/#53801 is merged.
400+
filter!(((region, _),) -> !isempty(region),
401+
annotations(errstr))
402+
sort!(annotations(errstr), by=first) # Remove when julialang/julia/#53800 is merged.
403+
@test errstr ==
404+
styled"MalformedStylingMacro\n\
405+
{error:│} Incomplete annotation declaration:\n\
406+
{error:│} {bright_green:\"\{\"}\n\
407+
{error:│} {info:╰─╴starts here}\n\
408+
{error:┕} {light,italic:1 issue}\n"
391409
end
392410

393411
@testset "AnnotatedIOBuffer" begin

0 commit comments

Comments
 (0)