1
0
mirror of https://github.com/erusev/parsedown.git synced 2023-08-10 21:13:06 +03:00

Expand public API of Components

Ref: https://github.com/erusev/parsedown/issues/694
This commit is contained in:
Aidan Woods
2019-02-16 20:31:20 +00:00
parent 3c0b528d54
commit 3ccd64a9a1
43 changed files with 813 additions and 76 deletions

View File

@ -0,0 +1,24 @@
<?php
namespace Erusev\Parsedown\Tests\Components\Blocks;
use Erusev\Parsedown\Components\Blocks\BlockQuote;
use Erusev\Parsedown\Parsing\Context;
use Erusev\Parsedown\Parsing\Line;
use Erusev\Parsedown\State;
use PHPUnit\Framework\TestCase;
final class BlockQuoteTest extends TestCase
{
/**
* @return void
* @throws \PHPUnit\Framework\ExpectationFailedException
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException
*/
public function testBlockQuoteAPI()
{
$BlockQuote = BlockQuote::build(new Context(new Line('> foo'), ''), new State);
$this->assertSame('foo', $BlockQuote->contents(new State)[0][0]->text());
}
}

View File

@ -0,0 +1,27 @@
<?php
namespace Erusev\Parsedown\Tests\Components\Blocks;
use Erusev\Parsedown\Components\Blocks\FencedCode;
use Erusev\Parsedown\Parsing\Context;
use Erusev\Parsedown\Parsing\Line;
use Erusev\Parsedown\State;
use PHPUnit\Framework\TestCase;
final class FencedCodeTest extends TestCase
{
/**
* @return void
* @throws \PHPUnit\Framework\ExpectationFailedException
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException
*/
public function testFencedCodeAPI()
{
$FencedCode = FencedCode::build(new Context(new Line('```foo'), ''), new State);
$FencedCode = $FencedCode->advance(new Context(new Line('bar'), ''), new State);
$FencedCode = $FencedCode->advance(new Context(new Line('```'), ''), new State);
$this->assertSame('foo', $FencedCode->infostring());
$this->assertSame("bar\n", $FencedCode->code());
}
}

View File

@ -0,0 +1,25 @@
<?php
namespace Erusev\Parsedown\Tests\Components\Blocks;
use Erusev\Parsedown\Components\Blocks\Header;
use Erusev\Parsedown\Parsing\Context;
use Erusev\Parsedown\Parsing\Line;
use Erusev\Parsedown\State;
use PHPUnit\Framework\TestCase;
final class HeaderTest extends TestCase
{
/**
* @return void
* @throws \PHPUnit\Framework\ExpectationFailedException
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException
*/
public function testHeaderAPI()
{
$Header = Header::build(new Context(new Line('## foo'), ''), new State);
$this->assertSame('foo', $Header->text());
$this->assertSame(2, $Header->level());
}
}

View File

@ -0,0 +1,24 @@
<?php
namespace Erusev\Parsedown\Tests\Components\Blocks;
use Erusev\Parsedown\Components\Blocks\IndentedCode;
use Erusev\Parsedown\Parsing\Context;
use Erusev\Parsedown\Parsing\Line;
use Erusev\Parsedown\State;
use PHPUnit\Framework\TestCase;
final class IndentedCodeTest extends TestCase
{
/**
* @return void
* @throws \PHPUnit\Framework\ExpectationFailedException
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException
*/
public function testIndentedCodeAPI()
{
$IndentedCode = IndentedCode::build(new Context(new Line(' foo'), ''), new State);
$this->assertSame("foo\n", $IndentedCode->code());
}
}

View File

@ -0,0 +1,24 @@
<?php
namespace Erusev\Parsedown\Tests\Components\Blocks;
use Erusev\Parsedown\Components\Blocks\Markup;
use Erusev\Parsedown\Parsing\Context;
use Erusev\Parsedown\Parsing\Line;
use Erusev\Parsedown\State;
use PHPUnit\Framework\TestCase;
final class MarkupTest extends TestCase
{
/**
* @return void
* @throws \PHPUnit\Framework\ExpectationFailedException
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException
*/
public function testMarkupAPI()
{
$Markup = Markup::build(new Context(new Line('<pre>'), ''), new State);
$this->assertSame('<pre>', $Markup->html());
}
}

View File

