From 75302feda446d8340dd8a065fb706f72248658e9 Mon Sep 17 00:00:00 2001 From: Roni Jacobson Date: Sun, 2 Aug 2026 02:21:12 +0300 Subject: [PATCH] Add test for superfluous newline in html formatting --- src/terminal/formatter.zig | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/src/terminal/formatter.zig b/src/terminal/formatter.zig index f76b865c9..7cde65560 100644 --- a/src/terminal/formatter.zig +++ b/src/terminal/formatter.zig @@ -5514,6 +5514,43 @@ test "Page html with unicode as numeric entities" { ); } +test "Page html trailing blank lines" { + const testing = std.testing; + const alloc = testing.allocator; + const io = testing.io; + + var builder: std.Io.Writer.Allocating = .init(alloc); + defer builder.deinit(); + + var t = try Terminal.init(io, alloc, .{ + .cols = 80, + .rows = 24, + }); + defer t.deinit(alloc); + + var s = t.vtStream(); + defer s.deinit(); + + s.nextSlice("hello\r\nworld\r\n\r\n"); + + const pages = &t.screens.active.pages; + try testing.expect(pages.pages.first != null); + try testing.expect(pages.pages.first == pages.pages.last); + + const page = pages.pages.last.?.page(); + var formatter: PageFormatter = .init(page, .{ .emit = .html }); + + const state = try formatter.formatWithState(&builder.writer); + const output = builder.writer.buffered(); + + // The closing div behaves as a newline + try testing.expectEqual(@as(usize, page.size.rows - 2), state.rows); + try testing.expectEqualStrings( + "
hello\nworld
", + output, + ); +} + test "Page html ascii characters unchanged" { const testing = std.testing; const alloc = testing.allocator;