diff --git a/composer.json b/composer.json index a13bb0f5..9de56ca2 100644 --- a/composer.json +++ b/composer.json @@ -28,7 +28,8 @@ "phpstan/phpstan-deprecation-rules": "^0.10", "phpstan/phpstan-phpunit": "^0.10", "phpstan/phpstan-strict-rules": "^0.10", - "phpunit/phpunit": "^7.0" + "phpunit/phpunit": "^7.0", + "gajus/dindent": "^2.0.2" }, "autoload": { "psr-4": { diff --git a/composer.lock b/composer.lock index 76f80f46..327f8f08 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "02d81bf59fb882c99a726ee8e1972313", + "content-hash": "9a9422bcd2ec96aca6a4f646ac10f86c", "packages": [ { "name": "doctrine/event-manager", @@ -543,6 +543,51 @@ ], "time": "2017-07-22T11:58:36+00:00" }, + { + "name": "gajus/dindent", + "version": "2.0.2", + "source": { + "type": "git", + "url": "https://github.com/gajus/dindent.git", + "reference": "d81c3a6f78fbe1ab26f5e753098bbbef6b6a9f3c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/gajus/dindent/zipball/d81c3a6f78fbe1ab26f5e753098bbbef6b6a9f3c", + "reference": "d81c3a6f78fbe1ab26f5e753098bbbef6b6a9f3c", + "shasum": "" + }, + "require": { + "php": ">=5.3" + }, + "require-dev": { + "satooshi/php-coveralls": "dev-master" + }, + "type": "library", + "autoload": { + "psr-4": { + "Gajus\\Dindent\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Gajus Kuizinas", + "email": "gk@anuary.com" + } + ], + "description": "HTML indentation library for development and testing.", + "homepage": "https://github.com/gajus/dindent", + "keywords": [ + "format", + "html", + "indent" + ], + "time": "2014-10-08T10:03:04+00:00" + }, { "name": "jean85/pretty-package-versions", "version": "1.2", diff --git a/tests/Functional/FunctionalTest.php b/tests/Functional/FunctionalTest.php new file mode 100644 index 00000000..d2151570 --- /dev/null +++ b/tests/Functional/FunctionalTest.php @@ -0,0 +1,135 @@ +expectException($exceptionClass); + + $expectedExceptionMessage = $expectedLines; + unset($expectedExceptionMessage[0]); + $expectedExceptionMessage = implode("\n", $expectedExceptionMessage); + + $this->expectExceptionMessage($expectedExceptionMessage); + } + + $document = $parser->parse($rst); + + $rendered = $document->$renderMethod(); + + if ($format === Format::HTML) { + $indenter = new Indenter(); + $rendered = $indenter->indent($rendered); + } + + self::assertSame( + $this->trimTrailingWhitespace($expected), + $this->trimTrailingWhitespace($rendered) + ); + } + + /** + * @return mixed[] + */ + public function getFunctionalTests() : array + { + $finder = new Finder(); + $finder + ->files() + ->in(__DIR__ . '/tests') + ->name('*.rst'); + + $tests = []; + + foreach ($finder as $file) { + $rst = $file->getContents(); + $filename = $file->getFilename(); + $basename = basename($filename, '.rst'); + + $dir = $file->getPathInfo(); + + $formats = [Format::HTML, Format::LATEX]; + + foreach ($formats as $format) { + $formatPath = $dir . '/' . $basename . '.' . $format; + + if (! file_exists($formatPath)) { + continue; + } + + $expected = file_get_contents($formatPath); + + if ($expected === false) { + continue; + } + + $configuration = new Configuration(); + $configuration->setFileExtension($format); + + $kernel = new Kernel($configuration); + $parser = new Parser($kernel); + + $environment = $parser->getEnvironment(); + $environment->setCurrentDirectory(__DIR__ . '/tests/' . $basename); + + $renderMethod = in_array($basename, self::RENDER_DOCUMENT_FILES, true) + ? 'renderDocument' + : 'render'; + + $tests[] = [$basename, $parser, $renderMethod, $format, $rst, trim($expected)]; + } + } + + return $tests; + } + + private function trimTrailingWhitespace(string $string) : string + { + $lines = explode("\n", $string); + + $lines = array_map(static function (string $line) { + return rtrim($line); + }, $lines); + + return trim(implode("\n", $lines)); + } +} diff --git a/tests/Functional/tests/anchor-failure/anchor-failure.html b/tests/Functional/tests/anchor-failure/anchor-failure.html new file mode 100644 index 00000000..fe92f3a2 --- /dev/null +++ b/tests/Functional/tests/anchor-failure/anchor-failure.html @@ -0,0 +1 @@ +