@ -0,0 +1,24 @@
<?php
namespace Erusev\Parsedown\Tests\Components\Blocks;
use Erusev\Parsedown\Components\Blocks\Paragraph;
use Erusev\Parsedown\Parsing\Context;
use Erusev\Parsedown\Parsing\Line;
use Erusev\Parsedown\State;
use PHPUnit\Framework\TestCase;
final class ParagraphTest extends TestCase
{
/**
* @return void
* @throws \PHPUnit\Framework\ExpectationFailedException
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException
*/
public function testParagraphAPI()
{
$Paragraph = Paragraph::build(new Context(new Line('foo'), ''), new State);
$this->assertSame('foo', $Paragraph->text());
}
}

View File

@ -0,0 +1,27 @@
<?php
namespace Erusev\Parsedown\Tests\Components\Blocks;
use Erusev\Parsedown\Components\Blocks\Paragraph;
use Erusev\Parsedown\Components\Blocks\SetextHeader;
use Erusev\Parsedown\Parsing\Context;
use Erusev\Parsedown\Parsing\Line;
use Erusev\Parsedown\State;
use PHPUnit\Framework\TestCase;
final class SetextHeaderTest extends TestCase
{
/**
* @return void
* @throws \PHPUnit\Framework\ExpectationFailedException
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException
*/
public function testSetextHeaderAPI()
{
$Paragraph = Paragraph::build(new Context(new Line('foo'), ''), new State);
$SetextHeader = SetextHeader::build(new Context(new Line('==='), ''), new State, $Paragraph);
$this->assertSame('foo', $SetextHeader->text());
$this->assertSame(1, $SetextHeader->level());
}
}

View File

@ -0,0 +1,32 @@
<?php
namespace Erusev\Parsedown\Tests\Components\Blocks;
use Erusev\Parsedown\Components\Blocks\TList;
use Erusev\Parsedown\Parsing\Context;
use Erusev\Parsedown\Parsing\Line;
use Erusev\Parsedown\State;
use PHPUnit\Framework\TestCase;
final class TListTest extends TestCase
{
/**
* @return void
* @throws \PHPUnit\Framework\ExpectationFailedException
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException
*/
public function testTListAPI()
{
$List = TList::build(new Context(new Line('* foo'), ''), new State);
$this->assertSame('foo', $List->items(new State)[0][0][0]->text());
$this->assertSame('ul', $List->type());
$this->assertSame(null, $List->listStart());
$List = TList::build(new Context(new Line('00100. foo'), ''), new State);
$this->assertSame('foo', $List->items(new State)[0][0][0]->text());
$this->assertSame('ol', $List->type());
$this->assertSame(100, $List->listStart());
}
}

View File

@ -0,0 +1,34 @@
<?php
namespace Erusev\Parsedown\Tests\Components\Blocks;
use Erusev\Parsedown\Components\Blocks\Paragraph;
use Erusev\Parsedown\Components\Blocks\Table;
use Erusev\Parsedown\Parsing\Context;
use Erusev\Parsedown\Parsing\Line;
use Erusev\Parsedown\State;
use PHPUnit\Framework\TestCase;
final class TableTest extends TestCase
{
/**
* @return void
* @throws \PHPUnit\Framework\ExpectationFailedException
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException
*/
public function testTableAPI()
{
$Paragraph = Paragraph::build(new Context(new Line('foo | bar'), ''), new State);
$Table = Table::build(new Context(new Line('--- | :---'), ''), new State, $Paragraph);
$Table = $Table->advance(new Context(new Line('baz | boo'), ''), new State);
$this->assertSame('foo', $Table->headerRow(new State)[0][0]->text());
$this->assertSame('bar', $Table->headerRow(new State)[1][0]->text());
$this->assertSame('baz', $Table->rows(new State)[0][0][0]->text());
$this->assertSame('boo', $Table->rows(new State)[0][1][0]->text());
$this->assertSame(null, $Table->alignments()[0]);
$this->assertSame('left', $Table->alignments()[1]);
}
}

View File

@ -0,0 +1,23 @@
<?php
namespace Erusev\Parsedown\Tests\Components\Inlines;
use Erusev\Parsedown\Components\Inlines\Code;
use Erusev\Parsedown\Parsing\Excerpt;
use Erusev\Parsedown\State;
use PHPUnit\Framework\TestCase;
final class CodeTest extends TestCase
{
/**
* @return void
* @throws \PHPUnit\Framework\ExpectationFailedException
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException
*/
public function testCodeAPI()
{
$Code = Code::build(new Excerpt('`foo`', 0), new State);
$this->assertSame('foo', $Code->text());
}
}

