xref: /dokuwiki/_test/tests/Parsing/ParserMode/GfmEmphasisStrongUnderscoreTest.php (revision 47a02a102092be9e1e6f1ddaf158bdfffdb13d4f)
12bb62bcaSAndreas Gohr<?php
22bb62bcaSAndreas Gohr
32bb62bcaSAndreas Gohrnamespace dokuwiki\test\Parsing\ParserMode;
42bb62bcaSAndreas Gohr
52bb62bcaSAndreas Gohruse dokuwiki\Parsing\ParserMode\GfmEmphasisStrongUnderscore;
62bb62bcaSAndreas Gohr
72bb62bcaSAndreas Gohr/**
82bb62bcaSAndreas Gohr * Tests for the GFM em-wrapping-strong mode via underscores (`___text___`).
92bb62bcaSAndreas Gohr *
102bb62bcaSAndreas Gohr * Only the exact 3+3 symmetric variant is handled; intraword underscores
110244be5cSAndreas Gohr * stay literal
122bb62bcaSAndreas Gohr */
132bb62bcaSAndreas Gohrclass GfmEmphasisStrongUnderscoreTest extends ParserTestBase
142bb62bcaSAndreas Gohr{
152bb62bcaSAndreas Gohr    public function setUp(): void
162bb62bcaSAndreas Gohr    {
172bb62bcaSAndreas Gohr        parent::setUp();
18*47a02a10SAndreas Gohr        $this->setSyntax('md');
192bb62bcaSAndreas Gohr    }
202bb62bcaSAndreas Gohr
212bb62bcaSAndreas Gohr    function testBasic()
222bb62bcaSAndreas Gohr    {
232bb62bcaSAndreas Gohr        $this->P->addMode('gfm_emphasis_strong_underscore', new GfmEmphasisStrongUnderscore());
242bb62bcaSAndreas Gohr        $this->P->parse('Foo ___Bar___ Baz');
252bb62bcaSAndreas Gohr        $calls = [
262bb62bcaSAndreas Gohr            ['document_start', []],
272bb62bcaSAndreas Gohr            ['p_open', []],
282bb62bcaSAndreas Gohr            ['cdata', ["\nFoo "]],
292bb62bcaSAndreas Gohr            ['emphasis_open', []],
302bb62bcaSAndreas Gohr            ['strong_open', []],
312bb62bcaSAndreas Gohr            ['cdata', ['Bar']],
322bb62bcaSAndreas Gohr            ['strong_close', []],
332bb62bcaSAndreas Gohr            ['emphasis_close', []],
342bb62bcaSAndreas Gohr            ['cdata', [' Baz']],
352bb62bcaSAndreas Gohr            ['p_close', []],
362bb62bcaSAndreas Gohr            ['document_end', []],
372bb62bcaSAndreas Gohr        ];
382bb62bcaSAndreas Gohr        $this->assertCalls($calls, $this->H->calls);
392bb62bcaSAndreas Gohr    }
402bb62bcaSAndreas Gohr
412bb62bcaSAndreas Gohr    function testSingleCharacter()
422bb62bcaSAndreas Gohr    {
432bb62bcaSAndreas Gohr        $this->P->addMode('gfm_emphasis_strong_underscore', new GfmEmphasisStrongUnderscore());
442bb62bcaSAndreas Gohr        $this->P->parse('___a___');
452bb62bcaSAndreas Gohr        $this->assertContains('emphasis_open', array_column($this->H->calls, 0));
462bb62bcaSAndreas Gohr        $this->assertContains('strong_open', array_column($this->H->calls, 0));
472bb62bcaSAndreas Gohr    }
482bb62bcaSAndreas Gohr
492bb62bcaSAndreas Gohr    function testLeadingWhitespaceDoesNotMatch()
502bb62bcaSAndreas Gohr    {
512bb62bcaSAndreas Gohr        $this->P->addMode('gfm_emphasis_strong_underscore', new GfmEmphasisStrongUnderscore());
522bb62bcaSAndreas Gohr        $this->P->parse('___ foo___');
532bb62bcaSAndreas Gohr        $this->assertNotContains('emphasis_open', array_column($this->H->calls, 0));
542bb62bcaSAndreas Gohr    }
552bb62bcaSAndreas Gohr
562bb62bcaSAndreas Gohr    function testTrailingWhitespaceDoesNotMatch()
572bb62bcaSAndreas Gohr    {
582bb62bcaSAndreas Gohr        $this->P->addMode('gfm_emphasis_strong_underscore', new GfmEmphasisStrongUnderscore());
592bb62bcaSAndreas Gohr        $this->P->parse('___foo ___');
602bb62bcaSAndreas Gohr        $this->assertNotContains('emphasis_open', array_column($this->H->calls, 0));
612bb62bcaSAndreas Gohr    }
622bb62bcaSAndreas Gohr
632bb62bcaSAndreas Gohr    function testDoesNotSpanParagraphBoundary()
642bb62bcaSAndreas Gohr    {
652bb62bcaSAndreas Gohr        $this->P->addMode('gfm_emphasis_strong_underscore', new GfmEmphasisStrongUnderscore());
662bb62bcaSAndreas Gohr        $this->P->parse("___foo\n\nbar___");
672bb62bcaSAndreas Gohr        $this->assertNotContains('emphasis_open', array_column($this->H->calls, 0));
682bb62bcaSAndreas Gohr    }
692bb62bcaSAndreas Gohr
702bb62bcaSAndreas Gohr    function testLongerSymmetricRunDoesNotMatch()
712bb62bcaSAndreas Gohr    {
722bb62bcaSAndreas Gohr        $this->P->addMode('gfm_emphasis_strong_underscore', new GfmEmphasisStrongUnderscore());
732bb62bcaSAndreas Gohr        $this->P->parse('____foo____');
742bb62bcaSAndreas Gohr        $this->assertNotContains('emphasis_open', array_column($this->H->calls, 0));
752bb62bcaSAndreas Gohr    }
762bb62bcaSAndreas Gohr
772bb62bcaSAndreas Gohr    function testAsymmetricDoesNotMatch()
782bb62bcaSAndreas Gohr    {
792bb62bcaSAndreas Gohr        $this->P->addMode('gfm_emphasis_strong_underscore', new GfmEmphasisStrongUnderscore());
802bb62bcaSAndreas Gohr        $this->P->parse('___foo__');
812bb62bcaSAndreas Gohr        $this->assertNotContains('emphasis_open', array_column($this->H->calls, 0));
822bb62bcaSAndreas Gohr    }
832bb62bcaSAndreas Gohr
842bb62bcaSAndreas Gohr    function testIntrawordDoesNotMatch()
852bb62bcaSAndreas Gohr    {
862bb62bcaSAndreas Gohr        $this->P->addMode('gfm_emphasis_strong_underscore', new GfmEmphasisStrongUnderscore());
872bb62bcaSAndreas Gohr        $this->P->parse('abc___foo___');
882bb62bcaSAndreas Gohr        $this->assertNotContains('emphasis_open', array_column($this->H->calls, 0));
892bb62bcaSAndreas Gohr    }
902bb62bcaSAndreas Gohr
912bb62bcaSAndreas Gohr    function testMultibyteIntrawordDoesNotMatch()
922bb62bcaSAndreas Gohr    {
932bb62bcaSAndreas Gohr        $this->P->addMode('gfm_emphasis_strong_underscore', new GfmEmphasisStrongUnderscore());
942bb62bcaSAndreas Gohr        $this->P->parse('für___etwas___');
952bb62bcaSAndreas Gohr        $this->assertNotContains('emphasis_open', array_column($this->H->calls, 0));
962bb62bcaSAndreas Gohr    }
972bb62bcaSAndreas Gohr
982bb62bcaSAndreas Gohr    function testMultibyteContentInside()
992bb62bcaSAndreas Gohr    {
1002bb62bcaSAndreas Gohr        $this->P->addMode('gfm_emphasis_strong_underscore', new GfmEmphasisStrongUnderscore());
1012bb62bcaSAndreas Gohr        $this->P->parse('foo ___für___ bar');
1022bb62bcaSAndreas Gohr        $this->assertContains('emphasis_open', array_column($this->H->calls, 0));
1032bb62bcaSAndreas Gohr        $this->assertContains('strong_open', array_column($this->H->calls, 0));
1042bb62bcaSAndreas Gohr    }
1052bb62bcaSAndreas Gohr
1062bb62bcaSAndreas Gohr    function testSortValue()
1072bb62bcaSAndreas Gohr    {
1082bb62bcaSAndreas Gohr        $this->assertSame(65, (new GfmEmphasisStrongUnderscore())->getSort());
1092bb62bcaSAndreas Gohr    }
1102bb62bcaSAndreas Gohr}
111