xref: /dokuwiki/_test/tests/Parsing/ParserMode/GfmEmphasisStrongUnderscoreTest.php (revision fe58309edafb067d90f3f40ef3d416100d558a04)
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    public function testBasic()
22    {
23        $this->P->addMode('gfm_emphasis_strong_underscore', new GfmEmphasisStrongUnderscore());
24        $this->P->parse('Foo ___Bar___ Baz');
25
26        $calls = [
27            ['document_start', []],
28            ['p_open', []],
29            ['cdata', ["\nFoo "]],
30            ['emphasis_open', []],
31            ['strong_open', []],
32            ['cdata', ['Bar']],
33            ['strong_close', []],
34            ['emphasis_close', []],
35            ['cdata', [' Baz']],
36            ['p_close', []],
37            ['document_end', []],
38        ];
39        $this->assertCalls($calls, $this->H->calls);
40    }
41
42    public function testSingleCharacter()
43    {
44        $this->P->addMode('gfm_emphasis_strong_underscore', new GfmEmphasisStrongUnderscore());
45        $this->P->parse('___a___');
46        $this->assertContains('emphasis_open', array_column($this->H->calls, 0));
47        $this->assertContains('strong_open', array_column($this->H->calls, 0));
48    }
49
50    public function testLeadingWhitespaceDoesNotMatch()
51    {
52        $this->P->addMode('gfm_emphasis_strong_underscore', new GfmEmphasisStrongUnderscore());
53        $this->P->parse('___ foo___');
54        $this->assertNotContains('emphasis_open', array_column($this->H->calls, 0));
55    }
56
57    public function testTrailingWhitespaceDoesNotMatch()
58    {
59        $this->P->addMode('gfm_emphasis_strong_underscore', new GfmEmphasisStrongUnderscore());
60        $this->P->parse('___foo ___');
61        $this->assertNotContains('emphasis_open', array_column($this->H->calls, 0));
62    }
63
64    public function testDoesNotSpanParagraphBoundary()
65    {
66        $this->P->addMode('gfm_emphasis_strong_underscore', new GfmEmphasisStrongUnderscore());
67        $this->P->parse("___foo\n\nbar___");
68        $this->assertNotContains('emphasis_open', array_column($this->H->calls, 0));
69    }
70
71    public function testLongerSymmetricRunDoesNotMatch()
72    {
73        $this->P->addMode('gfm_emphasis_strong_underscore', new GfmEmphasisStrongUnderscore());
74        $this->P->parse('____foo____');
75        $this->assertNotContains('emphasis_open', array_column($this->H->calls, 0));
76    }
77
78    public function testAsymmetricDoesNotMatch()
79    {
80        $this->P->addMode('gfm_emphasis_strong_underscore', new GfmEmphasisStrongUnderscore());
81        $this->P->parse('___foo__');
82        $this->assertNotContains('emphasis_open', array_column($this->H->calls, 0));
83    }
84
85    public function testIntrawordDoesNotMatch()
86    {
87        $this->P->addMode('gfm_emphasis_strong_underscore', new GfmEmphasisStrongUnderscore());
88        $this->P->parse('abc___foo___');
89        $this->assertNotContains('emphasis_open', array_column($this->H->calls, 0));
90    }
91
92    public function testMultibyteIntrawordDoesNotMatch()
93    {
94        $this->P->addMode('gfm_emphasis_strong_underscore', new GfmEmphasisStrongUnderscore());
95        $this->P->parse('für___etwas___');
96        $this->assertNotContains('emphasis_open', array_column($this->H->calls, 0));
97    }
98
99    public function testMultibyteContentInside()
100    {
101        $this->P->addMode('gfm_emphasis_strong_underscore', new GfmEmphasisStrongUnderscore());
102        $this->P->parse('foo ___für___ bar');
103        $this->assertContains('emphasis_open', array_column($this->H->calls, 0));
104        $this->assertContains('strong_open', array_column($this->H->calls, 0));
105    }
106
107    public function testSortValue()
108    {
109        $this->assertSame(65, (new GfmEmphasisStrongUnderscore())->getSort());
110    }
111
112    public function testRejectedOpenerBeforeValidSpanStaysLiteral()
113    {
114        $this->P->addMode('gfm_emphasis_strong_underscore', new GfmEmphasisStrongUnderscore());
115        $this->P->parse('___ foo ___bar___');
116        $this->assertContains('emphasis_open', array_column($this->H->calls, 0));
117        $this->assertStringContainsString('___ foo ', $this->H->calls[2][1][0]);
118    }
119}
120