| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- <?php
- declare(strict_types=1);
-
- use PHPUnit\Framework\TestCase;
-
- require_once __DIR__ . '/../php/markdown.php';
-
- final class UtilsTests extends TestCase {
- public function test_stripIndent() {
- $this->assertSame('', MDUtils::stripIndent(''));
- $this->assertSame('', MDUtils::stripIndent(' '));
- $this->assertSame('foo', MDUtils::stripIndent('foo'));
- $this->assertSame('foo', MDUtils::stripIndent(' foo'));
- $this->assertSame('foo', MDUtils::stripIndent(' foo'));
- $this->assertSame('foo', MDUtils::stripIndent(' foo'));
- $this->assertSame('foo', MDUtils::stripIndent(' foo'));
- $this->assertSame(' foo', MDUtils::stripIndent(' foo'));
- $this->assertSame('foo', MDUtils::stripIndent("\tfoo"));
- $this->assertSame("\tfoo", MDUtils::stripIndent("\t\tfoo"));
- $this->assertSame('foo', MDUtils::stripIndent("\t\tfoo", 2));
- $this->assertSame('foo', MDUtils::stripIndent(' foo', 2));
- }
-
- public function test_countIndents() {
- $this->assertSame(0, MDUtils::countIndents(''));
- $this->assertSame(1, MDUtils::countIndents(' '));
- $this->assertSame(1, MDUtils::countIndents(' '));
- $this->assertSame(0, MDUtils::countIndents('foo'));
- $this->assertSame(0, MDUtils::countIndents('foo'));
- $this->assertSame(1, MDUtils::countIndents(' foo'));
- $this->assertSame(1, MDUtils::countIndents(' foo'));
- $this->assertSame(1, MDUtils::countIndents(' foo'));
- $this->assertSame(1, MDUtils::countIndents(' foo'));
- $this->assertSame(2, MDUtils::countIndents(' foo'));
- $this->assertSame(1, MDUtils::countIndents("\tfoo"));
- $this->assertSame(2, MDUtils::countIndents("\t\tfoo"));
-
- $this->assertSame(0, MDUtils::countIndents('', true));
- $this->assertSame(0, MDUtils::countIndents(' ', true));
- $this->assertSame(1, MDUtils::countIndents(' ', true));
- $this->assertSame(0, MDUtils::countIndents('foo', true));
- $this->assertSame(0, MDUtils::countIndents(' foo', true));
- $this->assertSame(0, MDUtils::countIndents(' foo', true));
- $this->assertSame(0, MDUtils::countIndents(' foo', true));
- $this->assertSame(1, MDUtils::countIndents(' foo', true));
- $this->assertSame(1, MDUtils::countIndents(' foo', true));
- $this->assertSame(1, MDUtils::countIndents("\tfoo", true));
- $this->assertSame(2, MDUtils::countIndents("\t\tfoo", true));
- }
-
- public function test_tokenizeLabel() {
- // Escapes are preserved
- $this->assertSame([ '[foo]', 'foo' ], MDToken::tokenizeLabel('[foo] bar'));
- $this->assertSame([ '[foo\\[]', 'foo\\[' ], MDToken::tokenizeLabel('[foo\\[] bar'));
- $this->assertSame([ '[foo\\]]', 'foo\\]' ], MDToken::tokenizeLabel('[foo\\]] bar'));
- $this->assertSame([ '[foo[]]', 'foo[]' ], MDToken::tokenizeLabel('[foo[]] bar'));
- $this->assertSame([ '[foo\\(]', 'foo\\(' ], MDToken::tokenizeLabel('[foo\\(] bar'));
- $this->assertSame([ '[foo\\)]', 'foo\\)' ], MDToken::tokenizeLabel('[foo\\)] bar'));
- $this->assertSame([ '[foo()]', 'foo()' ], MDToken::tokenizeLabel('[foo()] bar'));
-
- $this->assertSame(null, MDToken::tokenizeLabel('foo bar'));
- $this->assertSame(null, MDToken::tokenizeLabel('[foo\\] bar'));
- $this->assertSame(null, MDToken::tokenizeLabel('[foo bar'));
- $this->assertSame(null, MDToken::tokenizeLabel('[foo[] bar'));
- }
-
- public function test_tokenizeURL() {
- $this->assertSame([ '(page.html)', 'page.html', null ], MDToken::tokenizeURL('(page.html) foo'));
- $this->assertSame([ '(page.html "link title")', 'page.html', 'link title' ], MDToken::tokenizeURL('(page.html "link title") foo'));
- $this->assertSame([ '(https://example.com/path/page.html?query=foo&bar=baz#fragment)', 'https://example.com/path/page.html?query=foo&bar=baz#fragment', null ], MDToken::tokenizeURL('(https://example.com/path/page.html?query=foo&bar=baz#fragment) foo'));
-
- $this->assertSame(null, MDToken::tokenizeURL('page.html foo'));
- $this->assertSame(null, MDToken::tokenizeURL('(page.html foo'));
- $this->assertSame(null, MDToken::tokenizeURL('page.html) foo'));
- $this->assertSame(null, MDToken::tokenizeURL('(page.html "title) foo'));
- $this->assertSame(null, MDToken::tokenizeURL('(page .html) foo'));
- $this->assertSame(null, MDToken::tokenizeURL('(user@example.com) foo'));
- $this->assertSame(null, MDToken::tokenizeURL('(user@example.com "title") foo'));
- }
-
- public function test_tokenizeEmail() {
- $this->assertSame([ '(user@example.com)', 'user@example.com', null ], MDToken::tokenizeEmail('(user@example.com)'));
- $this->assertSame([ '(user@example.com "link title")', 'user@example.com', 'link title' ], MDToken::tokenizeEmail('(user@example.com "link title")'));
-
- $this->assertSame(null, MDToken::tokenizeEmail('(https://example.com) foo'));
- $this->assertSame(null, MDToken::tokenizeEmail('(https://example.com "link title") foo'));
- $this->assertSame(null, MDToken::tokenizeEmail('(user@example.com "link title) foo'));
- $this->assertSame(null, MDToken::tokenizeEmail('(user@example.com foo'));
- $this->assertSame(null, MDToken::tokenizeEmail('user@example.com) foo'));
- }
- }
- ?>
|