|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +/* |
| 6 | + * This file is part of the league/commonmark package. |
| 7 | + * |
| 8 | + * (c) Colin O'Dell <[email protected]> and uAfrica.com (http://uafrica.com) |
| 9 | + * |
| 10 | + * For the full copyright and license information, please view the LICENSE |
| 11 | + * file that was distributed with this source code. |
| 12 | + */ |
| 13 | + |
| 14 | +namespace League\CommonMark\Tests\Functional\Extension\Highlight; |
| 15 | + |
| 16 | +use League\CommonMark\Environment\Environment; |
| 17 | +use League\CommonMark\Extension\CommonMark\CommonMarkCoreExtension; |
| 18 | +use League\CommonMark\Extension\Highlight\HighlightExtension; |
| 19 | +use League\CommonMark\Parser\MarkdownParser; |
| 20 | +use League\CommonMark\Renderer\HtmlRenderer; |
| 21 | +use PHPUnit\Framework\TestCase; |
| 22 | + |
| 23 | +final class HighlightExtensionTest extends TestCase |
| 24 | +{ |
| 25 | + /** |
| 26 | + * @dataProvider dataForIntegrationTest |
| 27 | + */ |
| 28 | + public function testMark(string $string, string $expected): void |
| 29 | + { |
| 30 | + $environment = new Environment(); |
| 31 | + $environment->addExtension(new CommonMarkCoreExtension()); |
| 32 | + $environment->addExtension(new HighlightExtension()); |
| 33 | + |
| 34 | + $parser = new MarkdownParser($environment); |
| 35 | + $renderer = new HtmlRenderer($environment); |
| 36 | + |
| 37 | + $document = $parser->parse($string); |
| 38 | + |
| 39 | + $html = (string) $renderer->renderDocument($document); |
| 40 | + |
| 41 | + $this->assertSame($expected, $html); |
| 42 | + } |
| 43 | + |
| 44 | + /** |
| 45 | + * @return array<array<string>> |
| 46 | + */ |
| 47 | + public static function dataForIntegrationTest(): array |
| 48 | + { |
| 49 | + return [ |
| 50 | + ['Hello, ==world!==', "<p>Hello, <mark>world!</mark></p>\n"], |
| 51 | + ['This is a test without any marks', "<p>This is a test without any marks</p>\n"], |
| 52 | + ['This is a test with ==valid== marks', "<p>This is a test with <mark>valid</mark> marks</p>\n"], |
| 53 | + ['This is a test `with` ==valid== marks', "<p>This is a test <code>with</code> <mark>valid</mark> marks</p>\n"], |
| 54 | + ['This is a ==unit== integration test', "<p>This is a <mark>unit</mark> integration test</p>\n"], |
| 55 | + ['==Mark== on the left', "<p><mark>Mark</mark> on the left</p>\n"], |
| 56 | + ['Mark on the ==right==', "<p>Mark on the <mark>right</mark></p>\n"], |
| 57 | + ['==Mark everywhere==', "<p><mark>Mark everywhere</mark></p>\n"], |
| 58 | + ['This ==test has no ending match', "<p>This ==test has no ending match</p>\n"], |
| 59 | + ['This ==test=== has mismatched equal signs', "<p>This ==test=== has mismatched equal signs</p>\n"], |
| 60 | + ['This ===test== also has mismatched equal signs', "<p>This ===test== also has mismatched equal signs</p>\n"], |
| 61 | + ['This one has ===three=== equal signs', "<p>This one has ===three=== equal signs</p>\n"], |
| 62 | + ["This ==has a\n\nnew paragraph==.", "<p>This ==has a</p>\n<p>new paragraph==.</p>\n"], |
| 63 | + ['Hello == == world', "<p>Hello == == world</p>\n"], |
| 64 | + ['This **is ==a little** test of mismatched delimiters==', "<p>This <strong>is ==a little</strong> test of mismatched delimiters==</p>\n"], |
| 65 | + ['Из: твоя ==тест== ветка', "<p>Из: твоя <mark>тест</mark> ветка</p>\n"], |
| 66 | + ['This one combines ==nested ==mark== text==', "<p>This one combines <mark>nested <mark>mark</mark> text</mark></p>\n"], |
| 67 | + ['Here we have **emphasized text containing a ==mark==**', "<p>Here we have <strong>emphasized text containing a <mark>mark</mark></strong></p>\n"], |
| 68 | + ['Four trailing equal signs ====', "<p>Four trailing equal signs ====</p>\n"], |
| 69 | + ['==Unmatched left', "<p>==Unmatched left</p>\n"], |
| 70 | + ['Unmatched right==', "<p>Unmatched right==</p>\n"], |
| 71 | + ['==foo=bar==', "<p><mark>foo=bar</mark></p>\n"], |
| 72 | + ['==foo==bar==', "<p><mark>foo</mark>bar==</p>\n"], |
| 73 | + ['==foo===bar==', "<p><mark>foo===bar</mark></p>\n"], |
| 74 | + ['==foo====bar==', "<p><mark>foo====bar</mark></p>\n"], |
| 75 | + ['==foo=====bar==', "<p><mark>foo=====bar</mark></p>\n"], |
| 76 | + ['==foo======bar==', "<p><mark>foo======bar</mark></p>\n"], |
| 77 | + ['==foo=======bar==', "<p><mark>foo=======bar</mark></p>\n"], |
| 78 | + ['> inside a ==blockquote==', "<blockquote>\n<p>inside a <mark>blockquote</mark></p>\n</blockquote>\n"], |
| 79 | + ]; |
| 80 | + } |
| 81 | +} |
0 commit comments