Skip to content

Commit bfdb4c3

Browse files
committed
Modify tests to also pass when run as stdlib
When julialang/julia tests StyledStrings as part of the stdlib, the package prefix starts appearing in show methods. By chopping it off, the show tests should pass/work both when run in isolation and as a stdlib.
1 parent c084718 commit bfdb4c3

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

test/runtests.jl

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ function with_terminfo(fn::Function, tinfo::Base.TermInfo)
3232
end
3333
end
3434

35+
# When tested as part of the stdlib, the package prefix can start appearing in show methods.
36+
choppkg(s::String) = chopprefix(s, "StyledStrings.")
37+
3538
@testset "SimpleColor" begin
3639
@test SimpleColor(:hey).value == :hey # no error
3740
@test SimpleColor(0x01, 0x02, 0x03).value == (r=0x01, g=0x02, b=0x03)
@@ -43,13 +46,13 @@ end
4346
@test tryparse(SimpleColor, "!not a color") === nothing
4447
@test parse(SimpleColor, "blue") == SimpleColor(:blue)
4548
@test_throws ArgumentError parse(SimpleColor, "!not a color")
46-
@test sprint(show, SimpleColor(:blue)) ==
49+
@test sprint(show, SimpleColor(:blue)) |> choppkg ==
4750
"SimpleColor(:blue)"
48-
@test sprint(show, SimpleColor(0x123456)) ==
51+
@test sprint(show, SimpleColor(0x123456)) |> choppkg ==
4952
"SimpleColor(0x123456)"
50-
@test sprint(show, MIME("text/plain"), SimpleColor(:blue)) ==
53+
@test sprint(show, MIME("text/plain"), SimpleColor(:blue)) |> choppkg ==
5154
"SimpleColor(blue)"
52-
@test sprint(show, MIME("text/plain"), SimpleColor(:blue), context = :color => true) ==
55+
@test sprint(show, MIME("text/plain"), SimpleColor(:blue), context = :color => true) |> choppkg ==
5356
"SimpleColor(\e[34m■\e[39m blue)"
5457
@test sprint(show, MIME("text/plain"), SimpleColor(:blue), context = (:color => true, :typeinfo => SimpleColor)) ==
5558
"\e[34m■\e[39m blue"
@@ -211,7 +214,7 @@ end
211214
StyledStrings.resetfaces!()
212215
end
213216
# Pretty display
214-
@test sprint(show, MIME("text/plain"), getface()) ==
217+
@test sprint(show, MIME("text/plain"), getface()) |> choppkg ==
215218
"""
216219
Face (sample)
217220
font: monospace
@@ -224,7 +227,7 @@ end
224227
strikethrough: false
225228
inverse: false\
226229
"""
227-
@test sprint(show, MIME("text/plain"), getface(), context = :color => true) ==
230+
@test sprint(show, MIME("text/plain"), getface(), context = :color => true) |> choppkg ==
228231
"""
229232
Face (sample)
230233
font: monospace
@@ -237,35 +240,35 @@ end
237240
strikethrough: false
238241
inverse: false\
239242
"""
240-
@test sprint(show, MIME("text/plain"), FACES.default[:red], context = :color => true) ==
243+
@test sprint(show, MIME("text/plain"), FACES.default[:red], context = :color => true) |> choppkg ==
241244
"""
242245
Face (\e[31msample\e[39m)
243246
foreground: \e[31m■\e[39m red\
244247
"""
245-
@test sprint(show, FACES.default[:red]) ==
248+
@test sprint(show, FACES.default[:red]) |> choppkg ==
246249
"Face(foreground=SimpleColor(:red))"
247-
@test sprint(show, MIME("text/plain"), FACES.default[:red], context = :compact => true) ==
250+
@test sprint(show, MIME("text/plain"), FACES.default[:red], context = :compact => true) |> choppkg ==
248251
"Face(foreground=SimpleColor(:red))"
249-
@test sprint(show, MIME("text/plain"), FACES.default[:red], context = (:compact => true, :color => true)) ==
252+
@test sprint(show, MIME("text/plain"), FACES.default[:red], context = (:compact => true, :color => true)) |> choppkg ==
250253
"Face(\e[31msample\e[39m)"
251-
@test sprint(show, MIME("text/plain"), FACES.default[:highlight], context = :compact => true) ==
254+
@test sprint(show, MIME("text/plain"), FACES.default[:highlight], context = :compact => true) |> choppkg ==
252255
"Face(inverse=true, inherit=[:emphasis])"
253256
with_terminfo(vt100) do # Not truecolor capable
254-
@test sprint(show, MIME("text/plain"), FACES.default[:region], context = :color => true) ==
257+
@test sprint(show, MIME("text/plain"), FACES.default[:region], context = :color => true) |> choppkg ==
255258
"""
256259
Face (\e[48;5;237msample\e[49m)
257260
background: \e[38;5;237m■\e[39m #3a3a3a\
258261
"""
259262
end
260263
with_terminfo(fancy_term) do # Truecolor capable
261-
@test sprint(show, MIME("text/plain"), FACES.default[:region], context = :color => true) ==
264+
@test sprint(show, MIME("text/plain"), FACES.default[:region], context = :color => true) |> choppkg ==
262265
"""
263266
Face (\e[48;2;58;58;58msample\e[49m)
264267
background: \e[38;2;58;58;58m■\e[39m #3a3a3a\
265268
"""
266269
end
267270
with_terminfo(vt100) do # Ensure `enter_reverse_mode` exists
268-
@test sprint(show, MIME("text/plain"), FACES.default[:highlight], context = :color => true) ==
271+
@test sprint(show, MIME("text/plain"), FACES.default[:highlight], context = :color => true) |> choppkg ==
269272
"""
270273
Face (\e[34m\e[7msample\e[39m\e[27m)
271274
inverse: true

0 commit comments

Comments
 (0)