1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
|
<?php
declare(strict_types=1);
/*
* This file is part of the league/commonmark package.
*
* (c) Colin O'Dell <colinodell@gmail.com>
*
* Original code based on the CommonMark JS reference parser (https://bitly.com/commonmark-js)
* - (c) John MacFarlane
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace League\CommonMark\Tests\Functional;
use League\CommonMark\CommonMarkConverter;
use League\CommonMark\MarkdownConverter;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
abstract class AbstractSpecTestCase extends TestCase
{
protected MarkdownConverter $converter;
protected function setUp(): void
{
$this->converter = new CommonMarkConverter();
}
/**
* @param string $input Markdown to parse
* @param string $output Expected result
*/
#[DataProvider('dataProvider')]
public function testSpecExample(string $input, string $output, string $type = '', string $section = '', int $number = -1): void
{
$actualResult = (string) $this->converter->convert($input);
$failureMessage = 'Unexpected result:';
$failureMessage .= "\n=== markdown ===============\n" . $this->showSpaces($input);
$failureMessage .= "\n=== expected ===============\n" . $this->showSpaces($output);
$failureMessage .= "\n=== got ====================\n" . $this->showSpaces($actualResult);
$this->assertEquals($output, $actualResult, $failureMessage);
}
abstract public static function dataProvider(): \Generator;
private function showSpaces(string $str): string
{
return \strtr($str, ["\t" => '→', ' ' => '␣']);
}
}
|