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