writeFixture(<<foo `````````` trailing prose SPEC); $examples = iterator_to_array($reader->examples(), false); $this->assertCount(1, $examples); $this->assertSame(1, $examples[0]['number']); $this->assertSame('Simple Headings', $examples[0]['section']); $this->assertNull($examples[0]['extension']); $this->assertSame("# foo", $examples[0]['markdown']); $this->assertSame("

foo

", $examples[0]['html']); } public function testSectionTracking() { $reader = $this->writeFixture(<<a

`````````` ## Section Two `````````` example b .

b

`````````` SPEC); $examples = iterator_to_array($reader->examples(), false); $this->assertCount(2, $examples); $this->assertSame(1, $examples[0]['number']); $this->assertSame('Section One', $examples[0]['section']); $this->assertSame(2, $examples[1]['number']); $this->assertSame('Section Two', $examples[1]['section']); } public function testExampleWithExtensionLabel() { $reader = $this->writeFixture(<<… `````````` SPEC); $examples = iterator_to_array($reader->examples(), false); $this->assertCount(1, $examples); $this->assertSame('table', $examples[0]['extension']); $this->assertStringContainsString('| a | b |', $examples[0]['markdown']); } public function testMultilineMarkdownAndHtml() { $reader = $this->writeFixture(<<line one line two

line four

`````````` SPEC); $examples = iterator_to_array($reader->examples(), false); $this->assertSame( "line one\nline two\n\nline four", $examples[0]['markdown'] ); $this->assertSame( "

line one\nline two

\n

line four

", $examples[0]['html'] ); } public function testBackticksInsideExampleAreNotConfusedForFence() { // Opening fence is 14 backticks; a shorter run inside must not close. $reader = $this->writeFixture(<<here is code with backticks

`````````````` SPEC); $examples = iterator_to_array($reader->examples(), false); $this->assertCount(1, $examples); $this->assertStringContainsString('`code`', $examples[0]['markdown']); } public function testNumbersAreSequential() { $body = ''; for ($i = 1; $i <= 5; $i++) { $body .= "`````````` example\nmd$i\n.\nhtml$i\n``````````\n\n"; } $reader = $this->writeFixture($body); $examples = iterator_to_array($reader->examples(), false); $this->assertCount(5, $examples); foreach ($examples as $i => $ex) { $this->assertSame($i + 1, $ex['number']); } } public function testUnclosedFenceThrows() { $reader = $this->writeFixture(<<x

SPEC); $this->expectException(\RuntimeException::class); iterator_to_array($reader->examples(), false); } public function testMissingFileThrows() { $reader = new SpecReader('/nonexistent/path/spec.txt'); $this->expectException(\RuntimeException::class); iterator_to_array($reader->examples(), false); } }