Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for paragraph to prepare for refactor
- Loading branch information
Showing
1 changed file
with
217 additions
and
0 deletions.
There are no files selected for viewing
217 changes: 217 additions & 0 deletions
217
incubator/guides-restructured-text/tests/unit/Parser/Productions/ParagraphRuleTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,217 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace unit\Parser\Productions; | ||
|
||
use League\Flysystem\FilesystemInterface; | ||
use phpDocumentor\Guides\Nodes\ParagraphNode; | ||
use phpDocumentor\Guides\Nodes\SpanNode; | ||
use phpDocumentor\Guides\ParserContext; | ||
use phpDocumentor\Guides\RestructuredText\MarkupLanguageParser; | ||
use phpDocumentor\Guides\RestructuredText\Parser\DocumentParser; | ||
use phpDocumentor\Guides\RestructuredText\Parser\LinesIterator; | ||
use phpDocumentor\Guides\RestructuredText\Parser\Productions\ParagraphRule; | ||
use phpDocumentor\Guides\UrlGenerator; | ||
use PHPUnit\Framework\TestCase; | ||
use Prophecy\PhpUnit\ProphecyTrait; | ||
|
||
final class ParagraphRuleTest extends TestCase | ||
{ | ||
use ProphecyTrait; | ||
|
||
/** | ||
* @uses \phpDocumentor\Guides\RestructuredText\Parser\LinesIterator | ||
* | ||
* @covers \phpDocumentor\Guides\RestructuredText\Parser\Productions\ParagraphRule::__construct | ||
* @covers \phpDocumentor\Guides\RestructuredText\Parser\Productions\ParagraphRule::apply | ||
* @covers \phpDocumentor\Guides\RestructuredText\Parser\Productions\ParagraphRule::applies | ||
* @covers \phpDocumentor\Guides\RestructuredText\Parser\Productions\ParagraphRule::isWhiteline | ||
* @dataProvider paragraphProvider | ||
*/ | ||
public function testParagraphNodeFromLinesIterator( | ||
string $input, | ||
ParagraphNode $node, | ||
?string $nextLine, | ||
bool $nextLiteral = false | ||
): void { | ||
$iterator = new LinesIterator(); | ||
$iterator->load($input); | ||
|
||
$parser = $this->prophesize(MarkupLanguageParser::class); | ||
$parser->getEnvironment()->willReturn( | ||
new ParserContext( | ||
'test', | ||
'test', | ||
1, | ||
$this->prophesize(FilesystemInterface::class)->reveal(), | ||
new UrlGenerator() | ||
) | ||
); | ||
$documentParser = $this->prophesize(DocumentParser::class); | ||
$documentParser->getDocumentIterator()->willReturn($iterator); | ||
|
||
$rule = new ParagraphRule( | ||
$parser->reveal(), | ||
$documentParser->reveal() | ||
); | ||
|
||
self::assertTrue($rule->applies($documentParser->reveal())); | ||
$result = $rule->apply($iterator); | ||
self::assertEquals( | ||
$node, | ||
$result | ||
); | ||
|
||
self::assertSame($nextLine, $iterator->getNextLine()); | ||
self::assertSame($nextLiteral, $documentParser->nextIndentedBlockShouldBeALiteralBlock); | ||
} | ||
|
||
public function paragraphProvider(): array | ||
{ | ||
return [ | ||
[ | ||
'input' => 'some text.', | ||
'output' => new ParagraphNode(new SpanNode('some text.', [])), | ||
'remaining' => null, | ||
], | ||
[ | ||
'input' => <<<RST | ||
some multiline | ||
paragraph | ||
RST | ||
, | ||
'output' => new ParagraphNode( | ||
new SpanNode( | ||
<<<RST | ||
some multiline | ||
paragraph | ||
RST, | ||
[] | ||
) | ||
), | ||
'remaining' => null, | ||
], | ||
[ | ||
'input' => <<<RST | ||
some multiline | ||
paragraph | ||
This is a new paragraph | ||
RST | ||
, | ||
'output' => new ParagraphNode( | ||
new SpanNode( | ||
<<<RST | ||
some multiline | ||
paragraph | ||
RST, | ||
[] | ||
) | ||
), | ||
'remaining' => '', | ||
], | ||
[ | ||
'input' => <<<RST | ||
some multiline | ||
paragraph | ||
This is a new paragraph | ||
RST | ||
, | ||
'output' => new ParagraphNode( | ||
new SpanNode( | ||
<<<RST | ||
some multiline | ||
paragraph | ||
RST, | ||
[] | ||
) | ||
), | ||
'remaining' => '', | ||
], | ||
[ | ||
'input' => <<<RST | ||
some multiline next paragraph is a literal block | ||
paragraph:: | ||
This is a new paragraph | ||
RST | ||
, | ||
'output' => new ParagraphNode( | ||
new SpanNode( | ||
<<<RST | ||
some multiline next paragraph is a literal block | ||
paragraph: | ||
RST, | ||
[] | ||
) | ||
), | ||
'remaining' => '', | ||
'nextLiteral' => true, | ||
], | ||
[ | ||
'input' => <<<RST | ||
some multiline next paragraph is a literal block | ||
paragraph:: | ||
This is a new paragraph | ||
RST | ||
, | ||
'output' => new ParagraphNode( | ||
new SpanNode( | ||
<<<RST | ||
some multiline next paragraph is a literal block | ||
paragraph: | ||
RST, | ||
[] | ||
) | ||
), | ||
'remaining' => '', | ||
'nextLiteral' => true, | ||
], | ||
[ | ||
'input' => <<<RST | ||
some multiline next paragraph is a literal block | ||
paragraph: :: | ||
This is a new paragraph | ||
RST | ||
, | ||
'output' => new ParagraphNode( | ||
new SpanNode( | ||
<<<RST | ||
some multiline next paragraph is a literal block | ||
paragraph: | ||
RST, | ||
[] | ||
) | ||
), | ||
'remaining' => '', | ||
'nextLiteral' => true, | ||
], | ||
[ | ||
'input' => <<<RST | ||
some multiline next paragraph is a literal block | ||
paragraph: | ||
:: | ||
This is a new paragraph | ||
RST | ||
, | ||
'output' => new ParagraphNode( | ||
new SpanNode( | ||
<<<RST | ||
some multiline next paragraph is a literal block | ||
paragraph: | ||
RST, | ||
[] | ||
) | ||
), | ||
'remaining' => '', | ||
'nextLiteral' => false, | ||
], | ||
]; | ||
} | ||
} |