From 76ded33fddd82aec83f8a4e554c23af23c13e400 Mon Sep 17 00:00:00 2001 From: Aaruni Kaushik Date: Tue, 30 Jan 2024 11:36:16 +0100 Subject: [PATCH] Bugfix: use the right string for spillover, add more tests. --- src/PrettyPrinting.jl | 4 ++-- test/PrettyPrinting-test.jl | 45 +++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 2 deletions(-) diff --git a/src/PrettyPrinting.jl b/src/PrettyPrinting.jl index bf31227958..5edea344fb 100644 --- a/src/PrettyPrinting.jl +++ b/src/PrettyPrinting.jl @@ -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 diff --git a/test/PrettyPrinting-test.jl b/test/PrettyPrinting-test.jl index 3f7c623ba2..b7ad216d7d 100644 --- a/test/PrettyPrinting-test.jl +++ b/test/PrettyPrinting-test.jl @@ -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) @@ -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)