Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: davidpersson/markup
base: 5710a7a04f
...
head fork: davidpersson/markup
compare: c32c159276
  • 3 commits
  • 4 files changed
  • 0 commit comments
  • 1 contributor
Showing with 196 additions and 0 deletions.
  1. +5 −0 README
  2. +29 −0 bootstrap.php
  3. +27 −0 phpunit.xml
  4. +135 −0 tests/unit/MarkdownTest.php
View
5 README
@@ -39,6 +39,11 @@ Versions & Requirements
-----------------------
Version 1.0.0, PHP >=5.3.0
+Installation
+------------
+Classes in this library can be autoloaded. In order to enable autoloading you
+must bootstrap the library with the included `bootstrap.php` file.
+
Usage
-----
<?php
View
29 bootstrap.php
@@ -0,0 +1,29 @@
+<?php
+/**
+ * markup
+ *
+ * Copyright (c) 2012-2013 David Persson
+ *
+ * Distributed under the terms of the MIT License.
+ * Redistributions of files must retain the above copyright notice.
+ *
+ * @copyright 2011-2013 David Persson <nperson@gmx.de>
+ * @license http://opensource.org/licenses/mit-license The MIT License
+ * @link http://github.com/davidpersson/markdown
+ */
+
+spl_autoload_register(function($class) {
+ if (strpos($class, 'markup') === false) {
+ return false;
+ }
+ $name = str_replace('markup\\', '', $class);
+ $name = str_replace('\\', '/', $name);
+
+ $file = __DIR__ . '/src/' . $name . '.php';
+
+ if (file_exists($file)) {
+ require_once $file;
+ }
+});
+
+?>
View
27 phpunit.xml
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ markup
+
+ Copyright (c) 2012-2013 David Persson
+
+ Distributed under the terms of the MIT License.
+ Redistributions of files must retain the above copyright notice.
+
+ @copyright 2012-2013 David Persson <nperson@gmx.de>
+ @license http://opensource.org/licenses/mit-license The MIT License
+ @link http://github.com/davidpersson/markup
+-->
+<phpunit
+ bootstrap="bootstrap.php"
+ backupGlobals="false"
+ backupStaticAttributes="false"
+>
+ <testsuites>
+ <testsuite name="Library">
+ <directory suffix="Test.php">tests/unit</directory>
+ </testsuite>
+ </testsuites>
+ <php>
+ <includePath>./src</includePath>
+ </php>
+</phpunit>
View
135 tests/unit/MarkdownTest.php
@@ -0,0 +1,135 @@
+<?php
+/**
+ * markup
+ *
+ * Copyright (c) 2012-2013 David Persson
+ *
+ * Distributed under the terms of the MIT License.
+ * Redistributions of files must retain the above copyright notice.
+ *
+ * @copyright 2011-2013 David Persson <nperson@gmx.de>
+ * @license http://opensource.org/licenses/mit-license The MIT License
+ * @link http://github.com/davidpersson/markdown
+ */
+
+namespace markup\tests\unit;
+
+use markup\Markdown;
+
+class MarkdownTest extends \PHPUnit_Framework_TestCase {
+
+ public function testGfm() {
+ // Not touch single underscores inside words
+ /*
+ $data = "foo_bar";
+ $result = Markdown::gfm($data);
+ $expected = "foo_bar";
+ $this->assertEquals($expected, $result);
+ */
+
+ // Not touch underscores in code blocks
+ /*
+ $data = " foo_bar_baz";
+ $result = Markdown::gfm($data);
+ $expected = " foo_bar_baz";
+ $this->assertEquals($expected, $result);
+ */
+
+ // Not treat pre blocks with pre-text differently
+ /*
+ $data = <<<MARKDOWN
+
+
+<pre>
+this is `a\\_test` and this\\_too
+</pre>
+MARKDOWN;
+ $a = Markdown::gfm($data);
+ $b = <<<FLAVORED
+hmm<pre>
+this is `a\\_test` and this\\_too
+</pre>
+FLAVORED;
+ $this->assertEquals(substr($a, 2), substr($b, 3));
+ */
+
+ // Escape two or more underscroes inside words
+ /*
+ $data = "foo_bar_baz";
+ $result = Markdown::gfm($data);
+ $expected = "foo\_bar\_baz";
+ $this->assertEquals($expected, $result);
+ */
+
+ // Turn newlines into br tags in simple cases
+ $data = "foo\nbar";
+ $result = Markdown::gfm($data);
+ $expected = "foo \nbar";
+ $this->assertEquals($expected, $result);
+
+ // Convert newlines in all groups
+ $data = "apple\npear\norange\n\nruby\npython\nerlang";
+ $result = Markdown::gfm($data);
+ $expected = "apple \npear \norange\n\nruby \npython \nerlang";
+ $expected = str_replace(' ', '_', $expected);
+ $result = str_replace(' ', '_', $result);
+ $this->assertEquals($expected, $result);
+
+ // Convert newlines in even long groups
+ $data = "apple\npear\norange\nbanana\n\nruby\npython\nerlang";
+ $result = Markdown::gfm($data);
+ $expected = "apple \npear \norange \nbanana\n\nruby \npython \nerlang";
+ $this->assertEquals($expected, $result);
+
+ // Not convert newlines in lists
+ $data = "# foo\n# bar";
+ $result = Markdown::gfm($data);
+ $expected = "# foo\n# bar";
+ $this->assertEquals($expected, $result);
+
+ $data = "* foo\n* bar";
+ $result = Markdown::gfm($data);
+ $expected = "* foo\n* bar";
+ $this->assertEquals($expected, $result);
+
+ // Do not cut off "n"s
+ $data = "this is fun";
+ $result = Markdown::gfm($data);
+ $expected = "this is fun";
+ }
+
+ public function testParseWithDefaultPasses() {
+ $data = <<<MARKDOWN
+## This is a test
+
+some lines that contain
+a break or
+
+two more lines which behave differently
+
+* and
+* a nice
+* list
+MARKDOWN;
+ $result = Markdown::parse($data);
+ $expected = <<<HTML
+<h2>This is a test</h2>
+
+<p>some lines that contain<br />
+a break or</p>
+
+<p>two more lines which behave differently</p>
+
+<ul>
+<li>and</li>
+<li>a nice</li>
+<li>list</li>
+</ul>
+
+HTML;
+ $this->assertEquals($expected, $result);
+ }
+
+}
+
+?>

No commit comments for this range

Something went wrong with that request. Please try again.