1
0
mirror of https://github.com/erusev/parsedown.git synced 2023-08-10 21:13:06 +03:00
parsedown/test/CommonMarkTest.php

64 lines
1.8 KiB
PHP
Raw Normal View History

<?php
/**
* Test Parsedown against the CommonMark spec.
*
* Some code based on the original JavaScript test runner by jgm.
*
2014-09-14 01:02:11 +04:00
* @link http://commonmark.org/ CommonMark
* @link http://git.io/8WtRvQ JavaScript test runner
*/
class CommonMarkTest extends PHPUnit_Framework_TestCase
{
const SPEC_URL = 'https://raw.githubusercontent.com/jgm/stmd/master/spec.txt';
2014-11-29 22:34:46 +03:00
/**
* @dataProvider data
* @param $markdown
* @param $expectedHtml
*/
function test_($markdown, $expectedHtml)
{
$parsedown = new Parsedown();
$actualHtml = $parsedown->text($markdown);
# trim for better compatibility of the HTML output
$actualHtml = trim($actualHtml);
$expectedHtml = trim($expectedHtml);
$this->assertEquals($expectedHtml, $actualHtml);
}
function data()
{
2014-11-29 21:18:23 +03:00
$spec = file_get_contents(self::SPEC_URL);
2014-11-29 22:34:46 +03:00
$spec = strstr($spec, '<!-- END TESTS -->', true);
$tests = array();
2014-11-29 22:34:46 +03:00
$testCount = 0;
$currentSection = '';
preg_replace_callback(
'/^\.\n([\s\S]*?)^\.\n([\s\S]*?)^\.$|^#{1,6} *(.*)$/m',
2014-11-29 22:34:46 +03:00
function($matches) use ( & $tests, & $currentSection, & $testCount) {
if (isset($matches[3]) and $matches[3]) {
$currentSection = $matches[3];
} else {
2014-11-29 22:34:46 +03:00
$testCount++;
$markdown = preg_replace('/→/', "\t", $matches[1]);
$tests []= array(
2014-11-29 22:34:46 +03:00
$markdown, # markdown
$matches[2], # html
$currentSection, # section
$testCount, # number
);
}
},
$spec
);
return $tests;
}
}