1<?php 2 3namespace dokuwiki\test\Parsing\ParserMode; 4 5use dokuwiki\Parsing\ModeRegistry; 6use dokuwiki\Parsing\ParserMode\GfmEmphasisStrongUnderscore; 7 8/** 9 * Tests for the GFM em-wrapping-strong mode via underscores (`___text___`). 10 * 11 * Only the exact 3+3 symmetric variant is handled; intraword underscores 12 * stay literal (multibyte-safe). 13 */ 14class GfmEmphasisStrongUnderscoreTest extends ParserTestBase 15{ 16 public function setUp(): void 17 { 18 parent::setUp(); 19 global $conf; 20 $conf['syntax'] = 'markdown'; 21 ModeRegistry::reset(); 22 } 23 24 public function tearDown(): void 25 { 26 ModeRegistry::reset(); 27 parent::tearDown(); 28 } 29 30 function testBasic() 31 { 32 $this->P->addMode('gfm_emphasis_strong_underscore', new GfmEmphasisStrongUnderscore()); 33 $this->P->parse('Foo ___Bar___ Baz'); 34 $calls = [ 35 ['document_start', []], 36 ['p_open', []], 37 ['cdata', ["\nFoo "]], 38 ['emphasis_open', []], 39 ['strong_open', []], 40 ['cdata', ['Bar']], 41 ['strong_close', []], 42 ['emphasis_close', []], 43 ['cdata', [' Baz']], 44 ['p_close', []], 45 ['document_end', []], 46 ]; 47 $this->assertCalls($calls, $this->H->calls); 48 } 49 50 function testSingleCharacter() 51 { 52 $this->P->addMode('gfm_emphasis_strong_underscore', new GfmEmphasisStrongUnderscore()); 53 $this->P->parse('___a___'); 54 $this->assertContains('emphasis_open', array_column($this->H->calls, 0)); 55 $this->assertContains('strong_open', array_column($this->H->calls, 0)); 56 } 57 58 function testLeadingWhitespaceDoesNotMatch() 59 { 60 $this->P->addMode('gfm_emphasis_strong_underscore', new GfmEmphasisStrongUnderscore()); 61 $this->P->parse('___ foo___'); 62 $this->assertNotContains('emphasis_open', array_column($this->H->calls, 0)); 63 } 64 65 function testTrailingWhitespaceDoesNotMatch() 66 { 67 $this->P->addMode('gfm_emphasis_strong_underscore', new GfmEmphasisStrongUnderscore()); 68 $this->P->parse('___foo ___'); 69 $this->assertNotContains('emphasis_open', array_column($this->H->calls, 0)); 70 } 71 72 function testDoesNotSpanParagraphBoundary() 73 { 74 $this->P->addMode('gfm_emphasis_strong_underscore', new GfmEmphasisStrongUnderscore()); 75 $this->P->parse("___foo\n\nbar___"); 76 $this->assertNotContains('emphasis_open', array_column($this->H->calls, 0)); 77 } 78 79 function testLongerSymmetricRunDoesNotMatch() 80 { 81 $this->P->addMode('gfm_emphasis_strong_underscore', new GfmEmphasisStrongUnderscore()); 82 $this->P->parse('____foo____'); 83 $this->assertNotContains('emphasis_open', array_column($this->H->calls, 0)); 84 } 85 86 function testAsymmetricDoesNotMatch() 87 { 88 $this->P->addMode('gfm_emphasis_strong_underscore', new GfmEmphasisStrongUnderscore()); 89 $this->P->parse('___foo__'); 90 $this->assertNotContains('emphasis_open', array_column($this->H->calls, 0)); 91 } 92 93 function testIntrawordDoesNotMatch() 94 { 95 $this->P->addMode('gfm_emphasis_strong_underscore', new GfmEmphasisStrongUnderscore()); 96 $this->P->parse('abc___foo___'); 97 $this->assertNotContains('emphasis_open', array_column($this->H->calls, 0)); 98 } 99 100 function testMultibyteIntrawordDoesNotMatch() 101 { 102 $this->P->addMode('gfm_emphasis_strong_underscore', new GfmEmphasisStrongUnderscore()); 103 $this->P->parse('für___etwas___'); 104 $this->assertNotContains('emphasis_open', array_column($this->H->calls, 0)); 105 } 106 107 function testMultibyteContentInside() 108 { 109 $this->P->addMode('gfm_emphasis_strong_underscore', new GfmEmphasisStrongUnderscore()); 110 $this->P->parse('foo ___für___ bar'); 111 $this->assertContains('emphasis_open', array_column($this->H->calls, 0)); 112 $this->assertContains('strong_open', array_column($this->H->calls, 0)); 113 } 114 115 function testSortValue() 116 { 117 $this->assertSame(65, (new GfmEmphasisStrongUnderscore())->getSort()); 118 } 119} 120