Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added transform tests. #114

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 19 additions & 0 deletions phpunit.xml.dist
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit backupGlobals="false"
backupStaticAttributes="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
bootstrap="./tests/bootstrap.php"
>
<testsuites>
<testsuite name="Markdown">
<directory>./tests</directory>
</testsuite>
</testsuites>
</phpunit>
42 changes: 42 additions & 0 deletions tests/MardownTest.php
@@ -0,0 +1,42 @@
<?php

namespace Michelf;

class MardownTest extends \PHPUnit_Framework_TestCase
{
private static $md;

static public function setupBeforeClass()
{
self::$md = new MarkdownExtra;
}

public function transformProvider()
{
$ar = array();
$di = new \DirectoryIterator(__DIR__ . '/samples');
$ri = new \RegexIterator($di, '#\.md$#');

foreach ($ri as $file)
{
$path = $file->getPath();
$base = $file->getBaseName('.md');

$ar[$base] = array
(
file_get_contents($path . DIRECTORY_SEPARATOR . $base . '.md'),
file_get_contents($path . DIRECTORY_SEPARATOR . $base . '.html')
);
}

return $ar;
}

/**
* @dataProvider transformProvider
*/
public function testTransform($md, $html)
{
$this->assertEquals($html . "\n", self::$md->transform($md));
}
}
4 changes: 4 additions & 0 deletions tests/bootstrap.php
@@ -0,0 +1,4 @@
<?php

require_once __DIR__ . '/../Michelf/Markdown.php';
require_once __DIR__ . '/../Michelf/MarkdownExtra.php';
17 changes: 17 additions & 0 deletions tests/samples/attributes.html
@@ -0,0 +1,17 @@
<h1 id="header1">Header 1</h1>

<h2 id="header2">Header 2</h2>

<h2 class="main">Markdown</h2>

<h2 id="markdown" class="main highlight">Markdown</h2>

<p><a href="url" title="" id="id" class="class">link</a></p>

<p><img src="url" alt="img" title="" id="id" class="class" /></p>

<p><a href="url" title="optional title" id="id" class="class">link</a></p>

<p><a href="url" title="optional title" id="id" class="class">ref</a></p>

<p><img src="url" alt="img" title="optional title" id="id" class="class" /></p>
20 changes: 20 additions & 0 deletions tests/samples/attributes.md
@@ -0,0 +1,20 @@
Header 1 {#header1}
========

## Header 2 ## {#header2}

## Markdown ## {.main}

## Markdown ## {.main .highlight #markdown}

[link](url){#id .class}

![img](url){#id .class}

[link][ref]

[ref]

![img][ref]

[ref]: url "optional title" {#id .class}
1 change: 1 addition & 0 deletions tests/samples/automatic-email.html
@@ -0,0 +1 @@
<p><a href="&#109;&#x61;&#x69;&#108;&#x74;&#x6f;&#58;&#x61;&#x64;&#100;&#114;&#x65;&#115;&#115;&#x40;&#101;&#120;&#x61;m&#112;&#x6c;e&#46;&#x63;&#x6f;&#109;">&#x61;&#x64;&#100;&#114;&#x65;&#115;&#115;&#x40;&#101;&#120;&#x61;m&#112;&#x6c;e&#46;&#x63;&#x6f;&#109;</a></p>
1 change: 1 addition & 0 deletions tests/samples/automatic-email.md
@@ -0,0 +1 @@
<address@example.com>
5 changes: 5 additions & 0 deletions tests/samples/automatic-escaping.html
@@ -0,0 +1,5 @@
<p>&copy;</p>

<p>AT&amp;T</p>

<p>4 &lt; 5</p>
5 changes: 5 additions & 0 deletions tests/samples/automatic-escaping.md
@@ -0,0 +1,5 @@
&copy;

AT&T

4 < 5
1 change: 1 addition & 0 deletions tests/samples/automatic-link.html
@@ -0,0 +1 @@
<p><a href="http://example.com/">http://example.com/</a></p>
1 change: 1 addition & 0 deletions tests/samples/automatic-link.md
@@ -0,0 +1 @@
<http://example.com/>
1 change: 1 addition & 0 deletions tests/samples/backlash-escapes.html
@@ -0,0 +1 @@
<p>&#92;&#96;&#42;&#95;&#123;&#125;&#91;&#93;&#40;&#41;&#35;&#43;&#45;&#46;&#33;&#58;&#124;</p>
1 change: 1 addition & 0 deletions tests/samples/backlash-escapes.md
@@ -0,0 +1 @@
\\\`\*\_\{\}\[\]\(\)\#\+\-\.\!\:\|
13 changes: 13 additions & 0 deletions tests/samples/blockquote-and-more.html
@@ -0,0 +1,13 @@
<blockquote>
<h2>This is a header.</h2>

<ol>
<li>This is the first list item.</li>
<li>This is the second list item.</li>
</ol>

<p>Here's some example code:</p>

<pre><code>return shell_exec("echo $input | $markdown_script");
</code></pre>
</blockquote>
8 changes: 8 additions & 0 deletions tests/samples/blockquote-and-more.md
@@ -0,0 +1,8 @@
> ## This is a header.
>
> 1. This is the first list item.
> 2. This is the second list item.
>
> Here's some example code:
>
> return shell_exec("echo $input | $markdown_script");
8 changes: 8 additions & 0 deletions tests/samples/blockquote-lazy.html
@@ -0,0 +1,8 @@
<blockquote>
<p>This is a blockquote with two paragraphs. Lorem ipsum dolor sit amet,
consectetuer adipiscing elit. Aliquam hendrerit mi posuere lectus.
Vestibulum enim wisi, viverra nec, fringilla in, laoreet vitae, risus.</p>

<p>Donec sit amet nisl. Aliquam semper ipsum sit amet velit. Suspendisse
id sem consectetuer libero luctus adipiscing.</p>
</blockquote>
6 changes: 6 additions & 0 deletions tests/samples/blockquote-lazy.md
@@ -0,0 +1,6 @@
> This is a blockquote with two paragraphs. Lorem ipsum dolor sit amet,
consectetuer adipiscing elit. Aliquam hendrerit mi posuere lectus.
Vestibulum enim wisi, viverra nec, fringilla in, laoreet vitae, risus.

> Donec sit amet nisl. Aliquam semper ipsum sit amet velit. Suspendisse
id sem consectetuer libero luctus adipiscing.
9 changes: 9 additions & 0 deletions tests/samples/blockquote-nested.html
@@ -0,0 +1,9 @@
<blockquote>
<p>This is the first level of quoting.</p>

<blockquote>
<p>This is nested blockquote.</p>
</blockquote>

<p>Back to the first level.</p>
</blockquote>
5 changes: 5 additions & 0 deletions tests/samples/blockquote-nested.md
@@ -0,0 +1,5 @@
> This is the first level of quoting.
>
> > This is nested blockquote.
>
> Back to the first level.
8 changes: 8 additions & 0 deletions tests/samples/blockquote.html
@@ -0,0 +1,8 @@
<blockquote>
<p>This is a blockquote with two paragraphs. Lorem ipsum dolor sit amet,
consectetuer adipiscing elit. Aliquam hendrerit mi posuere lectus.
Vestibulum enim wisi, viverra nec, fringilla in, laoreet vitae, risus.</p>

<p>Donec sit amet nisl. Aliquam semper ipsum sit amet velit. Suspendisse
id sem consectetuer libero luctus adipiscing.</p>
</blockquote>
6 changes: 6 additions & 0 deletions tests/samples/blockquote.md
@@ -0,0 +1,6 @@
> This is a blockquote with two paragraphs. Lorem ipsum dolor sit amet,
> consectetuer adipiscing elit. Aliquam hendrerit mi posuere lectus.
> Vestibulum enim wisi, viverra nec, fringilla in, laoreet vitae, risus.
>
> Donec sit amet nisl. Aliquam semper ipsum sit amet velit. Suspendisse
> id sem consectetuer libero luctus adipiscing.
5 changes: 5 additions & 0 deletions tests/samples/code-backtick.html
@@ -0,0 +1,5 @@
<p><code>There is a literal backtick (`) here.</code></p>

<p>A single backtick in a code span: <code>`</code></p>

<p>A backtick-delimited string in a code span: <code>`foo`</code></p>
5 changes: 5 additions & 0 deletions tests/samples/code-backtick.md
@@ -0,0 +1,5 @@
``There is a literal backtick (`) here.``

A single backtick in a code span: `` ` ``

A backtick-delimited string in a code span: `` `foo` ``
1 change: 1 addition & 0 deletions tests/samples/code-escaped.html
@@ -0,0 +1 @@
<p><code>&amp;#8212;</code> is the decimal-encoded equivalent of <code>&amp;mdash;</code>.</p>
1 change: 1 addition & 0 deletions tests/samples/code-escaped.md
@@ -0,0 +1 @@
`&#8212;` is the decimal-encoded equivalent of `&mdash;`.
1 change: 1 addition & 0 deletions tests/samples/code-html.html
@@ -0,0 +1 @@
<p>Please don't use any <code>&lt;blink&gt;</code> tags.</p>
1 change: 1 addition & 0 deletions tests/samples/code-html.md
@@ -0,0 +1 @@
Please don't use any `<blink>` tags.
1 change: 1 addition & 0 deletions tests/samples/code.html
@@ -0,0 +1 @@
<p>Use the <code>printf()</code> function.</p>
1 change: 1 addition & 0 deletions tests/samples/code.md
@@ -0,0 +1 @@
Use the `printf()` function.
4 changes: 4 additions & 0 deletions tests/samples/codeblock-escape.html
@@ -0,0 +1,4 @@
<pre><code>&lt;div class="footer"&gt;
&amp;copy; 2004 Foo Corporation
&lt;/div&gt;
</code></pre>
3 changes: 3 additions & 0 deletions tests/samples/codeblock-escape.md
@@ -0,0 +1,3 @@
<div class="footer">
&copy; 2004 Foo Corporation
</div>
6 changes: 6 additions & 0 deletions tests/samples/codeblock-multiline.html
@@ -0,0 +1,6 @@
<p>Here is an example of AppleScript:</p>

<pre><code>tell application "Foo"
beep
end tell
</code></pre>
5 changes: 5 additions & 0 deletions tests/samples/codeblock-multiline.md
@@ -0,0 +1,5 @@
Here is an example of AppleScript:

tell application "Foo"
beep
end tell
4 changes: 4 additions & 0 deletions tests/samples/codeblock.html
@@ -0,0 +1,4 @@
<p>This is a normal paragraph:</p>

<pre><code>This is a code block.
</code></pre>
3 changes: 3 additions & 0 deletions tests/samples/codeblock.md
@@ -0,0 +1,3 @@
This is a normal paragraph:

This is a code block.
21 changes: 21 additions & 0 deletions tests/samples/embended-markdown.html
@@ -0,0 +1,21 @@
<div>

<p>Voici du <em>vrai</em> texte Markdown.</p>

</div>

<table>
<tr>
<td>Voici du <em>vrai</em> texte Markdown.</td>
</tr>
</table>

<table>
<tr>
<td>

<p>Voici du <em>vrai</em> texte Markdown.</p>

</td>
</tr>
</table>
15 changes: 15 additions & 0 deletions tests/samples/embended-markdown.md
@@ -0,0 +1,15 @@
<div markdown="1">
Voici du *vrai* texte Markdown.
</div>

<table>
<tr>
<td markdown="1">Voici du *vrai* texte Markdown.</td>
</tr>
</table>

<table>
<tr>
<td markdown="block">Voici du *vrai* texte Markdown.</td>
</tr>
</table>
1 change: 1 addition & 0 deletions tests/samples/emphasis-in-word.html
@@ -0,0 +1 @@
<p>un<em>frigging</em>believable</p>
1 change: 1 addition & 0 deletions tests/samples/emphasis-in-word.md
@@ -0,0 +1 @@
un*frigging*believable
7 changes: 7 additions & 0 deletions tests/samples/emphasis.html
@@ -0,0 +1,7 @@
<p><em>single asterisks</em></p>

<p><em>single underscores</em></p>

<p><strong>double asterisks</strong></p>

<p><strong>double underscores</strong></p>
7 changes: 7 additions & 0 deletions tests/samples/emphasis.md
@@ -0,0 +1,7 @@
*single asterisks*

_single underscores_

**double asterisks**

__double underscores__
2 changes: 2 additions & 0 deletions tests/samples/fenced-code-attributes.html
@@ -0,0 +1,2 @@
<pre><code id="example-1" class="html">&lt;p&gt;just an &lt;b&gt;example&lt;/b&gt;
</code></pre>
3 changes: 3 additions & 0 deletions tests/samples/fenced-code-attributes.md
@@ -0,0 +1,3 @@
~~~~~~~~~~~~~~~~~~~~~~~~~ {.html #example-1}
<p>just an <b>example</b>
~~~~~~~~~~~~~~~~~~~~~~~~~
2 changes: 2 additions & 0 deletions tests/samples/fenced-code-class.html
@@ -0,0 +1,2 @@
<pre><code class="html">&lt;p&gt;just an &lt;b&gt;example&lt;/b&gt;
</code></pre>
3 changes: 3 additions & 0 deletions tests/samples/fenced-code-class.md
@@ -0,0 +1,3 @@
~~~~~~~~~~~~~~~~~~~~~~~~~ .html
<p>just an <b>example</b>
~~~~~~~~~~~~~~~~~~~~~~~~~
6 changes: 6 additions & 0 deletions tests/samples/fenced-code.html
@@ -0,0 +1,6 @@
<p>Here's an example:</p>

<pre><code>function test() {
console.log("notice the blank line before this function?");
}
</code></pre>
7 changes: 7 additions & 0 deletions tests/samples/fenced-code.md
@@ -0,0 +1,7 @@
Here's an example:

~~~
function test() {
console.log("notice the blank line before this function?");
}
~~~