Skip to content

Commit

Permalink
Bugfix: use the right string for spillover, add more tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
aaruni96 committed Jan 30, 2024
1 parent c8045b7 commit 76ded33
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/PrettyPrinting.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1613,8 +1613,8 @@ function _write_line(io::IOCustom, str::AbstractString)
# partitions of the spillover text
written += write(io.io, "\n")
written += write_indent(io)
for j in Base.Iterators.drop(Base.Iterators.take(normalised_str,i[end]), i[begin]-1)
# j is noramlised_str[i[begin]:i[end]], constructed via iterators
for j in Base.Iterators.drop(Base.Iterators.take(reststr,i[end]), i[begin]-1)
# j is reststr[i[begin]:i[end]], constructed via iterators
written += write(io.io, j)
io.printed = textwidth(j)
end
Expand Down
45 changes: 45 additions & 0 deletions test/PrettyPrinting-test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,23 @@ let
print(io, AbstractAlgebra.Indent(), "ŎŚĊĂŖ")
@test String(take!(io)) == "testing unicode\n" *
" ŎŚĊĂŖ"

# Test evil unicodes
io = IOBuffer()
io = AbstractAlgebra.pretty(io, force_newlines = true)
_, c = displaysize(io)
print(io, AbstractAlgebra.Indent())
ellipses = String([0xe2, 0x80, 0xa6])
wedge = String([0xe2, 0x88, 0xa7])
iacute = String([0xc3, 0xad])
str = wedge ^25 * ellipses^25 * iacute^50
print(io, "aa", str)
@test String(take!(io)) == " aa∧∧∧∧∧∧∧∧∧∧∧∧∧∧∧∧∧∧∧∧∧∧∧∧∧" *
"…………………………………………………………………" *
"íííííííííííííííííííííííííí\n" *
" íííííííííííííííííííííííí"


# Test string longer than width
io = IOBuffer()
io = AbstractAlgebra.pretty(io, force_newlines = true)
Expand Down Expand Up @@ -454,6 +471,34 @@ let
" aa" * "Ŗ"^(c-6) * "\n" *
" ŖŖŖŖŖŖ"

# Test evil unicode string much longer than width
io = IOBuffer()
io = AbstractAlgebra.pretty(io, force_newlines = true)
_, c = displaysize(io)
ellipses = String([0xe2, 0x80, 0xa6])
wedge = String([0xe2, 0x88, 0xa7])
iacute = String([0xc3, 0xad])
print(io, AbstractAlgebra.Indent())
println(io, "Ŏ"^c)
println(io, ellipses^c)
println(io, "aa", "Ś"^c)
println(io, "bb", wedge^c)
print(io, AbstractAlgebra.Indent())
println(io, "aa", "Ŗ"^c)
print(io, iacute^c)
@test String(take!(io)) == " " * "Ŏ"^(c-2) * "\n" *
" ŎŎ" * "\n" *
" " * ellipses^(c-2) * "\n" *
" " * ellipses^2 * "\n" *
" aa" * "Ś"^(c-4) * "\n" *
" ŚŚŚŚ" * "\n" *
" bb" * wedge^(c-4) * "\n" *
" " * wedge^4 * "\n" *
" aa" * "Ŗ"^(c-6) * "\n" *
" ŖŖŖŖŖŖ" * "\n" *
" " * iacute^(c-4) * "\n" *
" " * iacute^4

# Test too much indentation
io = IOBuffer()
io = AbstractAlgebra.pretty(io, force_newlines = true)
Expand Down

0 comments on commit 76ded33

Please sign in to comment.