|
14 | 14 | use PHPUnit\Framework\TestCase;
|
15 | 15 | use Symfony\Component\Yaml\Dumper;
|
16 | 16 | use Symfony\Component\Yaml\Exception\DumpException;
|
| 17 | +use Symfony\Component\Yaml\Exception\ParseException; |
17 | 18 | use Symfony\Component\Yaml\Parser;
|
18 | 19 | use Symfony\Component\Yaml\Tag\TaggedValue;
|
19 | 20 | use Symfony\Component\Yaml\Yaml;
|
@@ -602,6 +603,52 @@ public function testDumpingMultiLineStringAsScalarBlockTaggedValue()
|
602 | 603 | $this->assertSameData($data, $this->parser->parse($expected, Yaml::PARSE_CUSTOM_TAGS));
|
603 | 604 | }
|
604 | 605 |
|
| 606 | + public function testDumpingTaggedMultiLineInList() |
| 607 | + { |
| 608 | + $data = [ |
| 609 | + new TaggedValue('bar', "a\nb"), |
| 610 | + ]; |
| 611 | + $expected = "- !bar |\n a\n b"; |
| 612 | + $this->assertSame($expected, $this->dumper->dump($data, 2, 0, Yaml::DUMP_MULTI_LINE_LITERAL_BLOCK)); |
| 613 | + |
| 614 | + // @todo Fix the parser, eliminate these exceptions. |
| 615 | + $this->expectException(ParseException::class); |
| 616 | + $this->expectExceptionMessage('Unable to parse at line 3 (near "!bar |").'); |
| 617 | + |
| 618 | + $this->parser->parse($expected, Yaml::PARSE_CUSTOM_TAGS); |
| 619 | + } |
| 620 | + |
| 621 | + public function testDumpingTaggedMultiLineTrailingNewlinesInMap() |
| 622 | + { |
| 623 | + $data = [ |
| 624 | + 'foo' => new TaggedValue('bar', "a\nb\n\n\n"), |
| 625 | + ]; |
| 626 | + $expected = "foo: !bar |\n a\n b\n \n \n "; |
| 627 | + $this->assertSame($expected, $this->dumper->dump($data, 2, 0, Yaml::DUMP_MULTI_LINE_LITERAL_BLOCK)); |
| 628 | + |
| 629 | + // @todo Fix the parser, the result should be identical to $data. |
| 630 | + $this->assertSameData( |
| 631 | + [ |
| 632 | + 'foo' => new TaggedValue('bar', "a\nb\n"), |
| 633 | + ], |
| 634 | + $this->parser->parse($expected, Yaml::PARSE_CUSTOM_TAGS)); |
| 635 | + } |
| 636 | + |
| 637 | + public function testDumpingTaggedMultiLineTrailingNewlinesInList() |
| 638 | + { |
| 639 | + $data = [ |
| 640 | + new TaggedValue('bar', "a\nb\n\n\n"), |
| 641 | + ]; |
| 642 | + $expected = "- !bar |\n a\n b\n \n \n "; |
| 643 | + $this->assertSame($expected, $this->dumper->dump($data, 2, 0, Yaml::DUMP_MULTI_LINE_LITERAL_BLOCK)); |
| 644 | + |
| 645 | + // @todo Fix the parser, eliminate these exceptions. |
| 646 | + $this->expectException(ParseException::class); |
| 647 | + $this->expectExceptionMessage('Unable to parse at line 6 (near "!bar |").'); |
| 648 | + |
| 649 | + $this->parser->parse($expected, Yaml::PARSE_CUSTOM_TAGS); |
| 650 | + } |
| 651 | + |
605 | 652 | public function testDumpingInlinedMultiLineIfRnBreakLineInTaggedValue()
|
606 | 653 | {
|
607 | 654 | $data = [
|
|
0 commit comments