View File

@ -0,0 +1,29 @@
<?php
namespace Erusev\Parsedown\Tests\Components\Inlines;
use Erusev\Parsedown\Components\Inlines\Email;
use Erusev\Parsedown\Parsing\Excerpt;
use Erusev\Parsedown\State;
use PHPUnit\Framework\TestCase;
final class EmailTest extends TestCase
{
/**
* @return void
* @throws \PHPUnit\Framework\ExpectationFailedException
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException
*/
public function testEmailAPI()
{
$Email = Email::build(new Excerpt('<foo@bar.com>', 0), new State);
$this->assertSame('foo@bar.com', $Email->text());
$this->assertSame('mailto:foo@bar.com', $Email->url());
$Email = Email::build(new Excerpt('<mailto:foo@bar.com>', 0), new State);
$this->assertSame('mailto:foo@bar.com', $Email->text());
$this->assertSame('mailto:foo@bar.com', $Email->url());
}
}

View File

@ -0,0 +1,27 @@
<?php
namespace Erusev\Parsedown\Tests\Components\Inlines;
use Erusev\Parsedown\Components\Inlines\Emphasis;
use Erusev\Parsedown\Parsing\Excerpt;
use Erusev\Parsedown\State;
use PHPUnit\Framework\TestCase;
final class EmphasisTest extends TestCase
{
/**
* @return void
* @throws \PHPUnit\Framework\ExpectationFailedException
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException
*/
public function testEmphasisAPI()
{
$Emphasis = Emphasis::build(new Excerpt('*foo*', 0), new State);
$this->assertSame('foo', $Emphasis->text());
$Emphasis = Emphasis::build(new Excerpt('**foo**', 0), new State);
$this->assertSame('foo', $Emphasis->text());
}
}

View File

@ -0,0 +1,23 @@
<?php
namespace Erusev\Parsedown\Tests\Components\Inlines;
use Erusev\Parsedown\Components\Inlines\EscapeSequence;
use Erusev\Parsedown\Parsing\Excerpt;
use Erusev\Parsedown\State;
use PHPUnit\Framework\TestCase;
final class EscapeSequenceTest extends TestCase
{
/**
* @return void
* @throws \PHPUnit\Framework\ExpectationFailedException
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException
*/
public function testEscapeSequenceAPI()
{
$EscapeSequence = EscapeSequence::build(new Excerpt('\`', 0), new State);
$this->assertSame('`', $EscapeSequence->char());
}
}

View File

@ -0,0 +1,31 @@
<?php
namespace Erusev\Parsedown\Tests\Components\Inlines;
use Erusev\Parsedown\Components\Inlines\Image;
use Erusev\Parsedown\Parsing\Excerpt;
use Erusev\Parsedown\State;
use PHPUnit\Framework\TestCase;
final class ImageTest extends TestCase
{
/**
* @return void
* @throws \PHPUnit\Framework\ExpectationFailedException
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException
*/
public function testImageAPI()
{
$Image = Image::build(new Excerpt('![foo](https://example.com)', 0), new State);
$this->assertSame('foo', $Image->label());
$this->assertSame('https://example.com', $Image->url());
$this->assertSame(null, $Image->title());
$Image = Image::build(new Excerpt('![foo](https://example.com "bar")', 0), new State);
$this->assertSame('foo', $Image->label());
$this->assertSame('https://example.com', $Image->url());
$this->assertSame("bar", $Image->title());
}
}

View File

@ -0,0 +1,31 @@
<?php
namespace Erusev\Parsedown\Tests\Components\Inlines;
use Erusev\Parsedown\Components\Inlines\Link;
use Erusev\Parsedown\Parsing\Excerpt;
use Erusev\Parsedown\State;
use PHPUnit\Framework\TestCase;
final class LinkTest extends TestCase
{
/**
* @return void
* @throws \PHPUnit\Framework\ExpectationFailedException
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException
*/
public function testLinkAPI()
{
$Link = Link::build(new Excerpt('[foo](https://example.com)', 0), new State);
$this->assertSame('foo', $Link->label());
$this->assertSame('https://example.com', $Link->url());
$this->assertSame(null, $Link->title());
$Link = Link::build(new Excerpt('[foo](https://example.com "bar")', 0), new State);
$this->assertSame('foo', $Link->label());
$this->assertSame('https://example.com', $Link->url());
$this->assertSame("bar", $Link->title());
}
}

