1<?php 2 3namespace dokuwiki\test\Parsing\ParserMode; 4 5use dokuwiki\Parsing\ParserMode\GfmEmphasisStrong; 6 7/** 8 * Tests for the GFM em-wrapping-strong mode (`***text***`). 9 * 10 * Only the exact 3+3 symmetric variant is handled. Longer symmetric runs 11 * (4+4, 6+6, ...) and asymmetric variants fall through to other modes or 12 * stay literal. 13 */ 14class GfmEmphasisStrongTest extends ParserTestBase 15{ 16 public function setUp(): void 17 { 18 parent::setUp(); 19 $this->setSyntax('md'); 20 } 21 22 function testBasic() 23 { 24 $this->P->addMode('gfm_emphasis_strong', new GfmEmphasisStrong()); 25 $this->P->parse('Foo ***Bar*** Baz'); 26 $calls = [ 27 ['document_start', []], 28 ['p_open', []], 29 ['cdata', ["\nFoo "]], 30 ['emphasis_open', []], 31 ['strong_open', []], 32 ['cdata', ['Bar']], 33 ['strong_close', []], 34 ['emphasis_close', []], 35 ['cdata', [' Baz']], 36 ['p_close', []], 37 ['document_end', []], 38 ]; 39 $this->assertCalls($calls, $this->H->calls); 40 } 41 42 function testSingleCharacter() 43 { 44 $this->P->addMode('gfm_emphasis_strong', new GfmEmphasisStrong()); 45 $this->P->parse('***a***'); 46 $modes = array_column($this->H->calls, 0); 47 $this->assertContains('emphasis_open', $modes); 48 $this->assertContains('strong_open', $modes); 49 $this->assertContains('strong_close', $modes); 50 $this->assertContains('emphasis_close', $modes); 51 } 52 53 function testLeadingWhitespaceDoesNotMatch() 54 { 55 $this->P->addMode('gfm_emphasis_strong', new GfmEmphasisStrong()); 56 $this->P->parse('*** foo***'); 57 $this->assertNotContains('emphasis_open', array_column($this->H->calls, 0)); 58 } 59 60 function testTrailingWhitespaceDoesNotMatch() 61 { 62 $this->P->addMode('gfm_emphasis_strong', new GfmEmphasisStrong()); 63 $this->P->parse('***foo ***'); 64 $this->assertNotContains('emphasis_open', array_column($this->H->calls, 0)); 65 } 66 67 function testDoesNotSpanParagraphBoundary() 68 { 69 $this->P->addMode('gfm_emphasis_strong', new GfmEmphasisStrong()); 70 $this->P->parse("***foo\n\nbar***"); 71 $this->assertNotContains('emphasis_open', array_column($this->H->calls, 0)); 72 } 73 74 function testLongerSymmetricRunDoesNotMatch() 75 { 76 // `****foo****` has 4 asterisks each side. The entry pattern requires 77 // the opener run to be exactly 3 (via `(?<!\*)` and `(?!\*)` on the 78 // closer), so this mode doesn't fire. It falls through to other 79 // modes (which is tested via the full spec suite). 80 $this->P->addMode('gfm_emphasis_strong', new GfmEmphasisStrong()); 81 $this->P->parse('****foo****'); 82 $this->assertNotContains('emphasis_open', array_column($this->H->calls, 0)); 83 } 84 85 function testAsymmetricDoesNotMatch() 86 { 87 // `***foo**` has 3 asterisks on the left but only 2 on the right. 88 // The entry's closing-delimiter lookahead requires exactly 3 `*`s 89 // not followed by another `*`, so there's no valid closer. 90 $this->P->addMode('gfm_emphasis_strong', new GfmEmphasisStrong()); 91 $this->P->parse('***foo**'); 92 $this->assertNotContains('emphasis_open', array_column($this->H->calls, 0)); 93 } 94 95 function testSortValue() 96 { 97 $this->assertSame(65, (new GfmEmphasisStrong())->getSort()); 98 } 99} 100