mirror of
https://github.com/erusev/parsedown.git
synced 2023-08-10 21:13:06 +03:00
Improve tests
This commit is contained in:
parent
69f6754c4d
commit
4fb6ac31a5
@ -48,7 +48,7 @@ jobs:
|
||||
- composer install --prefer-dist --no-interaction --no-progress
|
||||
script:
|
||||
- composer test-units
|
||||
- vendor/bin/infection --show-mutations --threads=4 --min-msi=85 --min-covered-msi=90
|
||||
- vendor/bin/infection --show-mutations --threads=4 --min-msi=90 --min-covered-msi=90
|
||||
- <<: *MUTATION_AND_UNIT_TEST
|
||||
php: 7.2
|
||||
- <<: *MUTATION_AND_UNIT_TEST
|
||||
|
10
psalm.xml
10
psalm.xml
@ -13,16 +13,6 @@
|
||||
<PossiblyUnusedMethod>
|
||||
<errorLevel type="suppress">
|
||||
<directory name="tests" />
|
||||
<referencedMethod name="Erusev\Parsedown\Parsing\Lines::appendingContext" />
|
||||
<referencedMethod name="Erusev\Parsedown\Html\Sanitisation\Escaper::htmlElementValue" />
|
||||
<referencedMethod name="Erusev\Parsedown\Configurables\InlineTypes::addingHighPrecedence" />
|
||||
<referencedMethod name="Erusev\Parsedown\Configurables\InlineTypes::addingLowPrecedence" />
|
||||
<referencedMethod name="Erusev\Parsedown\Configurables\BlockTypes::addingMarkedHighPrecedence" />
|
||||
<referencedMethod name="Erusev\Parsedown\Configurables\BlockTypes::addingMarkedLowPrecedence" />
|
||||
<referencedMethod name="Erusev\Parsedown\Configurables\BlockTypes::addingUnmarkedHighPrecedence" />
|
||||
<referencedMethod name="Erusev\Parsedown\Configurables\BlockTypes::addingUnmarkedLowPrecedence" />
|
||||
<referencedMethod name="Erusev\Parsedown\Parsing\Lines::containsBlankLines" />
|
||||
<referencedMethod name="Erusev\Parsedown\Parsing\Lines::trailingBlankLines" />
|
||||
</errorLevel>
|
||||
</PossiblyUnusedMethod>
|
||||
<PropertyNotSetInConstructor>
|
||||
|
@ -99,7 +99,10 @@ final class BlockTypes implements Configurable
|
||||
{
|
||||
return $this->settingMarked(
|
||||
$marker,
|
||||
\array_merge($newBlockTypes, $this->blockTypes[$marker])
|
||||
\array_merge(
|
||||
$newBlockTypes,
|
||||
isset($this->blockTypes[$marker]) ? $this->blockTypes[$marker] : []
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@ -112,7 +115,10 @@ final class BlockTypes implements Configurable
|
||||
{
|
||||
return $this->settingMarked(
|
||||
$marker,
|
||||
\array_merge($this->blockTypes[$marker], $newBlockTypes)
|
||||
\array_merge(
|
||||
isset($this->blockTypes[$marker]) ? $this->blockTypes[$marker] : [],
|
||||
$newBlockTypes
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -81,7 +81,10 @@ final class InlineTypes implements Configurable
|
||||
{
|
||||
return $this->setting(
|
||||
$marker,
|
||||
\array_merge($newInlineTypes, $this->inlineTypes[$marker])
|
||||
\array_merge(
|
||||
$newInlineTypes,
|
||||
isset($this->inlineTypes[$marker]) ? $this->inlineTypes[$marker] : []
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@ -94,7 +97,10 @@ final class InlineTypes implements Configurable
|
||||
{
|
||||
return $this->setting(
|
||||
$marker,
|
||||
\array_merge($this->inlineTypes[$marker], $newInlineTypes)
|
||||
\array_merge(
|
||||
isset($this->inlineTypes[$marker]) ? $this->inlineTypes[$marker] : [],
|
||||
$newInlineTypes
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
45
tests/src/Configurables/BlockTypesTest.php
Normal file
45
tests/src/Configurables/BlockTypesTest.php
Normal file
@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace Erusev\Parsedown\Tests\Configurables;
|
||||
|
||||
use Erusev\Parsedown\Components\Blocks\IndentedCode;
|
||||
use Erusev\Parsedown\Components\Blocks\Markup;
|
||||
use Erusev\Parsedown\Components\Blocks\Rule;
|
||||
use Erusev\Parsedown\Configurables\BlockTypes;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
final class BlockTypesTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @return void
|
||||
* @throws \PHPUnit\Framework\ExpectationFailedException
|
||||
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException
|
||||
*/
|
||||
public function testAddingTypes()
|
||||
{
|
||||
$BlockTypes = new BlockTypes([], []);
|
||||
$this->assertSame([], $BlockTypes->markedBy('@'));
|
||||
$this->assertSame([], $BlockTypes->unmarked());
|
||||
|
||||
$BlockTypes = $BlockTypes->addingMarkedHighPrecedence('@', [IndentedCode::class]);
|
||||
$this->assertSame([IndentedCode::class], $BlockTypes->markedBy('@'));
|
||||
|
||||
$BlockTypes = $BlockTypes->addingUnmarkedHighPrecedence([Markup::class]);
|
||||
$this->assertSame([IndentedCode::class], $BlockTypes->markedBy('@'));
|
||||
$this->assertSame([Markup::class], $BlockTypes->unmarked());
|
||||
|
||||
$BlockTypes = $BlockTypes->addingMarkedHighPrecedence('@', [Markup::class]);
|
||||
$this->assertSame([Markup::class, IndentedCode::class], $BlockTypes->markedBy('@'));
|
||||
|
||||
$BlockTypes = $BlockTypes->addingUnmarkedHighPrecedence([Rule::class]);
|
||||
$this->assertSame([Markup::class, IndentedCode::class], $BlockTypes->markedBy('@'));
|
||||
$this->assertSame([Rule::class, Markup::class], $BlockTypes->unmarked());
|
||||
|
||||
$BlockTypes = $BlockTypes->addingMarkedLowPrecedence('@', [Rule::class]);
|
||||
$this->assertSame([Markup::class, IndentedCode::class, Rule::class], $BlockTypes->markedBy('@'));
|
||||
|
||||
$BlockTypes = $BlockTypes->addingUnmarkedLowPrecedence([IndentedCode::class]);
|
||||
$this->assertSame([Markup::class, IndentedCode::class, Rule::class], $BlockTypes->markedBy('@'));
|
||||
$this->assertSame([Rule::class, Markup::class, IndentedCode::class], $BlockTypes->unmarked());
|
||||
}
|
||||
}
|
32
tests/src/Configurables/InlineTypesTest.php
Normal file
32
tests/src/Configurables/InlineTypesTest.php
Normal file
@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace Erusev\Parsedown\Tests\Configurables;
|
||||
|
||||
use Erusev\Parsedown\Components\Inlines\Code;
|
||||
use Erusev\Parsedown\Components\Inlines\Emphasis;
|
||||
use Erusev\Parsedown\Components\Inlines\Link;
|
||||
use Erusev\Parsedown\Configurables\InlineTypes;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
final class InlineTypesTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @return void
|
||||
* @throws \PHPUnit\Framework\ExpectationFailedException
|
||||
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException
|
||||
*/
|
||||
public function testAddingTypes()
|
||||
{
|
||||
$InlineTypes = new InlineTypes([]);
|
||||
$this->assertSame([], $InlineTypes->markedBy('@'));
|
||||
|
||||
$InlineTypes = $InlineTypes->addingHighPrecedence('@', [Emphasis::class]);
|
||||
$this->assertSame([Emphasis::class], $InlineTypes->markedBy('@'));
|
||||
|
||||
$InlineTypes = $InlineTypes->addingHighPrecedence('@', [Code::class]);
|
||||
$this->assertSame([Code::class, Emphasis::class], $InlineTypes->markedBy('@'));
|
||||
|
||||
$InlineTypes = $InlineTypes->addingLowPrecedence('@', [Link::class]);
|
||||
$this->assertSame([Code::class, Emphasis::class, Link::class], $InlineTypes->markedBy('@'));
|
||||
}
|
||||
}
|
22
tests/src/Html/Sanitisation/EscaperTest.php
Normal file
22
tests/src/Html/Sanitisation/EscaperTest.php
Normal file
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace Erusev\Parsedown\Tests\Html\Sanitisation;
|
||||
|
||||
use Erusev\Parsedown\Html\Sanitisation\Escaper;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
final class EscaperTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @return void
|
||||
* @throws \PHPUnit\Framework\ExpectationFailedException
|
||||
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException
|
||||
*/
|
||||
public function testHtmlElementValue()
|
||||
{
|
||||
$this->assertSame(
|
||||
Escaper::htmlElementValue('<foo bar="baz" boo=\'bim\'>&'),
|
||||
'<foo bar="baz" boo=\'bim\'>&'
|
||||
);
|
||||
}
|
||||
}
|
82
tests/src/Parsing/LinesTest.php
Normal file
82
tests/src/Parsing/LinesTest.php
Normal file
@ -0,0 +1,82 @@
|
||||
<?php
|
||||
|
||||
namespace Erusev\Parsedown\Tests\Parsing;
|
||||
|
||||
use Erusev\Parsedown\Parsing\Context;
|
||||
use Erusev\Parsedown\Parsing\Line;
|
||||
use Erusev\Parsedown\Parsing\Lines;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
final class LinesTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @return void
|
||||
* @throws \PHPUnit\Framework\ExpectationFailedException
|
||||
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException
|
||||
*/
|
||||
public function testContainsBlankLines()
|
||||
{
|
||||
$Lines = Lines::fromTextLines('foo', 0);
|
||||
|
||||
$this->assertFalse($Lines->containsBlankLines());
|
||||
|
||||
$Lines = $Lines->appendingTextLines('bar', 0);
|
||||
|
||||
$this->assertFalse($Lines->containsBlankLines());
|
||||
|
||||
$Lines = $Lines->appendingTextLines("boo\nbaz", 0);
|
||||
|
||||
$this->assertFalse($Lines->containsBlankLines());
|
||||
|
||||
$Lines = $Lines->appendingTextLines("zoo\n\nzoom", 0);
|
||||
|
||||
$this->assertTrue($Lines->containsBlankLines());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
* @throws \PHPUnit\Framework\ExpectationFailedException
|
||||
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException
|
||||
*/
|
||||
public function testAppendContext()
|
||||
{
|
||||
$Lines = Lines::fromTextLines('foo', 0);
|
||||
|
||||
$this->assertFalse($Lines->containsBlankLines());
|
||||
|
||||
$Lines = $Lines->appendingContext(new Context(new Line('bar'), "\n \n"));
|
||||
|
||||
$this->assertTrue($Lines->containsBlankLines());
|
||||
$this->assertSame($Lines->trailingBlankLines(), 0);
|
||||
|
||||
$Lines = $Lines->appendingContext(new Context(new Line('boo'), ''));
|
||||
$Lines = $Lines->appendingContext(new Context(new Line('baz'), ''));
|
||||
|
||||
$this->assertTrue($Lines->containsBlankLines());
|
||||
$this->assertSame($Lines->trailingBlankLines(), 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
* @throws \PHPUnit\Framework\ExpectationFailedException
|
||||
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException
|
||||
*/
|
||||
public function testTrailingBlankLines()
|
||||
{
|
||||
$Lines = Lines::fromTextLines('foo', 0);
|
||||
|
||||
$this->assertSame($Lines->trailingBlankLines(), 0);
|
||||
|
||||
$Lines = $Lines->appendingTextLines("bar\n", 0);
|
||||
|
||||
$this->assertSame($Lines->trailingBlankLines(), 1);
|
||||
|
||||
$Lines = $Lines->appendingTextLines("boo\nbaz\n\n", 0);
|
||||
|
||||
$this->assertSame($Lines->trailingBlankLines(), 2);
|
||||
|
||||
$Lines = $Lines->appendingTextLines("zoo\n\nzoom", 0);
|
||||
|
||||
$this->assertSame($Lines->trailingBlankLines(), 0);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user