|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace gapple\Tests\StructuredFields; |
| 4 | + |
| 5 | +use gapple\StructuredFields\ParsingInput; |
| 6 | +use PHPUnit\Framework\TestCase; |
| 7 | + |
| 8 | +class ParsingInputTest extends TestCase |
| 9 | +{ |
| 10 | + public function testGetEmptyChar(): void |
| 11 | + { |
| 12 | + $input = new ParsingInput(''); |
| 13 | + $this->expectException(\RuntimeException::class); |
| 14 | + $input->getChar(); |
| 15 | + } |
| 16 | + |
| 17 | + /** |
| 18 | + * @return array<string, array{string, bool, string}> |
| 19 | + */ |
| 20 | + public static function trimProvider(): array |
| 21 | + { |
| 22 | + return [ |
| 23 | + 'space' => [' test ', false, 'test '], |
| 24 | + 'ows' => [" \t test ", true, 'test '], |
| 25 | + 'non-ows' => [" \t test ", false, "\t test "], |
| 26 | + ]; |
| 27 | + } |
| 28 | + |
| 29 | + /** |
| 30 | + * @dataProvider trimProvider |
| 31 | + */ |
| 32 | + public function testTrim(string $value, bool $ows, string $expected): void |
| 33 | + { |
| 34 | + $input = new ParsingInput($value); |
| 35 | + $input->trim($ows); |
| 36 | + |
| 37 | + $this->assertEquals($expected, $input->remaining()); |
| 38 | + } |
| 39 | + |
| 40 | + public function testConsumeExcess(): void |
| 41 | + { |
| 42 | + $input = new ParsingInput('test'); |
| 43 | + $this->expectException(\RuntimeException::class); |
| 44 | + $this->expectExceptionMessage('Reached end of value'); |
| 45 | + $input->consume(5); |
| 46 | + } |
| 47 | + |
| 48 | + public function testConsumeNotMatched(): void |
| 49 | + { |
| 50 | + $input = new ParsingInput('test'); |
| 51 | + $this->expectException(\RuntimeException::class); |
| 52 | + $this->expectExceptionMessage('Unexpected character'); |
| 53 | + $input->consumeString('foo'); |
| 54 | + } |
| 55 | +} |
0 commit comments