|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace Tempest\Highlight\Tests\Languages\BBCode; |
| 6 | + |
| 7 | +use PHPUnit\Framework\Attributes\DataProvider; |
| 8 | +use PHPUnit\Framework\TestCase; |
| 9 | +use Tempest\Highlight\Highlighter; |
| 10 | + |
| 11 | +class BBCodeLanguageTest extends TestCase |
| 12 | +{ |
| 13 | + #[DataProvider('provide_highlight_cases')] |
| 14 | + public function test_highlight(string $content, string $expected): void |
| 15 | + { |
| 16 | + $highlighter = new Highlighter(); |
| 17 | + |
| 18 | + $this->assertSame( |
| 19 | + $expected, |
| 20 | + $highlighter->parse($content, 'bbcode'), |
| 21 | + ); |
| 22 | + } |
| 23 | + |
| 24 | + public static function provide_highlight_cases(): iterable |
| 25 | + { |
| 26 | + return [ |
| 27 | + [<<<'TXT' |
| 28 | +[b]Hello World[/b] |
| 29 | +[i]italic text[/i] |
| 30 | +[u]underlined[/u] |
| 31 | +[s]strikethrough[/s] |
| 32 | +TXT, |
| 33 | + <<<'TXT' |
| 34 | +[<span class="hl-keyword">b</span>]Hello World[/<span class="hl-keyword">b</span>] |
| 35 | +[<span class="hl-keyword">i</span>]italic text[/<span class="hl-keyword">i</span>] |
| 36 | +[<span class="hl-keyword">u</span>]underlined[/<span class="hl-keyword">u</span>] |
| 37 | +[<span class="hl-keyword">s</span>]strikethrough[/<span class="hl-keyword">s</span>] |
| 38 | +TXT], |
| 39 | +
|
| 40 | + [<<<'TXT' |
| 41 | +[url=http://example.com]Click here[/url] |
| 42 | +[color=#ff0000]Red text[/color] |
| 43 | +[size=18]Big text[/size] |
| 44 | +[quote=John]Hello there[/quote] |
| 45 | +TXT, |
| 46 | + <<<'TXT' |
| 47 | +[<span class="hl-keyword">url</span>=<span class="hl-attribute">http://example.com</span>]Click here[/<span class="hl-keyword">url</span>] |
| 48 | +[<span class="hl-keyword">color</span>=<span class="hl-attribute">#ff0000</span>]Red text[/<span class="hl-keyword">color</span>] |
| 49 | +[<span class="hl-keyword">size</span>=<span class="hl-attribute">18</span>]Big text[/<span class="hl-keyword">size</span>] |
| 50 | +[<span class="hl-keyword">quote</span>=<span class="hl-attribute">John</span>]Hello there[/<span class="hl-keyword">quote</span>] |
| 51 | +TXT], |
| 52 | +
|
| 53 | + [<<<'TXT' |
| 54 | +[list] |
| 55 | +[*]First item |
| 56 | +[*]Second item |
| 57 | +[*]Third item |
| 58 | +[/list] |
| 59 | +TXT, |
| 60 | + <<<'TXT' |
| 61 | +[<span class="hl-keyword">list</span>] |
| 62 | +[<span class="hl-keyword">*</span>]First item |
| 63 | +[<span class="hl-keyword">*</span>]Second item |
| 64 | +[<span class="hl-keyword">*</span>]Third item |
| 65 | +[/<span class="hl-keyword">list</span>] |
| 66 | +TXT], |
| 67 | +
|
| 68 | + [<<<'TXT' |
| 69 | +[img]http://example.com/image.png[/img] |
| 70 | +[code]echo "hello";[/code] |
| 71 | +TXT, |
| 72 | + <<<'TXT' |
| 73 | +[<span class="hl-keyword">img</span>]http://example.com/image.png[/<span class="hl-keyword">img</span>] |
| 74 | +[<span class="hl-keyword">code</span>]echo "hello";[/<span class="hl-keyword">code</span>] |
| 75 | +TXT], |
| 76 | + ]; |
| 77 | + } |
| 78 | +} |
0 commit comments