xref: /dokuwiki/_test/tests/Parsing/ParserMode/GfmEmphasisStrongTest.php (revision 47a02a102092be9e1e6f1ddaf158bdfffdb13d4f)
12bb62bcaSAndreas Gohr<?php
22bb62bcaSAndreas Gohr
32bb62bcaSAndreas Gohrnamespace dokuwiki\test\Parsing\ParserMode;
42bb62bcaSAndreas Gohr
52bb62bcaSAndreas Gohruse dokuwiki\Parsing\ParserMode\GfmEmphasisStrong;
62bb62bcaSAndreas Gohr
72bb62bcaSAndreas Gohr/**
82bb62bcaSAndreas Gohr * Tests for the GFM em-wrapping-strong mode (`***text***`).
92bb62bcaSAndreas Gohr *
102bb62bcaSAndreas Gohr * Only the exact 3+3 symmetric variant is handled. Longer symmetric runs
112bb62bcaSAndreas Gohr * (4+4, 6+6, ...) and asymmetric variants fall through to other modes or
122bb62bcaSAndreas Gohr * stay literal.
132bb62bcaSAndreas Gohr */
142bb62bcaSAndreas Gohrclass GfmEmphasisStrongTest extends ParserTestBase
152bb62bcaSAndreas Gohr{
162bb62bcaSAndreas Gohr    public function setUp(): void
172bb62bcaSAndreas Gohr    {
182bb62bcaSAndreas Gohr        parent::setUp();
19*47a02a10SAndreas Gohr        $this->setSyntax('md');
202bb62bcaSAndreas Gohr    }
212bb62bcaSAndreas Gohr
222bb62bcaSAndreas Gohr    function testBasic()
232bb62bcaSAndreas Gohr    {
242bb62bcaSAndreas Gohr        $this->P->addMode('gfm_emphasis_strong', new GfmEmphasisStrong());
252bb62bcaSAndreas Gohr        $this->P->parse('Foo ***Bar*** Baz');
262bb62bcaSAndreas Gohr        $calls = [
272bb62bcaSAndreas Gohr            ['document_start', []],
282bb62bcaSAndreas Gohr            ['p_open', []],
292bb62bcaSAndreas Gohr            ['cdata', ["\nFoo "]],
302bb62bcaSAndreas Gohr            ['emphasis_open', []],
312bb62bcaSAndreas Gohr            ['strong_open', []],
322bb62bcaSAndreas Gohr            ['cdata', ['Bar']],
332bb62bcaSAndreas Gohr            ['strong_close', []],
342bb62bcaSAndreas Gohr            ['emphasis_close', []],
352bb62bcaSAndreas Gohr            ['cdata', [' Baz']],
362bb62bcaSAndreas Gohr            ['p_close', []],
372bb62bcaSAndreas Gohr            ['document_end', []],
382bb62bcaSAndreas Gohr        ];
392bb62bcaSAndreas Gohr        $this->assertCalls($calls, $this->H->calls);
402bb62bcaSAndreas Gohr    }
412bb62bcaSAndreas Gohr
422bb62bcaSAndreas Gohr    function testSingleCharacter()
432bb62bcaSAndreas Gohr    {
442bb62bcaSAndreas Gohr        $this->P->addMode('gfm_emphasis_strong', new GfmEmphasisStrong());
452bb62bcaSAndreas Gohr        $this->P->parse('***a***');
462bb62bcaSAndreas Gohr        $modes = array_column($this->H->calls, 0);
472bb62bcaSAndreas Gohr        $this->assertContains('emphasis_open', $modes);
482bb62bcaSAndreas Gohr        $this->assertContains('strong_open', $modes);
492bb62bcaSAndreas Gohr        $this->assertContains('strong_close', $modes);
502bb62bcaSAndreas Gohr        $this->assertContains('emphasis_close', $modes);
512bb62bcaSAndreas Gohr    }
522bb62bcaSAndreas Gohr
532bb62bcaSAndreas Gohr    function testLeadingWhitespaceDoesNotMatch()
542bb62bcaSAndreas Gohr    {
552bb62bcaSAndreas Gohr        $this->P->addMode('gfm_emphasis_strong', new GfmEmphasisStrong());
562bb62bcaSAndreas Gohr        $this->P->parse('*** foo***');
572bb62bcaSAndreas Gohr        $this->assertNotContains('emphasis_open', array_column($this->H->calls, 0));
582bb62bcaSAndreas Gohr    }
592bb62bcaSAndreas Gohr
602bb62bcaSAndreas Gohr    function testTrailingWhitespaceDoesNotMatch()
612bb62bcaSAndreas Gohr    {
622bb62bcaSAndreas Gohr        $this->P->addMode('gfm_emphasis_strong', new GfmEmphasisStrong());
632bb62bcaSAndreas Gohr        $this->P->parse('***foo ***');
642bb62bcaSAndreas Gohr        $this->assertNotContains('emphasis_open', array_column($this->H->calls, 0));
652bb62bcaSAndreas Gohr    }
662bb62bcaSAndreas Gohr
672bb62bcaSAndreas Gohr    function testDoesNotSpanParagraphBoundary()
682bb62bcaSAndreas Gohr    {
692bb62bcaSAndreas Gohr        $this->P->addMode('gfm_emphasis_strong', new GfmEmphasisStrong());
702bb62bcaSAndreas Gohr        $this->P->parse("***foo\n\nbar***");
712bb62bcaSAndreas Gohr        $this->assertNotContains('emphasis_open', array_column($this->H->calls, 0));
722bb62bcaSAndreas Gohr    }
732bb62bcaSAndreas Gohr
742bb62bcaSAndreas Gohr    function testLongerSymmetricRunDoesNotMatch()
752bb62bcaSAndreas Gohr    {
762bb62bcaSAndreas Gohr        // `****foo****` has 4 asterisks each side. The entry pattern requires
772bb62bcaSAndreas Gohr        // the opener run to be exactly 3 (via `(?<!\*)` and `(?!\*)` on the
782bb62bcaSAndreas Gohr        // closer), so this mode doesn't fire. It falls through to other
792bb62bcaSAndreas Gohr        // modes (which is tested via the full spec suite).
802bb62bcaSAndreas Gohr        $this->P->addMode('gfm_emphasis_strong', new GfmEmphasisStrong());
812bb62bcaSAndreas Gohr        $this->P->parse('****foo****');
822bb62bcaSAndreas Gohr        $this->assertNotContains('emphasis_open', array_column($this->H->calls, 0));
832bb62bcaSAndreas Gohr    }
842bb62bcaSAndreas Gohr
852bb62bcaSAndreas Gohr    function testAsymmetricDoesNotMatch()
862bb62bcaSAndreas Gohr    {
872bb62bcaSAndreas Gohr        // `***foo**` has 3 asterisks on the left but only 2 on the right.
882bb62bcaSAndreas Gohr        // The entry's closing-delimiter lookahead requires exactly 3 `*`s
892bb62bcaSAndreas Gohr        // not followed by another `*`, so there's no valid closer.
902bb62bcaSAndreas Gohr        $this->P->addMode('gfm_emphasis_strong', new GfmEmphasisStrong());
912bb62bcaSAndreas Gohr        $this->P->parse('***foo**');
922bb62bcaSAndreas Gohr        $this->assertNotContains('emphasis_open', array_column($this->H->calls, 0));
932bb62bcaSAndreas Gohr    }
942bb62bcaSAndreas Gohr
952bb62bcaSAndreas Gohr    function testSortValue()
962bb62bcaSAndreas Gohr    {
972bb62bcaSAndreas Gohr        $this->assertSame(65, (new GfmEmphasisStrong())->getSort());
982bb62bcaSAndreas Gohr    }
992bb62bcaSAndreas Gohr}
100