@Anchor Section

diff --git a/tests/HTML/files/anchor-failure.rst b/tests/Functional/tests/anchor-failure/anchor-failure.rst similarity index 100% rename from tests/HTML/files/anchor-failure.rst rename to tests/Functional/tests/anchor-failure/anchor-failure.rst diff --git a/tests/Functional/tests/anchor/anchor.html b/tests/Functional/tests/anchor/anchor.html new file mode 100644 index 00000000..c25547f0 --- /dev/null +++ b/tests/Functional/tests/anchor/anchor.html @@ -0,0 +1,8 @@ +
+

+ Anchors +

+ + +

go to lists

+
diff --git a/tests/HTML/files/anchor.rst b/tests/Functional/tests/anchor/anchor.rst similarity index 100% rename from tests/HTML/files/anchor.rst rename to tests/Functional/tests/anchor/anchor.rst diff --git a/tests/Functional/tests/anchor/anchor.tex b/tests/Functional/tests/anchor/anchor.tex new file mode 100644 index 00000000..c0c33e22 --- /dev/null +++ b/tests/Functional/tests/anchor/anchor.tex @@ -0,0 +1,3 @@ +\chapter{Anchors} +\label{lists} +\ref{#lists} diff --git a/tests/Functional/tests/anonymous/anonymous.html b/tests/Functional/tests/anonymous/anonymous.html new file mode 100644 index 00000000..7563db24 --- /dev/null +++ b/tests/Functional/tests/anonymous/anonymous.html @@ -0,0 +1 @@ +

I love GitHub

diff --git a/tests/HTML/files/anonymous.rst b/tests/Functional/tests/anonymous/anonymous.rst similarity index 95% rename from tests/HTML/files/anonymous.rst rename to tests/Functional/tests/anonymous/anonymous.rst index 75653d4e..7f510674 100644 --- a/tests/HTML/files/anonymous.rst +++ b/tests/Functional/tests/anonymous/anonymous.rst @@ -1,5 +1,3 @@ - I love GitHub__ .. __: http://www.github.com/ - diff --git a/tests/Functional/tests/anonymous/anonymous.tex b/tests/Functional/tests/anonymous/anonymous.tex new file mode 100644 index 00000000..6452be8e --- /dev/null +++ b/tests/Functional/tests/anonymous/anonymous.tex @@ -0,0 +1 @@ +I love \href{http://www.github.com/}{GitHub} diff --git a/tests/Functional/tests/bom/bom.html b/tests/Functional/tests/bom/bom.html new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/tests/Functional/tests/bom/bom.html @@ -0,0 +1 @@ + diff --git a/tests/HTML/files/bom.rst b/tests/Functional/tests/bom/bom.rst similarity index 100% rename from tests/HTML/files/bom.rst rename to tests/Functional/tests/bom/bom.rst diff --git a/tests/Functional/tests/class-directive/class-directive.html b/tests/Functional/tests/class-directive/class-directive.html new file mode 100644 index 00000000..37ec2b10 --- /dev/null +++ b/tests/Functional/tests/class-directive/class-directive.html @@ -0,0 +1,35 @@ +

Test special-paragraph1 1.

+

Test special-paragraph1 2.

+

Test special-paragraph2 1.

+

Test special-paragraph2 2.

+
+

Test

+
+ +

Weird class names.

+

Level 1

+
+

Level2 1

+

Level2 2

+
+
+
term 1
+
Definition 1
+
+ + + + + + + + + + + + + +
First colSecond col
Second rowOther col
diff --git a/tests/HTML/files/class-directive.rst b/tests/Functional/tests/class-directive/class-directive.rst similarity index 100% rename from tests/HTML/files/class-directive.rst rename to tests/Functional/tests/class-directive/class-directive.rst diff --git a/tests/Functional/tests/code-block-lastline/code-block-lastline.html b/tests/Functional/tests/code-block-lastline/code-block-lastline.html new file mode 100644 index 00000000..26c6a075 --- /dev/null +++ b/tests/Functional/tests/code-block-lastline/code-block-lastline.html @@ -0,0 +1,3 @@ +
A
+B C
+
diff --git a/tests/Functional/tests/code-block-lastline/code-block-lastline.rst b/tests/Functional/tests/code-block-lastline/code-block-lastline.rst new file mode 100644 index 00000000..ae6adb94 --- /dev/null +++ b/tests/Functional/tests/code-block-lastline/code-block-lastline.rst @@ -0,0 +1,5 @@ +.. code-block:: + + A + B + C diff --git a/tests/Functional/tests/code-block/code-block.html b/tests/Functional/tests/code-block/code-block.html new file mode 100644 index 00000000..7f9e7768 --- /dev/null +++ b/tests/Functional/tests/code-block/code-block.html @@ -0,0 +1,4 @@ +
#include <iostream> using namespace std; int main(void)
+{ cout << "Hello world!" << endl;
+}
+
diff --git a/tests/HTML/files/code-block.rst b/tests/Functional/tests/code-block/code-block.rst similarity index 99% rename from tests/HTML/files/code-block.rst rename to tests/Functional/tests/code-block/code-block.rst index 31bde181..e2c5735d 100644 --- a/tests/HTML/files/code-block.rst +++ b/tests/Functional/tests/code-block/code-block.rst @@ -1,4 +1,3 @@ - .. code-block:: c++ #include diff --git a/tests/Functional/tests/code-java/code-java.html b/tests/Functional/tests/code-java/code-java.html new file mode 100644 index 00000000..60e0d5cf --- /dev/null +++ b/tests/Functional/tests/code-java/code-java.html @@ -0,0 +1,4 @@ +
protected void f()
+{
+}
+
diff --git a/tests/HTML/files/code-java.rst b/tests/Functional/tests/code-java/code-java.rst similarity index 98% rename from tests/HTML/files/code-java.rst rename to tests/Functional/tests/code-java/code-java.rst index 6787df9f..9a16919b 100644 --- a/tests/HTML/files/code-java.rst +++ b/tests/Functional/tests/code-java/code-java.rst @@ -1,4 +1,3 @@ - .. code-block:: java protected void f() diff --git a/tests/Functional/tests/code-list/code-list.html b/tests/Functional/tests/code-list/code-list.html new file mode 100644 index 00000000..e4c553f6 --- /dev/null +++ b/tests/Functional/tests/code-list/code-list.html @@ -0,0 +1,3 @@ +
* Testing
+* Hey
+
diff --git a/tests/HTML/files/code-list.rst b/tests/Functional/tests/code-list/code-list.rst similarity index 98% rename from tests/HTML/files/code-list.rst rename to tests/Functional/tests/code-list/code-list.rst index 131e87b8..3d6a0340 100644 --- a/tests/HTML/files/code-list.rst +++ b/tests/Functional/tests/code-list/code-list.rst @@ -1,4 +1,3 @@ - .. This should not be interpreted as a list .. code-block:: diff --git a/tests/Functional/tests/code-with-whitespace/code-with-whitespace.html b/tests/Functional/tests/code-with-whitespace/code-with-whitespace.html new file mode 100644 index 00000000..8379a491 --- /dev/null +++ b/tests/Functional/tests/code-with-whitespace/code-with-whitespace.html @@ -0,0 +1,4 @@ +
+
+

Test code block with whitespace.

+
diff --git a/tests/Functional/tests/code-with-whitespace/code-with-whitespace.rst b/tests/Functional/tests/code-with-whitespace/code-with-whitespace.rst new file mode 100644 index 00000000..7c4b0b33 --- /dev/null +++ b/tests/Functional/tests/code-with-whitespace/code-with-whitespace.rst @@ -0,0 +1,3 @@ +:: + + Test code block with whitespace. diff --git a/tests/Functional/tests/code/code.html b/tests/Functional/tests/code/code.html new file mode 100644 index 00000000..0c9e2364 --- /dev/null +++ b/tests/Functional/tests/code/code.html @@ -0,0 +1,3 @@ +

Code block:

+
This is a code block You hou!
+
diff --git a/tests/HTML/files/code.rst b/tests/Functional/tests/code/code.rst similarity index 98% rename from tests/HTML/files/code.rst rename to tests/Functional/tests/code/code.rst index 2dd00a2f..0ad7cea2 100644 --- a/tests/HTML/files/code.rst +++ b/tests/Functional/tests/code/code.rst @@ -1,4 +1,3 @@ - Code block:: This is a code block diff --git a/tests/Functional/tests/code/code.tex b/tests/Functional/tests/code/code.tex new file mode 100644 index 00000000..b299bd01 --- /dev/null +++ b/tests/Functional/tests/code/code.tex @@ -0,0 +1,8 @@ +Code block: +\lstset{language=} +\begin{lstlisting} +This is a code block + +You hou! + +\end{lstlisting} diff --git a/tests/Functional/tests/comment-3/comment-3.html b/tests/Functional/tests/comment-3/comment-3.html new file mode 100644 index 00000000..9133b5ec --- /dev/null +++ b/tests/Functional/tests/comment-3/comment-3.html @@ -0,0 +1 @@ +

... This is not a comment!

diff --git a/tests/HTML/files/comment-3.rst b/tests/Functional/tests/comment-3/comment-3.rst similarity index 96% rename from tests/HTML/files/comment-3.rst rename to tests/Functional/tests/comment-3/comment-3.rst index d8c7a28c..5922a5e0 100644 --- a/tests/HTML/files/comment-3.rst +++ b/tests/Functional/tests/comment-3/comment-3.rst @@ -1,4 +1,2 @@ - .. This is a comment! ... This is not a comment! - diff --git a/tests/Functional/tests/comment/comment.html b/tests/Functional/tests/comment/comment.html new file mode 100644 index 00000000..bb04776e --- /dev/null +++ b/tests/Functional/tests/comment/comment.html @@ -0,0 +1,2 @@ +

Text before

+

Text after

diff --git a/tests/Functional/tests/comment/comment.rst b/tests/Functional/tests/comment/comment.rst new file mode 100644 index 00000000..8c904de5 --- /dev/null +++ b/tests/Functional/tests/comment/comment.rst @@ -0,0 +1,3 @@ +Text before +.. Testing comment +Text after diff --git a/tests/Functional/tests/comments/comments.html b/tests/Functional/tests/comments/comments.html new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/tests/Functional/tests/comments/comments.html @@ -0,0 +1 @@ + diff --git a/tests/HTML/files/comments.rst b/tests/Functional/tests/comments/comments.rst similarity index 100% rename from tests/HTML/files/comments.rst rename to tests/Functional/tests/comments/comments.rst diff --git a/tests/Functional/tests/crlf/crlf.html b/tests/Functional/tests/crlf/crlf.html new file mode 100644 index 00000000..08c1d048 --- /dev/null +++ b/tests/Functional/tests/crlf/crlf.html @@ -0,0 +1,6 @@ +
+

+ Hello world +

+

Hey!

+
diff --git a/tests/HTML/files/crlf.rst b/tests/Functional/tests/crlf/crlf.rst similarity index 88% rename from tests/HTML/files/crlf.rst rename to tests/Functional/tests/crlf/crlf.rst index 163efa8d..621b342c 100644 --- a/tests/HTML/files/crlf.rst +++ b/tests/Functional/tests/crlf/crlf.rst @@ -1,4 +1,4 @@ Hello world =========== -Hey! +Hey! diff --git a/tests/Functional/tests/css/css.html b/tests/Functional/tests/css/css.html new file mode 100644 index 00000000..85efa8f7 --- /dev/null +++ b/tests/Functional/tests/css/css.html @@ -0,0 +1 @@ +

Testing page!

diff --git a/tests/HTML/files/css.rst b/tests/Functional/tests/css/css.rst similarity index 97% rename from tests/HTML/files/css.rst rename to tests/Functional/tests/css/css.rst index 8275c4bd..d4803bfc 100644 --- a/tests/HTML/files/css.rst +++ b/tests/Functional/tests/css/css.rst @@ -1,4 +1,3 @@ - .. stylesheet:: style.css Testing page! diff --git a/tests/Functional/tests/definition-list/definition-list.html b/tests/Functional/tests/definition-list/definition-list.html new file mode 100644 index 00000000..4e5606d2 --- /dev/null +++ b/tests/Functional/tests/definition-list/definition-list.html @@ -0,0 +1,75 @@ +
+

+ Test +

+
+

Test

+
+

Text around the definition list.

+
+
term 1
+
Definition 1
+
term 2
+
+

Definition 1

+

Definition 2

+

Definition 3

+
+
term 3 :classifier
+
Definition 1
+
term 4 :classifier one:classifier two
+
Definition 1
+
term with & :classifier with &
+
Definition 1 with &
+
term with & :classifier with &:classifier with &
+
+

Definition 1 with &

+

Definition 2 with &

+
+
+ term 5: + classifier +
+
Definition 1
+
multi-line definition term
+
+

Definition 1 line 1 Definition 1 line 2

+

Definition 2 line 1 Definition 2 line 2

+
+
+
+
+

+ Definition List in a Directive +

+
+

Definition list in a directive

+
+
term 1
+
+

Definition 1 line 1 Definition 1 line 2

+

Definition 2

+
+
term 2
+
+

Definition 1 line 1 Definition 1 line 2

+

Definition 2

+
+
+
+
+
+

+ Definition List Surrounded by Paragraphs +

+

Paragraph 1

+
+
term 1
+
definition 1 definition 2
+
+

Paragraph 2

+
+
term 2
+
definition 1 definition 2
+
+
diff --git a/tests/Functional/tests/definition-list/definition-list.rst b/tests/Functional/tests/definition-list/definition-list.rst new file mode 100644 index 00000000..37b243dd --- /dev/null +++ b/tests/Functional/tests/definition-list/definition-list.rst @@ -0,0 +1,75 @@ +Test +==== + +.. note:: + Test + +Text around the definition list. + +term 1 + Definition 1 + +term 2 + Definition 1 + + Definition 2 + + Definition 3 + +term 3 : classifier + Definition 1 + +term 4 : classifier one : classifier two + Definition 1 + +term with & : classifier with & + Definition 1 with & + +term with & : classifier with & : classifier with & + Definition 1 with & + + Definition 2 with & + +``term 5`` : ``classifier`` + Definition 1 + +multi-line definition term + Definition 1 line 1 + Definition 1 line 2 + + Definition 2 line 1 + Definition 2 line 2 + +Definition List in a Directive +============================== + +.. note:: + + **Definition list in a directive** + + term 1 + Definition 1 line 1 + Definition 1 line 2 + + Definition 2 + + term 2 + Definition 1 line 1 + Definition 1 line 2 + + Definition 2 + +Definition List Surrounded by Paragraphs +========================================= + +Paragraph 1 + +term 1 + definition 1 + definition 2 + +Paragraph 2 + +term 2 + definition 1 + definition 2 diff --git a/tests/Functional/tests/directive-title/directive-title.html b/tests/Functional/tests/directive-title/directive-title.html new file mode 100644 index 00000000..52efe37d --- /dev/null +++ b/tests/Functional/tests/directive-title/directive-title.html @@ -0,0 +1,7 @@ +
+
+

+ Some title! +

+
+
diff --git a/tests/HTML/files/directive-title.rst b/tests/Functional/tests/directive-title/directive-title.rst similarity index 94% rename from tests/HTML/files/directive-title.rst rename to tests/Functional/tests/directive-title/directive-title.rst index 765c63e6..0890ede7 100644 --- a/tests/HTML/files/directive-title.rst +++ b/tests/Functional/tests/directive-title/directive-title.rst @@ -1,5 +1,3 @@ - .. note:: Some title! =========== - diff --git a/tests/Functional/tests/div/div.html b/tests/Functional/tests/div/div.html new file mode 100644 index 00000000..d92e8a68 --- /dev/null +++ b/tests/Functional/tests/div/div.html @@ -0,0 +1,3 @@ +
+

Hello!

+
diff --git a/tests/HTML/files/div.rst b/tests/Functional/tests/div/div.rst similarity index 96% rename from tests/HTML/files/div.rst rename to tests/Functional/tests/div/div.rst index a7ca1a67..0d13aa1e 100644 --- a/tests/HTML/files/div.rst +++ b/tests/Functional/tests/div/div.rst @@ -1,3 +1,2 @@ - .. div:: testing Hello! diff --git a/tests/Functional/tests/empty-p/empty-p.html b/tests/Functional/tests/empty-p/empty-p.html new file mode 100644 index 00000000..cb5e0a77 --- /dev/null +++ b/tests/Functional/tests/empty-p/empty-p.html @@ -0,0 +1,6 @@ +

Empty paragraph:

+
+
+

Code

+
+

Hello

diff --git a/tests/HTML/files/empty-p.rst b/tests/Functional/tests/empty-p/empty-p.rst similarity index 97% rename from tests/HTML/files/empty-p.rst rename to tests/Functional/tests/empty-p/empty-p.rst index bba01850..e1b85927 100644 --- a/tests/HTML/files/empty-p.rst +++ b/tests/Functional/tests/empty-p/empty-p.rst @@ -1,4 +1,3 @@ - Empty paragraph: :: diff --git a/tests/Functional/tests/empty/empty.html b/tests/Functional/tests/empty/empty.html new file mode 100644 index 00000000..e69de29b diff --git a/tests/Functional/tests/empty/empty.rst b/tests/Functional/tests/empty/empty.rst new file mode 100644 index 00000000..e69de29b diff --git a/tests/Functional/tests/escape/escape.html b/tests/Functional/tests/escape/escape.html new file mode 100644 index 00000000..e44a0ef0 --- /dev/null +++ b/tests/Functional/tests/escape/escape.html @@ -0,0 +1 @@ +

Testing that this is escaped: <script>

diff --git a/tests/HTML/files/escape.rst b/tests/Functional/tests/escape/escape.rst similarity index 95% rename from tests/HTML/files/escape.rst rename to tests/Functional/tests/escape/escape.rst index 4ec31eac..196efc79 100644 --- a/tests/HTML/files/escape.rst +++ b/tests/Functional/tests/escape/escape.rst @@ -1,3 +1 @@ - Testing that this is escaped: