Add Standard Markdown testsuite.
You could run the Parsedown testsuite only with: phpunit --testsuite ParsedownTests And you could run the Standard Markdown one with: phpunit --testsuite StandardMarkdown See more at http://standardmarkdown.com/
This commit is contained in:
parent
0220a93010
commit
6f1fac9823
|
@ -7,4 +7,5 @@ php:
|
||||||
- 5.3
|
- 5.3
|
||||||
- 5.2
|
- 5.2
|
||||||
- hhvm
|
- hhvm
|
||||||
|
|
||||||
|
before_script: curl -sS https://raw.githubusercontent.com/jgm/stmd/master/spec.txt>test/standard-markdown/spec.txt
|
||||||
|
|
|
@ -1,8 +1,11 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<phpunit bootstrap="test/bootstrap.php" colors="true">
|
<phpunit bootstrap="test/bootstrap.php" colors="true">
|
||||||
<testsuites>
|
<testsuites>
|
||||||
<testsuite>
|
<testsuite name="ParsedownTests">
|
||||||
<file>test/Test.php</file>
|
<file>test/Test.php</file>
|
||||||
|
</testsuite>
|
||||||
|
<testsuite name="StandardMarkdown">
|
||||||
|
<file>test/standard-markdown/StandardMarkdownTest.php</file>
|
||||||
</testsuite>
|
</testsuite>
|
||||||
</testsuites>
|
</testsuites>
|
||||||
</phpunit>
|
</phpunit>
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
spec.txt
|
|
@ -0,0 +1,60 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
class StandardMarkdownTest extends PHPUnit_Framework_TestCase
|
||||||
|
{
|
||||||
|
const SPEC_FILEPATH = 'spec.txt';
|
||||||
|
|
||||||
|
const SPEC_URL = 'https://raw.githubusercontent.com/jgm/stmd/master/spec.txt';
|
||||||
|
|
||||||
|
public function getStandardMarkdownRules()
|
||||||
|
{
|
||||||
|
if (is_file(self::SPEC_FILEPATH) and is_readable(self::SPEC_FILEPATH)) {
|
||||||
|
$spec = file_get_contents(self::SPEC_FILEPATH);
|
||||||
|
} else {
|
||||||
|
$spec = file_get_contents(self::SPEC_URL);
|
||||||
|
}
|
||||||
|
|
||||||
|
$tests = array();
|
||||||
|
$testsCount = 0;
|
||||||
|
$currentSection = '';
|
||||||
|
|
||||||
|
$spec = preg_replace('/^<!-- END TESTS -->(.|[\n])*/m', '', $spec);
|
||||||
|
|
||||||
|
preg_replace_callback(
|
||||||
|
'/^\.\n([\s\S]*?)^\.\n([\s\S]*?)^\.$|^#{1,6} *(.*)$/m',
|
||||||
|
function($matches) use (&$tests, &$currentSection, &$testsCount) {
|
||||||
|
if (isset($matches[3]) and $matches[3]) {
|
||||||
|
$currentSection = $matches[3];
|
||||||
|
} else {
|
||||||
|
$testsCount++;
|
||||||
|
$markdown = preg_replace('/→/', "\t", $matches[1]);
|
||||||
|
$tests []= array(
|
||||||
|
$markdown, // markdown
|
||||||
|
$matches[2], // html
|
||||||
|
$currentSection, // section
|
||||||
|
$testsCount, // number
|
||||||
|
);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
$spec
|
||||||
|
);
|
||||||
|
|
||||||
|
return $tests;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider getStandardMarkdownRules
|
||||||
|
*/
|
||||||
|
public function testAgainstStandardMarkdown($markdown, $expectedHtml, $section, $number)
|
||||||
|
{
|
||||||
|
$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);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue