|
| 1 | +<?php declare(strict_types=1); |
| 2 | + |
| 3 | +namespace PrinsFrank\PdfParser\Tests\Unit\Document\Generic\Character; |
| 4 | + |
| 5 | +use PHPUnit\Framework\Attributes\CoversClass; |
| 6 | +use PHPUnit\Framework\TestCase; |
| 7 | +use PrinsFrank\PdfParser\Document\Generic\Character\LiteralStringEscapeCharacter; |
| 8 | + |
| 9 | +#[CoversClass(LiteralStringEscapeCharacter::class)] |
| 10 | +class LiteralStringEscapeCharacterTest extends TestCase { |
| 11 | + public function testUnescapeCharactersMultilineExample2(): void { |
| 12 | + static::assertSame( |
| 13 | + 'These two strings are the same.', |
| 14 | + LiteralStringEscapeCharacter::unescapeCharacters( |
| 15 | + <<<EOD |
| 16 | + These \ |
| 17 | + two strings \ |
| 18 | + are the same. |
| 19 | + EOD |
| 20 | + ) |
| 21 | + ); |
| 22 | + } |
| 23 | + |
| 24 | + public function testUnescapeNewlinesExample3(): void { |
| 25 | + static::assertSame( |
| 26 | + <<<EOD |
| 27 | + This string has an end-of-line at the end of it. |
| 28 | +
|
| 29 | + EOD, |
| 30 | + LiteralStringEscapeCharacter::unescapeCharacters( |
| 31 | + <<<EOD |
| 32 | + This string has an end-of-line at the end of it. |
| 33 | +
|
| 34 | + EOD, |
| 35 | + ), |
| 36 | + ); |
| 37 | + static::assertSame( |
| 38 | + <<<EOD |
| 39 | + So does this one. |
| 40 | +
|
| 41 | + EOD, |
| 42 | + LiteralStringEscapeCharacter::unescapeCharacters( |
| 43 | + <<<EOD |
| 44 | + So does this one.\n |
| 45 | + EOD, |
| 46 | + ), |
| 47 | + ); |
| 48 | + } |
| 49 | + |
| 50 | + public function testUnescapeOctalCharactersExample4(): void { |
| 51 | + static::assertSame( |
| 52 | + 'This string contains ¥two octal charactersÇ.', |
| 53 | + LiteralStringEscapeCharacter::unescapeCharacters('This string contains \245two octal characters\307.') |
| 54 | + ); |
| 55 | + } |
| 56 | + |
| 57 | + public function testUnescapeOctalCharactersExample5(): void { |
| 58 | + static::assertSame('+', LiteralStringEscapeCharacter::unescapeCharacters('\053')); |
| 59 | + static::assertSame('+', LiteralStringEscapeCharacter::unescapeCharacters('\53')); |
| 60 | + static::assertSame("\005" . '3', LiteralStringEscapeCharacter::unescapeCharacters('\0053')); |
| 61 | + } |
| 62 | + |
| 63 | + public function testUnescapeCharacters(): void { |
| 64 | + static::assertSame("\n", LiteralStringEscapeCharacter::unescapeCharacters('\n')); |
| 65 | + static::assertSame("\r", LiteralStringEscapeCharacter::unescapeCharacters('\r')); |
| 66 | + static::assertSame("\t", LiteralStringEscapeCharacter::unescapeCharacters('\t')); |
| 67 | + static::assertSame("\x08", LiteralStringEscapeCharacter::unescapeCharacters('\b')); |
| 68 | + static::assertSame("\x0C", LiteralStringEscapeCharacter::unescapeCharacters('\f')); |
| 69 | + static::assertSame("(", LiteralStringEscapeCharacter::unescapeCharacters('\(')); |
| 70 | + static::assertSame(")", LiteralStringEscapeCharacter::unescapeCharacters('\)')); |
| 71 | + static::assertSame("\\", LiteralStringEscapeCharacter::unescapeCharacters('\\')); |
| 72 | + static::assertSame("\000", LiteralStringEscapeCharacter::unescapeCharacters('\0')); |
| 73 | + static::assertSame("\005" . '35', LiteralStringEscapeCharacter::unescapeCharacters('\00535')); |
| 74 | + static::assertSame("\005" . '353', LiteralStringEscapeCharacter::unescapeCharacters('\005353')); |
| 75 | + } |
| 76 | +} |
0 commit comments