Update website
This commit is contained in:
parent
4413528994
commit
1d90fbf296
6865 changed files with 1091082 additions and 0 deletions
55
vendor/doctrine/rst-parser/tests/Parser/DocumentParserTest.php
vendored
Normal file
55
vendor/doctrine/rst-parser/tests/Parser/DocumentParserTest.php
vendored
Normal file
|
@ -0,0 +1,55 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Doctrine\Tests\RST\Parser;
|
||||
|
||||
use Doctrine\Common\EventManager;
|
||||
use Doctrine\RST\Directives\Directive;
|
||||
use Doctrine\RST\Environment;
|
||||
use Doctrine\RST\ErrorManager;
|
||||
use Doctrine\RST\NodeFactory\NodeFactory;
|
||||
use Doctrine\RST\Parser;
|
||||
use Doctrine\RST\Parser\DocumentParser;
|
||||
use Exception;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class DocumentParserTest extends TestCase
|
||||
{
|
||||
public function testErrorWhenDirectiveThrowsException(): void
|
||||
{
|
||||
$parser = $this->createMock(Parser::class);
|
||||
$environment = $this->createMock(Environment::class);
|
||||
$nodeFactory = $this->createMock(NodeFactory::class);
|
||||
$eventManager = $this->createMock(EventManager::class);
|
||||
$codeBlockDirective = $this->createMock(Directive::class);
|
||||
$errorManager = $this->createMock(ErrorManager::class);
|
||||
|
||||
$docParser = new DocumentParser(
|
||||
$parser,
|
||||
$environment,
|
||||
$nodeFactory,
|
||||
$eventManager,
|
||||
['code-block' => $codeBlockDirective],
|
||||
true,
|
||||
__DIR__
|
||||
);
|
||||
|
||||
$codeBlockDirective->expects(self::once())
|
||||
->method('process')
|
||||
->willThrowException(new Exception('Invalid something something!'));
|
||||
$codeBlockDirective->expects(self::once())
|
||||
->method('getName')
|
||||
->willReturn('code-block-name');
|
||||
|
||||
$environment->expects(self::once())
|
||||
->method('getErrorManager')
|
||||
->willReturn($errorManager);
|
||||
|
||||
$errorManager->expects(self::once())
|
||||
->method('error')
|
||||
->with('Error while processing "code-block-name" directive: "Invalid something something!"');
|
||||
|
||||
$docParser->parse('.. code-block:: php');
|
||||
}
|
||||
}
|
98
vendor/doctrine/rst-parser/tests/Parser/LineCheckerTest.php
vendored
Normal file
98
vendor/doctrine/rst-parser/tests/Parser/LineCheckerTest.php
vendored
Normal file
|
@ -0,0 +1,98 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Doctrine\Tests\RST\Parser;
|
||||
|
||||
use Doctrine\Common\EventManager;
|
||||
use Doctrine\RST\Parser\LineChecker;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
use function str_repeat;
|
||||
|
||||
class LineCheckerTest extends TestCase
|
||||
{
|
||||
/** @var LineChecker */
|
||||
private $lineChecker;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$eventManager = $this->createMock(EventManager::class);
|
||||
|
||||
$this->lineChecker = new LineChecker();
|
||||
}
|
||||
|
||||
/** @dataProvider getSpecialCharacters */
|
||||
public function testIsSpecialLine(string $specialCharacter): void
|
||||
{
|
||||
self::assertNull($this->lineChecker->isSpecialLine($specialCharacter));
|
||||
self::assertSame($specialCharacter, $this->lineChecker->isSpecialLine(str_repeat($specialCharacter, 2)));
|
||||
self::assertSame($specialCharacter, $this->lineChecker->isSpecialLine(str_repeat($specialCharacter, 3)));
|
||||
}
|
||||
|
||||
/** @return list<array{string}> */
|
||||
public function getSpecialCharacters(): array
|
||||
{
|
||||
return [['='], ['-'], ['~'], ['*'], ['+'], ['^'], ['"'], ['.'], ['`'], ["'"], ['_'], ['#'], [':']];
|
||||
}
|
||||
|
||||
public function testIsListLine(): void
|
||||
{
|
||||
self::assertTrue($this->lineChecker->isListLine('- Test'));
|
||||
self::assertTrue($this->lineChecker->isListLine('- Test'));
|
||||
self::assertFalse($this->lineChecker->isListLine(' - Test'));
|
||||
}
|
||||
|
||||
public function testIsBlockLine(): void
|
||||
{
|
||||
self::assertTrue($this->lineChecker->isBlockLine(' '));
|
||||
self::assertTrue($this->lineChecker->isBlockLine(' '));
|
||||
self::assertTrue($this->lineChecker->isBlockLine(' '));
|
||||
self::assertTrue($this->lineChecker->isBlockLine(''));
|
||||
self::assertFalse($this->lineChecker->isBlockLine('- Test'));
|
||||
self::assertFalse($this->lineChecker->isBlockLine('.. code-block::'));
|
||||
}
|
||||
|
||||
public function testIsComment(): void
|
||||
{
|
||||
self::assertTrue($this->lineChecker->isComment('.. Test'));
|
||||
self::assertTrue($this->lineChecker->isComment('..'));
|
||||
self::assertTrue($this->lineChecker->isComment('.. with _ underscore'));
|
||||
self::assertTrue($this->lineChecker->isComment('.. with : colon'));
|
||||
self::assertTrue($this->lineChecker->isComment('.. can finish with colon:'));
|
||||
|
||||
self::assertFalse($this->lineChecker->isComment('Test'));
|
||||
self::assertFalse($this->lineChecker->isComment('.. _should not start with underscore'));
|
||||
self::assertFalse($this->lineChecker->isComment('.. should not finish with double colon::'));
|
||||
self::assertFalse($this->lineChecker->isComment('.. should contain::double colon'));
|
||||
}
|
||||
|
||||
public function testIsDirective(): void
|
||||
{
|
||||
self::assertTrue($this->lineChecker->isDirective('.. code-block::'));
|
||||
self::assertTrue($this->lineChecker->isDirective('.. code-block:: php'));
|
||||
self::assertTrue($this->lineChecker->isDirective('.. code&block:: php'));
|
||||
self::assertTrue($this->lineChecker->isDirective('.. `code-block`:: php'));
|
||||
self::assertFalse($this->lineChecker->isDirective('.. code block:: php'));
|
||||
self::assertFalse($this->lineChecker->isDirective('.. code block :: php'));
|
||||
self::assertFalse($this->lineChecker->isDirective('..code block:: php'));
|
||||
self::assertFalse($this->lineChecker->isDirective('.. code-block::php'));
|
||||
self::assertFalse($this->lineChecker->isDirective('Test'));
|
||||
}
|
||||
|
||||
public function testIsIndented(): void
|
||||
{
|
||||
self::assertTrue($this->lineChecker->isIndented(' Test'));
|
||||
self::assertTrue($this->lineChecker->isIndented(' Test'));
|
||||
self::assertFalse($this->lineChecker->isIndented('Test'));
|
||||
self::assertFalse($this->lineChecker->isIndented(''));
|
||||
self::assertFalse($this->lineChecker->isIndented(' Test', 4));
|
||||
}
|
||||
|
||||
public function testIsDefinitionListEnded(): void
|
||||
{
|
||||
self::assertTrue($this->lineChecker->isDefinitionListEnded('Test', ''));
|
||||
self::assertFalse($this->lineChecker->isDefinitionListEnded('Term', ' Definition'));
|
||||
self::assertFalse($this->lineChecker->isDefinitionListEnded('', ' Definition'));
|
||||
}
|
||||
}
|
61
vendor/doctrine/rst-parser/tests/Parser/LineDataParserTest.php
vendored
Normal file
61
vendor/doctrine/rst-parser/tests/Parser/LineDataParserTest.php
vendored
Normal file
|
@ -0,0 +1,61 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Doctrine\Tests\RST\Parser;
|
||||
|
||||
use Doctrine\Common\EventManager;
|
||||
use Doctrine\RST\Parser;
|
||||
use Doctrine\RST\Parser\LineDataParser;
|
||||
use Doctrine\RST\Parser\Link;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class LineDataParserTest extends TestCase
|
||||
{
|
||||
/** @var Parser */
|
||||
private $parser;
|
||||
|
||||
/** @var LineDataParser */
|
||||
private $lineDataParser;
|
||||
|
||||
/** @var EventManager|MockObject $eventManager */
|
||||
private $eventManager;
|
||||
|
||||
/**
|
||||
* @param mixed $expected
|
||||
*
|
||||
* @dataProvider getTestLinks
|
||||
*/
|
||||
public function testParseLink(string $line, $expected): void
|
||||
{
|
||||
$this->eventManager->expects(self::exactly($expected instanceof Link ? 1 : 0))
|
||||
->method('dispatchEvent');
|
||||
|
||||
self::assertEquals($expected, $this->lineDataParser->parseLink($line));
|
||||
}
|
||||
|
||||
/** @return list<array{string, mixed}> */
|
||||
public function getTestLinks(): array
|
||||
{
|
||||
return [
|
||||
['', null],
|
||||
['test', null],
|
||||
['.. test', null],
|
||||
['.. _test', null],
|
||||
['.. _test: https://www.google.com', new Link('test', 'https://www.google.com', Link::TYPE_LINK)],
|
||||
['.. _`test`: https://www.google.com', new Link('test', 'https://www.google.com', Link::TYPE_LINK)],
|
||||
['__ https://www.google.com', new Link('_', 'https://www.google.com', Link::TYPE_LINK)],
|
||||
['.. _anchor:', new Link('anchor', '#anchor', Link::TYPE_ANCHOR)],
|
||||
];
|
||||
}
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->parser = $this->createMock(Parser::class);
|
||||
|
||||
$this->eventManager = $this->createMock(EventManager::class);
|
||||
|
||||
$this->lineDataParser = new LineDataParser($this->parser, $this->eventManager);
|
||||
}
|
||||
}
|
455
vendor/doctrine/rst-parser/tests/Parser/ParserTest.php
vendored
Normal file
455
vendor/doctrine/rst-parser/tests/Parser/ParserTest.php
vendored
Normal file
|
@ -0,0 +1,455 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Doctrine\Tests\RST\Parser;
|
||||
|
||||
use Doctrine\RST\Nodes\CodeNode;
|
||||
use Doctrine\RST\Nodes\DocumentNode;
|
||||
use Doctrine\RST\Nodes\DummyNode;
|
||||
use Doctrine\RST\Nodes\ListNode;
|
||||
use Doctrine\RST\Nodes\Node;
|
||||
use Doctrine\RST\Nodes\ParagraphNode;
|
||||
use Doctrine\RST\Nodes\QuoteNode;
|
||||
use Doctrine\RST\Nodes\TableNode;
|
||||
use Doctrine\RST\Nodes\TitleNode;
|
||||
use Doctrine\RST\Parser;
|
||||
use Exception;
|
||||
use InvalidArgumentException;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use RuntimeException;
|
||||
|
||||
use function assert;
|
||||
use function count;
|
||||
use function file_get_contents;
|
||||
use function sprintf;
|
||||
use function trim;
|
||||
|
||||
/**
|
||||
* Unit testing for RST
|
||||
*/
|
||||
class ParserTest extends TestCase
|
||||
{
|
||||
/** @var Parser $parser */
|
||||
protected $parser;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$directory = __DIR__ . '/files/';
|
||||
$parser = new Parser();
|
||||
|
||||
$parser->getEnvironment()->setCurrentDirectory($directory);
|
||||
|
||||
$this->parser = $parser;
|
||||
}
|
||||
|
||||
public function testGetSubParserPassesConfiguration(): void
|
||||
{
|
||||
$parser = new Parser();
|
||||
|
||||
$configuration = $parser->getEnvironment()->getConfiguration();
|
||||
|
||||
$subParser = $parser->getSubParser();
|
||||
|
||||
self::assertSame($configuration, $subParser->getEnvironment()->getConfiguration());
|
||||
}
|
||||
|
||||
/**
|
||||
* Testing that code node value is good
|
||||
*/
|
||||
public function testCodeNode(): void
|
||||
{
|
||||
$document = $this->parse('code-block-lastline.rst');
|
||||
|
||||
$nodes = $document->getNodes(static function ($node): bool {
|
||||
return $node instanceof CodeNode;
|
||||
});
|
||||
|
||||
self::assertSame(1, count($nodes));
|
||||
self::assertSame("A\nB\n C", trim($nodes[0]->getValueString()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Testing that code node options are parsed
|
||||
*/
|
||||
public function testCodeNodeWithOptions(): void
|
||||
{
|
||||
$document = $this->parse('code-block-with-options.rst');
|
||||
|
||||
$nodes = $document->getNodes(static function (Node $node): bool {
|
||||
return $node instanceof CodeNode;
|
||||
});
|
||||
|
||||
self::assertSame(1, count($nodes));
|
||||
$codeNode = $nodes[0];
|
||||
assert($codeNode instanceof CodeNode);
|
||||
self::assertSame("A\nB\nC", trim($codeNode->getValueString()));
|
||||
self::assertSame(['name' => 'My Very Best Code'], $codeNode->getOptions());
|
||||
}
|
||||
|
||||
/**
|
||||
* Testing paragraph nodes
|
||||
*/
|
||||
public function testParagraphNode(): void
|
||||
{
|
||||
$document = $this->parse('paragraph.rst');
|
||||
|
||||
self::assertHasNode($document, static function ($node): bool {
|
||||
return $node instanceof ParagraphNode;
|
||||
}, 1);
|
||||
self::assertStringContainsString('Hello world!', $document->render());
|
||||
}
|
||||
|
||||
/**
|
||||
* Testing multi-paragraph nodes
|
||||
*/
|
||||
public function testParagraphNodes(): void
|
||||
{
|
||||
$document = $this->parse('paragraphs.rst');
|
||||
|
||||
self::assertHasNode($document, static function ($node): bool {
|
||||
return $node instanceof ParagraphNode;
|
||||
}, 3);
|
||||
}
|
||||
|
||||
/**
|
||||
* Testing quote and block code
|
||||
*/
|
||||
public function testBlockNode(): void
|
||||
{
|
||||
$quote = $this->parse('quote.rst');
|
||||
|
||||
self::assertHasNode($quote, static function ($node): bool {
|
||||
return $node instanceof QuoteNode;
|
||||
}, 1);
|
||||
|
||||
$code = $this->parse('code.rst');
|
||||
|
||||
self::assertHasNode($quote, static function ($node): bool {
|
||||
return $node instanceof QuoteNode;
|
||||
}, 1);
|
||||
|
||||
self::assertStringNotContainsString('::', $code->render());
|
||||
}
|
||||
|
||||
/**
|
||||
* Testing the titling
|
||||
*/
|
||||
public function testTitles(): void
|
||||
{
|
||||
$document = $this->parse('title.rst');
|
||||
|
||||
self::assertHasNode($document, static function ($node): bool {
|
||||
return $node instanceof TitleNode
|
||||
&& $node->getLevel() === 1;
|
||||
}, 1);
|
||||
|
||||
$document = $this->parse('title2.rst');
|
||||
|
||||
self::assertHasNode($document, static function ($node): bool {
|
||||
return $node instanceof TitleNode
|
||||
&& $node->getLevel() === 2;
|
||||
}, 1);
|
||||
}
|
||||
|
||||
public function testTitlesWithCustomInitialHeaderLevel(): void
|
||||
{
|
||||
$this->parser->getEnvironment()->getConfiguration()->setInitialHeaderLevel(2);
|
||||
|
||||
$document = $this->parse('title.rst');
|
||||
|
||||
self::assertHasNode($document, static function ($node): bool {
|
||||
return $node instanceof TitleNode && $node->getLevel() === 2;
|
||||
}, 1);
|
||||
|
||||
$document = $this->parse('title2.rst');
|
||||
|
||||
self::assertHasNode($document, static function ($node): bool {
|
||||
return $node instanceof TitleNode && $node->getLevel() === 3;
|
||||
}, 1);
|
||||
}
|
||||
|
||||
public function testList(): void
|
||||
{
|
||||
$document = $this->parse('list.rst');
|
||||
|
||||
self::assertHasNode($document, static function ($node): bool {
|
||||
return $node instanceof ListNode;
|
||||
}, 1);
|
||||
|
||||
$document = $this->parse('list.rst');
|
||||
|
||||
self::assertHasNode($document, static function ($node): bool {
|
||||
return $node instanceof ListNode;
|
||||
}, 1);
|
||||
|
||||
$document = $this->parse('list-empty.rst');
|
||||
self::assertHasNode($document, static function ($node): bool {
|
||||
return $node instanceof ListNode;
|
||||
}, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Testing the titles retrieving
|
||||
*/
|
||||
public function testGetTitles(): void
|
||||
{
|
||||
$document = $this->parse('titles.rst');
|
||||
|
||||
self::assertSame($document->getTitle(), 'The main title');
|
||||
self::assertSame($document->getTitles(), [
|
||||
[
|
||||
'The main title',
|
||||
[
|
||||
[
|
||||
'First level title',
|
||||
[
|
||||
['Second level title', []],
|
||||
['Other second level title', []],
|
||||
],
|
||||
],
|
||||
[
|
||||
'Other first level title',
|
||||
[
|
||||
['Next second level title', []],
|
||||
['Yet another second level title', []],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Testing the table feature
|
||||
*/
|
||||
public function testTable(): void
|
||||
{
|
||||
$document = $this->parse('table.rst');
|
||||
|
||||
$nodes = $document->getNodes(static function ($node): bool {
|
||||
return $node instanceof TableNode;
|
||||
});
|
||||
|
||||
self::assertSame(count($nodes), 1);
|
||||
|
||||
$table = $nodes[0];
|
||||
assert($table instanceof TableNode);
|
||||
|
||||
self::assertSame(3, $table->getCols());
|
||||
self::assertSame(3, $table->getRows());
|
||||
|
||||
$document = $this->parse('pretty-table.rst');
|
||||
|
||||
$nodes = $document->getNodes(static function ($node): bool {
|
||||
return $node instanceof TableNode;
|
||||
});
|
||||
|
||||
self::assertSame(count($nodes), 1);
|
||||
|
||||
$table = $nodes[0];
|
||||
assert($table instanceof TableNode);
|
||||
|
||||
self::assertSame(3, $table->getCols());
|
||||
self::assertSame(2, $table->getRows());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that a simple replace works
|
||||
*/
|
||||
public function testReplace(): void
|
||||
{
|
||||
$document = $this->parse('replace.rst');
|
||||
|
||||
self::assertStringContainsString('Hello world!', $document->render());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the include:: pseudo-directive
|
||||
*/
|
||||
public function testInclusion(): void
|
||||
{
|
||||
$document = $this->parse('inclusion.rst');
|
||||
|
||||
self::assertStringContainsString('I was actually included', $document->renderDocument());
|
||||
}
|
||||
|
||||
public function testThrowExceptionOnInvalidFileInclude(): void
|
||||
{
|
||||
$parser = new Parser();
|
||||
$environment = $parser->getEnvironment();
|
||||
|
||||
$data = file_get_contents(__DIR__ . '/files/inclusion-bad.rst');
|
||||
|
||||
self::assertIsString($data);
|
||||
|
||||
$this->expectException(RuntimeException::class);
|
||||
$this->expectExceptionMessage('Include ".. include:: non-existent-file.rst" does not exist or is not readable.');
|
||||
|
||||
$parser->parse($data);
|
||||
}
|
||||
|
||||
public function testDirective(): void
|
||||
{
|
||||
$document = $this->parse('directive.rst');
|
||||
|
||||
$nodes = $document->getNodes(static function ($node): bool {
|
||||
return $node instanceof DummyNode;
|
||||
});
|
||||
|
||||
self::assertSame(1, count($nodes));
|
||||
|
||||
$node = $nodes[0];
|
||||
assert($node instanceof DummyNode);
|
||||
|
||||
$data = $node->data;
|
||||
|
||||
self::assertSame('some data', $data['data']);
|
||||
$options = $data['options'];
|
||||
self::assertTrue(isset($options['maxdepth']));
|
||||
self::assertTrue(isset($options['titlesonly']));
|
||||
self::assertTrue(isset($options['glob']));
|
||||
self::assertTrue($options['titlesonly']);
|
||||
self::assertSame('123', $options['maxdepth']);
|
||||
}
|
||||
|
||||
public function testSubsequentParsesDontHaveTheSameTitleLevelOrder(): void
|
||||
{
|
||||
$directory = __DIR__ . '/files';
|
||||
|
||||
$parser = new Parser();
|
||||
$parser->getEnvironment()->setCurrentDirectory($directory);
|
||||
|
||||
/** @var TitleNode[] $nodes1 */
|
||||
$nodes1 = $parser->parseFile(sprintf('%s/mixed-titles-1.rst', $directory))->getNodes();
|
||||
/** @var TitleNode[] $nodes2 */
|
||||
$nodes2 = $parser->parseFile(sprintf('%s/mixed-titles-2.rst', $directory))->getNodes();
|
||||
|
||||
$node = $nodes1[1];
|
||||
self::assertSame(1, $node->getLevel());
|
||||
|
||||
$node = $nodes1[3];
|
||||
self::assertSame(2, $node->getLevel());
|
||||
|
||||
$node = $nodes2[1];
|
||||
self::assertSame(1, $node->getLevel(), 'Title level in second parse is influenced by first parse');
|
||||
|
||||
$node = $nodes2[3];
|
||||
self::assertSame(2, $node->getLevel(), 'Title level in second parse is influenced by first parse');
|
||||
}
|
||||
|
||||
public function testNewlineBeforeAnIncludedIsntGobbled(): void
|
||||
{
|
||||
/** @var Node[] $nodes */
|
||||
$nodes = $this->parse('inclusion-newline.rst')->getNodes();
|
||||
|
||||
self::assertCount(5, $nodes);
|
||||
self::assertInstanceOf('Doctrine\RST\Nodes\SectionBeginNode', $nodes[0]);
|
||||
self::assertInstanceOf('Doctrine\RST\Nodes\TitleNode', $nodes[1]);
|
||||
self::assertInstanceOf('Doctrine\RST\Nodes\ParagraphNode', $nodes[2]);
|
||||
self::assertInstanceOf('Doctrine\RST\Nodes\ParagraphNode', $nodes[3]);
|
||||
self::assertStringContainsString('<p>Test this paragraph is present.</p>', $nodes[2]->render());
|
||||
self::assertStringContainsString('<p>And this one as well.</p>', $nodes[3]->render());
|
||||
}
|
||||
|
||||
public function testIncludesKeepScope(): void
|
||||
{
|
||||
// See http://docutils.sourceforge.net/docs/ref/rst/directives.html#including-an-external-document-fragment
|
||||
|
||||
/** @var Node[] $nodes */
|
||||
$nodes = $this->parse('inclusion-scope.rst')->getNodes();
|
||||
|
||||
self::assertCount(4, $nodes);
|
||||
|
||||
$node = $nodes[0]->getValue();
|
||||
assert($node instanceof Node);
|
||||
self::assertSame("This first example will be parsed at the document level, and can\nthus contain any construct, including section headers.", $node->render());
|
||||
|
||||
$node = $nodes[1]->getValue();
|
||||
assert($node instanceof Node);
|
||||
self::assertSame('This is included.', $node->render());
|
||||
|
||||
$node = $nodes[2]->getValue();
|
||||
assert($node instanceof Node);
|
||||
self::assertSame('Back in the main document.', $node->render());
|
||||
|
||||
self::assertInstanceOf('Doctrine\RST\Nodes\QuoteNode', $nodes[3]);
|
||||
|
||||
$node = $nodes[3]->getValue();
|
||||
self::assertStringContainsString('This is included.', $node->render());
|
||||
}
|
||||
|
||||
public function testIncludesPolicy(): void
|
||||
{
|
||||
$directory = __DIR__ . '/files/';
|
||||
$parser = new Parser();
|
||||
$environment = $parser->getEnvironment();
|
||||
$environment->setCurrentDirectory($directory);
|
||||
|
||||
// Test defaults
|
||||
self::assertTrue($parser->getIncludeAllowed());
|
||||
self::assertSame('', $parser->getIncludeRoot());
|
||||
|
||||
// Default policy:
|
||||
$document = $parser->parseFile($directory . 'inclusion-policy.rst')->render();
|
||||
self::assertStringContainsString('SUBDIRECTORY OK', $document);
|
||||
self::assertStringContainsString('EXTERNAL FILE INCLUDED!', $document);
|
||||
|
||||
// Disbaled policy:
|
||||
$parser->setIncludePolicy(false);
|
||||
$nodes = $parser->parseFile($directory . 'inclusion-policy.rst')->getNodes();
|
||||
self::assertCount(1, $nodes);
|
||||
|
||||
// Enabled
|
||||
$parser->setIncludePolicy(true);
|
||||
$nodes = $parser->parseFile($directory . 'inclusion-policy.rst')->getNodes();
|
||||
self::assertCount(6, $nodes);
|
||||
|
||||
// Jailed
|
||||
$parser->setIncludePolicy(true, $directory);
|
||||
$nodes = $parser->parseFile($directory . 'inclusion-policy.rst')->getNodes();
|
||||
self::assertCount(5, $nodes);
|
||||
}
|
||||
|
||||
public function testParseFileThrowsInvalidArgumentExceptionForMissingFile(): void
|
||||
{
|
||||
$this->expectException(InvalidArgumentException::class);
|
||||
$this->expectExceptionMessage('File at path does-not-exist.rst does not exist');
|
||||
|
||||
$parser = new Parser();
|
||||
$parser->parseFile('does-not-exist.rst');
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function, parses a file and returns the document
|
||||
* produced by the parser
|
||||
*/
|
||||
private function parse(string $file): DocumentNode
|
||||
{
|
||||
$directory = $this->parser->getEnvironment()->getCurrentDirectory();
|
||||
$data = file_get_contents($directory . $file);
|
||||
|
||||
if ($data === false) {
|
||||
throw new Exception('Could not open file.');
|
||||
}
|
||||
|
||||
return $this->parser->parse($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that a document has nodes that satisfy the function
|
||||
*/
|
||||
private function assertHasNode(DocumentNode $document, callable $function, ?int $count = null): void
|
||||
{
|
||||
$nodes = $document->getNodes($function);
|
||||
self::assertNotEmpty($nodes);
|
||||
|
||||
if ($count === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
self::assertSame($count, count($nodes));
|
||||
}
|
||||
}
|
89
vendor/doctrine/rst-parser/tests/Parser/TableParserTest.php
vendored
Normal file
89
vendor/doctrine/rst-parser/tests/Parser/TableParserTest.php
vendored
Normal file
|
@ -0,0 +1,89 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Doctrine\Tests\RST\Parser;
|
||||
|
||||
use Doctrine\RST\Nodes\TableNode;
|
||||
use Doctrine\RST\Parser;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class TableParserTest extends TestCase
|
||||
{
|
||||
/** @dataProvider getLineSeparatorsData */
|
||||
public function testParseTableLineSeparator(string $inputLine, ?Parser\TableSeparatorLineConfig $expectedConfig): void
|
||||
{
|
||||
$tableParser = new Parser\TableParser();
|
||||
$actualSeparatorConfig = $tableParser->parseTableSeparatorLine($inputLine);
|
||||
|
||||
// equals to compare object data, not identity
|
||||
self::assertEquals($expectedConfig, $actualSeparatorConfig);
|
||||
}
|
||||
|
||||
/** @return list<array{string, Parser\TableSeparatorLineConfig|null}> */
|
||||
public function getLineSeparatorsData(): array
|
||||
{
|
||||
return [
|
||||
[
|
||||
'FOO',
|
||||
null,
|
||||
],
|
||||
[
|
||||
'=== === ===',
|
||||
new Parser\TableSeparatorLineConfig(
|
||||
false,
|
||||
TableNode::TYPE_SIMPLE,
|
||||
[[0, 3], [4, 7], [8, 11]],
|
||||
'=',
|
||||
'=== === ==='
|
||||
),
|
||||
],
|
||||
[
|
||||
'=== ===== ===',
|
||||
new Parser\TableSeparatorLineConfig(
|
||||
false,
|
||||
TableNode::TYPE_SIMPLE,
|
||||
[[0, 3], [4, 9], [10, 13]],
|
||||
'=',
|
||||
'=== ===== ==='
|
||||
),
|
||||
],
|
||||
[
|
||||
'=== ===== === ===',
|
||||
new Parser\TableSeparatorLineConfig(
|
||||
false,
|
||||
TableNode::TYPE_SIMPLE,
|
||||
[[0, 3], [6, 11], [14, 17], [18, 21]],
|
||||
'=',
|
||||
'=== ===== === ==='
|
||||
),
|
||||
],
|
||||
[
|
||||
// not a valid first/last, but it
|
||||
// *is* valid to have these inside a simple table
|
||||
'--- --- ---',
|
||||
new Parser\TableSeparatorLineConfig(
|
||||
false,
|
||||
TableNode::TYPE_SIMPLE,
|
||||
[[0, 3], [4, 7], [8, 11]],
|
||||
'-',
|
||||
'--- --- ---'
|
||||
),
|
||||
],
|
||||
[
|
||||
'--- -=- ---',
|
||||
null,
|
||||
],
|
||||
[
|
||||
'+-----+------+--------+',
|
||||
new Parser\TableSeparatorLineConfig(
|
||||
false,
|
||||
TableNode::TYPE_PRETTY,
|
||||
[[1, 6], [7, 13], [14, 22]],
|
||||
'-',
|
||||
'+-----+------+--------+'
|
||||
),
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
6
vendor/doctrine/rst-parser/tests/Parser/files/code-block-lastline.rst
vendored
Normal file
6
vendor/doctrine/rst-parser/tests/Parser/files/code-block-lastline.rst
vendored
Normal file
|
@ -0,0 +1,6 @@
|
|||
|
||||
.. code-block::
|
||||
|
||||
A
|
||||
B
|
||||
C
|
7
vendor/doctrine/rst-parser/tests/Parser/files/code-block-with-options.rst
vendored
Normal file
7
vendor/doctrine/rst-parser/tests/Parser/files/code-block-with-options.rst
vendored
Normal file
|
@ -0,0 +1,7 @@
|
|||
|
||||
.. code-block::
|
||||
:name: My Very Best Code
|
||||
|
||||
A
|
||||
B
|
||||
C
|
3
vendor/doctrine/rst-parser/tests/Parser/files/code-with-whitespace.rst
vendored
Normal file
3
vendor/doctrine/rst-parser/tests/Parser/files/code-with-whitespace.rst
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
::
|
||||
|
||||
Test code block with whitespace.
|
6
vendor/doctrine/rst-parser/tests/Parser/files/code.rst
vendored
Normal file
6
vendor/doctrine/rst-parser/tests/Parser/files/code.rst
vendored
Normal file
|
@ -0,0 +1,6 @@
|
|||
|
||||
This is a code::
|
||||
|
||||
Some code
|
||||
|
||||
Some code
|
5
vendor/doctrine/rst-parser/tests/Parser/files/comment.rst
vendored
Normal file
5
vendor/doctrine/rst-parser/tests/Parser/files/comment.rst
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
|
||||
Text before
|
||||
.. Testing comment
|
||||
Text after
|
||||
|
75
vendor/doctrine/rst-parser/tests/Parser/files/definition-list.rst
vendored
Normal file
75
vendor/doctrine/rst-parser/tests/Parser/files/definition-list.rst
vendored
Normal file
|
@ -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
|
7
vendor/doctrine/rst-parser/tests/Parser/files/directive.rst
vendored
Normal file
7
vendor/doctrine/rst-parser/tests/Parser/files/directive.rst
vendored
Normal file
|
@ -0,0 +1,7 @@
|
|||
|
||||
.. dummy:: some data
|
||||
:maxdepth: 123
|
||||
:titlesonly:
|
||||
:glob:
|
||||
|
||||
Blha
|
0
vendor/doctrine/rst-parser/tests/Parser/files/empty.rst
vendored
Normal file
0
vendor/doctrine/rst-parser/tests/Parser/files/empty.rst
vendored
Normal file
3
vendor/doctrine/rst-parser/tests/Parser/files/include.rst
vendored
Normal file
3
vendor/doctrine/rst-parser/tests/Parser/files/include.rst
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
|
||||
I was actually included
|
||||
|
4
vendor/doctrine/rst-parser/tests/Parser/files/inclusion-bad.rst
vendored
Normal file
4
vendor/doctrine/rst-parser/tests/Parser/files/inclusion-bad.rst
vendored
Normal file
|
@ -0,0 +1,4 @@
|
|||
Inclusion test
|
||||
==============
|
||||
|
||||
.. include:: non-existent-file.rst
|
1
vendor/doctrine/rst-parser/tests/Parser/files/inclusion-newline-include.rst
vendored
Normal file
1
vendor/doctrine/rst-parser/tests/Parser/files/inclusion-newline-include.rst
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
And this one as well.
|
6
vendor/doctrine/rst-parser/tests/Parser/files/inclusion-newline.rst
vendored
Normal file
6
vendor/doctrine/rst-parser/tests/Parser/files/inclusion-newline.rst
vendored
Normal file
|
@ -0,0 +1,6 @@
|
|||
Inclusion test
|
||||
==============
|
||||
|
||||
Test this paragraph is present.
|
||||
|
||||
.. include:: inclusion-newline-include.rst
|
7
vendor/doctrine/rst-parser/tests/Parser/files/inclusion-policy.rst
vendored
Normal file
7
vendor/doctrine/rst-parser/tests/Parser/files/inclusion-policy.rst
vendored
Normal file
|
@ -0,0 +1,7 @@
|
|||
Test the inclusion policy:
|
||||
|
||||
.. include:: subdir/test.rst
|
||||
|
||||
.. include:: inclusion-scope-include.rst
|
||||
|
||||
.. include:: ../../Functional/tests/render/include-external/include-external.rst
|
1
vendor/doctrine/rst-parser/tests/Parser/files/inclusion-scope-include.rst
vendored
Normal file
1
vendor/doctrine/rst-parser/tests/Parser/files/inclusion-scope-include.rst
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
This is included.
|
12
vendor/doctrine/rst-parser/tests/Parser/files/inclusion-scope.rst
vendored
Normal file
12
vendor/doctrine/rst-parser/tests/Parser/files/inclusion-scope.rst
vendored
Normal file
|
@ -0,0 +1,12 @@
|
|||
This first example will be parsed at the document level, and can
|
||||
thus contain any construct, including section headers.
|
||||
|
||||
.. include:: inclusion-scope-include.rst
|
||||
|
||||
Back in the main document.
|
||||
|
||||
This second example will be parsed in a block quote context.
|
||||
Therefore it may only contain body elements. It may not
|
||||
contain section headers.
|
||||
|
||||
.. include:: inclusion-scope-include.rst
|
5
vendor/doctrine/rst-parser/tests/Parser/files/inclusion.rst
vendored
Normal file
5
vendor/doctrine/rst-parser/tests/Parser/files/inclusion.rst
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
|
||||
Inclusion test
|
||||
==============
|
||||
|
||||
.. include:: include.rst
|
7
vendor/doctrine/rst-parser/tests/Parser/files/indented-list.rst
vendored
Normal file
7
vendor/doctrine/rst-parser/tests/Parser/files/indented-list.rst
vendored
Normal file
|
@ -0,0 +1,7 @@
|
|||
|
||||
Testing an indented list:
|
||||
|
||||
* First item
|
||||
* Second item
|
||||
* Third item
|
||||
|
12
vendor/doctrine/rst-parser/tests/Parser/files/list-empty.rst
vendored
Normal file
12
vendor/doctrine/rst-parser/tests/Parser/files/list-empty.rst
vendored
Normal file
|
@ -0,0 +1,12 @@
|
|||
|
||||
This is a list with an empty line:
|
||||
|
||||
1. Test!
|
||||
2. Other test!
|
||||
|
||||
* Sub test
|
||||
* Other sub test
|
||||
|
||||
3. The list just continues here
|
||||
|
||||
This is not in the list
|
7
vendor/doctrine/rst-parser/tests/Parser/files/list.rst
vendored
Normal file
7
vendor/doctrine/rst-parser/tests/Parser/files/list.rst
vendored
Normal file
|
@ -0,0 +1,7 @@
|
|||
|
||||
Testing a list:
|
||||
|
||||
* First item
|
||||
* Second item
|
||||
* Third item
|
||||
|
5
vendor/doctrine/rst-parser/tests/Parser/files/mixed-titles-1.rst
vendored
Normal file
5
vendor/doctrine/rst-parser/tests/Parser/files/mixed-titles-1.rst
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
Header 1
|
||||
========
|
||||
|
||||
Header 2
|
||||
--------
|
5
vendor/doctrine/rst-parser/tests/Parser/files/mixed-titles-2.rst
vendored
Normal file
5
vendor/doctrine/rst-parser/tests/Parser/files/mixed-titles-2.rst
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
Header 1
|
||||
--------
|
||||
|
||||
Header 2
|
||||
========
|
7
vendor/doctrine/rst-parser/tests/Parser/files/multi-comment.rst
vendored
Normal file
7
vendor/doctrine/rst-parser/tests/Parser/files/multi-comment.rst
vendored
Normal file
|
@ -0,0 +1,7 @@
|
|||
|
||||
Text before
|
||||
.. Testing a
|
||||
multi-line comment
|
||||
Blha blha
|
||||
Text after
|
||||
|
1
vendor/doctrine/rst-parser/tests/Parser/files/paragraph.rst
vendored
Normal file
1
vendor/doctrine/rst-parser/tests/Parser/files/paragraph.rst
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
Hello world!
|
8
vendor/doctrine/rst-parser/tests/Parser/files/paragraphs.rst
vendored
Normal file
8
vendor/doctrine/rst-parser/tests/Parser/files/paragraphs.rst
vendored
Normal file
|
@ -0,0 +1,8 @@
|
|||
Paragraph 1
|
||||
|
||||
Paragraph 2
|
||||
With two lines
|
||||
|
||||
Paragraph 3
|
||||
With *emphasis*
|
||||
|
7
vendor/doctrine/rst-parser/tests/Parser/files/pretty-table.rst
vendored
Normal file
7
vendor/doctrine/rst-parser/tests/Parser/files/pretty-table.rst
vendored
Normal file
|
@ -0,0 +1,7 @@
|
|||
|
||||
+------------------+------------+----------+
|
||||
| This is a table | With | Some |
|
||||
+------------------+------------+----------+
|
||||
| Data | In it | Pretty! |
|
||||
+------------------+------------+----------+
|
||||
|
6
vendor/doctrine/rst-parser/tests/Parser/files/quote.rst
vendored
Normal file
6
vendor/doctrine/rst-parser/tests/Parser/files/quote.rst
vendored
Normal file
|
@ -0,0 +1,6 @@
|
|||
|
||||
This is a quote:
|
||||
|
||||
Hello
|
||||
|
||||
I am a quote block
|
5
vendor/doctrine/rst-parser/tests/Parser/files/replace.rst
vendored
Normal file
5
vendor/doctrine/rst-parser/tests/Parser/files/replace.rst
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
|
||||
Hello |name|
|
||||
|
||||
.. |name| replace:: world!
|
||||
|
5
vendor/doctrine/rst-parser/tests/Parser/files/subdir/test.rst
vendored
Normal file
5
vendor/doctrine/rst-parser/tests/Parser/files/subdir/test.rst
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
Testing.
|
||||
|
||||
SUBDIRECTORY OK
|
||||
|
||||
Testing complete.
|
8
vendor/doctrine/rst-parser/tests/Parser/files/table.rst
vendored
Normal file
8
vendor/doctrine/rst-parser/tests/Parser/files/table.rst
vendored
Normal file
|
@ -0,0 +1,8 @@
|
|||
|
||||
===== ===== =====
|
||||
Col A Col B Col C
|
||||
===== ===== =====
|
||||
Col X Col Y Col Z
|
||||
===== ===== =====
|
||||
Col U Col J Col K
|
||||
===== ===== =====
|
4
vendor/doctrine/rst-parser/tests/Parser/files/title.rst
vendored
Normal file
4
vendor/doctrine/rst-parser/tests/Parser/files/title.rst
vendored
Normal file
|
@ -0,0 +1,4 @@
|
|||
|
||||
Main title
|
||||
==========
|
||||
|
7
vendor/doctrine/rst-parser/tests/Parser/files/title2.rst
vendored
Normal file
7
vendor/doctrine/rst-parser/tests/Parser/files/title2.rst
vendored
Normal file
|
@ -0,0 +1,7 @@
|
|||
|
||||
Main title
|
||||
==========
|
||||
|
||||
Second title
|
||||
------------
|
||||
|
21
vendor/doctrine/rst-parser/tests/Parser/files/titles.rst
vendored
Normal file
21
vendor/doctrine/rst-parser/tests/Parser/files/titles.rst
vendored
Normal file
|
@ -0,0 +1,21 @@
|
|||
|
||||
The main title
|
||||
==============
|
||||
|
||||
First level title
|
||||
-----------------
|
||||
|
||||
Second level title
|
||||
~~~~~~~~~~~~~~~~~~
|
||||
|
||||
Other second level title
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
Other first level title
|
||||
-----------------------
|
||||
|
||||
Next second level title
|
||||
~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
Yet another second level title
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
Loading…
Add table
Add a link
Reference in a new issue