1bcefb8aeSAndreas Gohr<?php 2bcefb8aeSAndreas Gohr 3bcefb8aeSAndreas Gohrnamespace dokuwiki\test\Parsing\ParserMode; 4bcefb8aeSAndreas Gohr 5bcefb8aeSAndreas Gohruse dokuwiki\Parsing\ParserMode\GfmStrongUnderscore; 6bcefb8aeSAndreas Gohr 7bcefb8aeSAndreas Gohr/** 8bcefb8aeSAndreas Gohr * Tests for GFM strong emphasis via double underscores (`__text__`). 9bcefb8aeSAndreas Gohr */ 10bcefb8aeSAndreas Gohrclass GfmStrongUnderscoreTest extends ParserTestBase 11bcefb8aeSAndreas Gohr{ 12bcefb8aeSAndreas Gohr public function setUp(): void 13bcefb8aeSAndreas Gohr { 14bcefb8aeSAndreas Gohr parent::setUp(); 15*47a02a10SAndreas Gohr $this->setSyntax('md'); 16bcefb8aeSAndreas Gohr } 17bcefb8aeSAndreas Gohr 18bcefb8aeSAndreas Gohr function testBasic() 19bcefb8aeSAndreas Gohr { 20bcefb8aeSAndreas Gohr $this->P->addMode('gfm_strong_underscore', new GfmStrongUnderscore()); 21bcefb8aeSAndreas Gohr $this->P->parse('Foo __Bar__ Baz'); 22bcefb8aeSAndreas Gohr $calls = [ 23bcefb8aeSAndreas Gohr ['document_start', []], 24bcefb8aeSAndreas Gohr ['p_open', []], 25bcefb8aeSAndreas Gohr ['cdata', ["\nFoo "]], 26bcefb8aeSAndreas Gohr ['strong_open', []], 27bcefb8aeSAndreas Gohr ['cdata', ['Bar']], 28bcefb8aeSAndreas Gohr ['strong_close', []], 29bcefb8aeSAndreas Gohr ['cdata', [' Baz']], 30bcefb8aeSAndreas Gohr ['p_close', []], 31bcefb8aeSAndreas Gohr ['document_end', []], 32bcefb8aeSAndreas Gohr ]; 33bcefb8aeSAndreas Gohr $this->assertCalls($calls, $this->H->calls); 34bcefb8aeSAndreas Gohr } 35bcefb8aeSAndreas Gohr 36bcefb8aeSAndreas Gohr function testSingleCharacter() 37bcefb8aeSAndreas Gohr { 38bcefb8aeSAndreas Gohr $this->P->addMode('gfm_strong_underscore', new GfmStrongUnderscore()); 39bcefb8aeSAndreas Gohr $this->P->parse('__x__'); 40bcefb8aeSAndreas Gohr $modes = array_column($this->H->calls, 0); 41bcefb8aeSAndreas Gohr $this->assertContains('strong_open', $modes); 42bcefb8aeSAndreas Gohr $this->assertContains('strong_close', $modes); 43bcefb8aeSAndreas Gohr } 44bcefb8aeSAndreas Gohr 45bcefb8aeSAndreas Gohr function testMultipleWords() 46bcefb8aeSAndreas Gohr { 47bcefb8aeSAndreas Gohr $this->P->addMode('gfm_strong_underscore', new GfmStrongUnderscore()); 48bcefb8aeSAndreas Gohr $this->P->parse('__one two three__'); 49bcefb8aeSAndreas Gohr $modes = array_column($this->H->calls, 0); 50bcefb8aeSAndreas Gohr $this->assertContains('strong_open', $modes); 51bcefb8aeSAndreas Gohr } 52bcefb8aeSAndreas Gohr 53bcefb8aeSAndreas Gohr function testIntrawordDoesNotOpen() 54bcefb8aeSAndreas Gohr { 55bcefb8aeSAndreas Gohr // `foo__bar__` — opening `__` intraword (preceded by `o`). 56bcefb8aeSAndreas Gohr $this->P->addMode('gfm_strong_underscore', new GfmStrongUnderscore()); 57bcefb8aeSAndreas Gohr $this->P->parse('foo__bar__'); 58bcefb8aeSAndreas Gohr $this->assertNotContains('strong_open', array_column($this->H->calls, 0)); 59bcefb8aeSAndreas Gohr } 60bcefb8aeSAndreas Gohr 61bcefb8aeSAndreas Gohr function testLeadingWhitespaceDoesNotOpen() 62bcefb8aeSAndreas Gohr { 63bcefb8aeSAndreas Gohr $this->P->addMode('gfm_strong_underscore', new GfmStrongUnderscore()); 64bcefb8aeSAndreas Gohr $this->P->parse('__ foo bar__'); 65bcefb8aeSAndreas Gohr $this->assertNotContains('strong_open', array_column($this->H->calls, 0)); 66bcefb8aeSAndreas Gohr } 67bcefb8aeSAndreas Gohr 68bcefb8aeSAndreas Gohr function testTrailingWhitespaceDoesNotClose() 69bcefb8aeSAndreas Gohr { 70bcefb8aeSAndreas Gohr $this->P->addMode('gfm_strong_underscore', new GfmStrongUnderscore()); 71bcefb8aeSAndreas Gohr $this->P->parse('__foo bar __'); 72bcefb8aeSAndreas Gohr $this->assertNotContains('strong_open', array_column($this->H->calls, 0)); 73bcefb8aeSAndreas Gohr } 74bcefb8aeSAndreas Gohr 75bcefb8aeSAndreas Gohr function testEmptyDelimiterDoesNotMatch() 76bcefb8aeSAndreas Gohr { 77bcefb8aeSAndreas Gohr $this->P->addMode('gfm_strong_underscore', new GfmStrongUnderscore()); 78bcefb8aeSAndreas Gohr $this->P->parse('____'); 79bcefb8aeSAndreas Gohr $this->assertNotContains('strong_open', array_column($this->H->calls, 0)); 80bcefb8aeSAndreas Gohr } 81bcefb8aeSAndreas Gohr 82bcefb8aeSAndreas Gohr function testMultibyteIntrawordDoesNotMatch() 83bcefb8aeSAndreas Gohr { 84bcefb8aeSAndreas Gohr // Cyrillic spec example: `пристаням__стремятся__` — intraword, literal. 85bcefb8aeSAndreas Gohr $this->P->addMode('gfm_strong_underscore', new GfmStrongUnderscore()); 86bcefb8aeSAndreas Gohr $this->P->parse('пристаням__стремятся__'); 87bcefb8aeSAndreas Gohr $this->assertNotContains('strong_open', array_column($this->H->calls, 0)); 88bcefb8aeSAndreas Gohr } 89bcefb8aeSAndreas Gohr 90bcefb8aeSAndreas Gohr function testMultibyteContentInsideStrongWorks() 91bcefb8aeSAndreas Gohr { 92bcefb8aeSAndreas Gohr $this->P->addMode('gfm_strong_underscore', new GfmStrongUnderscore()); 93bcefb8aeSAndreas Gohr $this->P->parse('foo __für etwas__ bar'); 94bcefb8aeSAndreas Gohr $this->assertContains('strong_open', array_column($this->H->calls, 0)); 95bcefb8aeSAndreas Gohr $this->assertContains('strong_close', array_column($this->H->calls, 0)); 96bcefb8aeSAndreas Gohr } 97bcefb8aeSAndreas Gohr 98bcefb8aeSAndreas Gohr function testDoesNotSpanParagraphBoundary() 99bcefb8aeSAndreas Gohr { 100bcefb8aeSAndreas Gohr $this->P->addMode('gfm_strong_underscore', new GfmStrongUnderscore()); 101bcefb8aeSAndreas Gohr $this->P->parse("__open\n\nclose__"); 102bcefb8aeSAndreas Gohr $this->assertNotContains('strong_open', array_column($this->H->calls, 0)); 103bcefb8aeSAndreas Gohr } 104bcefb8aeSAndreas Gohr 105bcefb8aeSAndreas Gohr function testSortValue() 106bcefb8aeSAndreas Gohr { 107bcefb8aeSAndreas Gohr $this->assertSame(70, (new GfmStrongUnderscore())->getSort()); 108bcefb8aeSAndreas Gohr } 109bcefb8aeSAndreas Gohr 110bcefb8aeSAndreas Gohr function testInstructionNameIsStrong() 111bcefb8aeSAndreas Gohr { 112bcefb8aeSAndreas Gohr // The mode name is distinct (so it coexists with DW Strong in the 113bcefb8aeSAndreas Gohr // lexer) but it must emit the same `strong_open`/`strong_close` 114bcefb8aeSAndreas Gohr // instructions so the XHTML renderer outputs <strong>. 115bcefb8aeSAndreas Gohr $this->P->addMode('gfm_strong_underscore', new GfmStrongUnderscore()); 116bcefb8aeSAndreas Gohr $this->P->parse('__x__'); 117bcefb8aeSAndreas Gohr $modes = array_column($this->H->calls, 0); 118bcefb8aeSAndreas Gohr $this->assertContains('strong_open', $modes); 119bcefb8aeSAndreas Gohr $this->assertNotContains('gfm_strong_underscore_open', $modes); 120bcefb8aeSAndreas Gohr } 121bcefb8aeSAndreas Gohr} 122