From 21a27a0366c52680a65dfbd120aab2a183b4cbc7 Mon Sep 17 00:00:00 2001 From: Mark Scherer Date: Sat, 15 Aug 2026 14:17:10 +0200 Subject: [PATCH] test: cover the empty-figure early return in plain text renderFigure() returns an empty string when nothing in the figure renders, skipping the blank-line terminator every other block emits. No source spells that shape, so the branch went uncovered; the AST does, and FigureGroupExtension reaches it whenever a figure div holds no renderable content. --- .../TestCase/Renderer/PlainTextRendererTest.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/TestCase/Renderer/PlainTextRendererTest.php b/tests/TestCase/Renderer/PlainTextRendererTest.php index 3fca5b5..8036c3b 100644 --- a/tests/TestCase/Renderer/PlainTextRendererTest.php +++ b/tests/TestCase/Renderer/PlainTextRendererTest.php @@ -6,6 +6,8 @@ use Djot\DjotConverter; use Djot\Event\RenderEvent; +use Djot\Node\Block\Figure; +use Djot\Node\Document; use Djot\Node\Inline\Symbol; use Djot\Renderer\PlainTextRenderer; use Djot\Renderer\SoftBreakMode; @@ -79,6 +81,20 @@ public function testFigureBetweenParagraphs(): void $this->assertSame("Before.\n\na\nPanel caption\n\nAfter.\n", $this->renderer->render($document)); } + /** + * A figure with nothing renderable in it contributes no text at all - not + * even the blank line every other block terminates with. Reachable through + * the AST rather than through source: an empty figure div transformed by an + * extension leaves an empty panels container behind. + */ + public function testEmptyFigureRendersNothing(): void + { + $document = new Document(); + $document->appendChild(new Figure()); + + $this->assertSame("\n", $this->renderer->render($document)); + } + public function testHeadings(): void { $djot = "# Welcome\n\nThis is content.";