Skip to content

Commit 50ce803

Browse files
committed
[Yaml] DumperTest: Add cases with tagged multi line string literals, with bad apples.
1 parent c52560f commit 50ce803

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

src/Symfony/Component/Yaml/Tests/DumperTest.php

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Component\Yaml\Dumper;
1616
use Symfony\Component\Yaml\Exception\DumpException;
17+
use Symfony\Component\Yaml\Exception\ParseException;
1718
use Symfony\Component\Yaml\Parser;
1819
use Symfony\Component\Yaml\Tag\TaggedValue;
1920
use Symfony\Component\Yaml\Yaml;
@@ -611,6 +612,52 @@ public function testDumpingMultiLineStringAsScalarBlockTaggedValue()
611612
$this->assertSameData($data, $this->parser->parse($expected, Yaml::PARSE_CUSTOM_TAGS));
612613
}
613614

615+
public function testDumpingTaggedMultiLineInList()
616+
{
617+
$data = [
618+
new TaggedValue('bar', "a\nb"),
619+
];
620+
$expected = "- !bar |\n a\n b";
621+
$this->assertSame($expected, $this->dumper->dump($data, 2, 0, Yaml::DUMP_MULTI_LINE_LITERAL_BLOCK));
622+
623+
// @todo Fix the parser, eliminate these exceptions.
624+
$this->expectException(ParseException::class);
625+
$this->expectExceptionMessage('Unable to parse at line 3 (near "!bar |").');
626+
627+
$this->parser->parse($expected, Yaml::PARSE_CUSTOM_TAGS);
628+
}
629+
630+
public function testDumpingTaggedMultiLineTrailingNewlinesInMap()
631+
{
632+
$data = [
633+
'foo' => new TaggedValue('bar', "a\nb\n\n\n"),
634+
];
635+
$expected = "foo: !bar |\n a\n b\n \n \n ";
636+
$this->assertSame($expected, $this->dumper->dump($data, 2, 0, Yaml::DUMP_MULTI_LINE_LITERAL_BLOCK));
637+
638+
// @todo Fix the parser, the result should be identical to $data.
639+
$this->assertSameData(
640+
[
641+
'foo' => new TaggedValue('bar', "a\nb\n"),
642+
],
643+
$this->parser->parse($expected, Yaml::PARSE_CUSTOM_TAGS));
644+
}
645+
646+
public function testDumpingTaggedMultiLineTrailingNewlinesInList()
647+
{
648+
$data = [
649+
new TaggedValue('bar', "a\nb\n\n\n"),
650+
];
651+
$expected = "- !bar |\n a\n b\n \n \n ";
652+
$this->assertSame($expected, $this->dumper->dump($data, 2, 0, Yaml::DUMP_MULTI_LINE_LITERAL_BLOCK));
653+
654+
// @todo Fix the parser, eliminate these exceptions.
655+
$this->expectException(ParseException::class);
656+
$this->expectExceptionMessage('Unable to parse at line 6 (near "!bar |").');
657+
658+
$this->parser->parse($expected, Yaml::PARSE_CUSTOM_TAGS);
659+
}
660+
614661
public function testDumpingInlinedMultiLineIfRnBreakLineInTaggedValue()
615662
{
616663
$data = [

0 commit comments

Comments
 (0)