View File

@ -0,0 +1,23 @@
<?php
namespace Erusev\Parsedown\Tests\Components\Inlines;
use Erusev\Parsedown\Components\Inlines\Markup;
use Erusev\Parsedown\Parsing\Excerpt;
use Erusev\Parsedown\State;
use PHPUnit\Framework\TestCase;
final class MarkupTest extends TestCase
{
/**
* @return void
* @throws \PHPUnit\Framework\ExpectationFailedException
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException
*/
public function testMarkupAPI()
{
$Markup = Markup::build(new Excerpt('<foo>', 0), new State);
$this->assertSame('<foo>', $Markup->html());
}
}

View File

@ -4,6 +4,7 @@ namespace Erusev\Parsedown\Tests\Components\Inlines;
use Erusev\Parsedown\Components\Inlines\PlainText;
use Erusev\Parsedown\Parsing\Excerpt;
use Erusev\Parsedown\State;
use PHPUnit\Framework\TestCase;
final class PlainTextTest extends TestCase
@ -13,9 +14,9 @@ final class PlainTextTest extends TestCase
* @throws \PHPUnit\Framework\ExpectationFailedException
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException
*/
public function testPlainTextText()
public function testPlainTextAPI()
{
$Plaintext = Plaintext::build(new Excerpt('foo', 0));
$Plaintext = Plaintext::build(new Excerpt('foo', 0), new State);
$this->assertSame('foo', $Plaintext->text());
}

View File

@ -0,0 +1,27 @@
<?php
namespace Erusev\Parsedown\Tests\Components\Inlines;
use Erusev\Parsedown\Components\Inlines\SpecialCharacter;
use Erusev\Parsedown\Parsing\Excerpt;
use Erusev\Parsedown\State;
use PHPUnit\Framework\TestCase;
final class SpecialCharacterTest extends TestCase
{
/**
* @return void
* @throws \PHPUnit\Framework\ExpectationFailedException
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException
*/
public function testSpecialCharacterAPI()
{
$SpecialCharacter = SpecialCharacter::build(new Excerpt('&nbsp;', 0), new State);
$this->assertSame('nbsp', $SpecialCharacter->charCode());
$SpecialCharacter = SpecialCharacter::build(new Excerpt('&#3C;', 0), new State);
$this->assertSame('#3C', $SpecialCharacter->charCode());
}
}

View File

@ -0,0 +1,23 @@
<?php
namespace Erusev\Parsedown\Tests\Components\Inlines;
use Erusev\Parsedown\Components\Inlines\Strikethrough;
use Erusev\Parsedown\Parsing\Excerpt;
use Erusev\Parsedown\State;
use PHPUnit\Framework\TestCase;
final class StrikethroughTest extends TestCase
{
/**
* @return void
* @throws \PHPUnit\Framework\ExpectationFailedException
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException
*/
public function testStrikethroughAPI()
{
$Strikethrough = Strikethrough::build(new Excerpt('~~foo~~', 0), new State);
$this->assertSame('foo', $Strikethrough->text());
}
}

View File

@ -0,0 +1,23 @@
<?php
namespace Erusev\Parsedown\Tests\Components\Inlines;
use Erusev\Parsedown\Components\Inlines\UrlTag;
use Erusev\Parsedown\Parsing\Excerpt;
use Erusev\Parsedown\State;
use PHPUnit\Framework\TestCase;
final class UrlTagTest extends TestCase
{
/**
* @return void
* @throws \PHPUnit\Framework\ExpectationFailedException
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException
*/
public function testUrlTagAPI()
{
$UrlTag = UrlTag::build(new Excerpt('<https://example.com>', 0), new State);
$this->assertSame('https://example.com', $UrlTag->url());
}
}

View File

@ -0,0 +1,23 @@
<?php
namespace Erusev\Parsedown\Tests\Components\Inlines;
use Erusev\Parsedown\Components\Inlines\Url;
use Erusev\Parsedown\Parsing\Excerpt;
use Erusev\Parsedown\State;
use PHPUnit\Framework\TestCase;
final class UrlTest extends TestCase
{
/**
* @return void
* @throws \PHPUnit\Framework\ExpectationFailedException
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException
*/
public function testUrlAPI()
{
$Url = Url::build(new Excerpt('https://example.com', 0), new State);
$this->assertSame('https://example.com', $Url->url());
}
}