Skip to content

Commit ae37cfd

Browse files
committed
[Yaml] DumperTest: Add cases with tagged multi line string literals, with bad apples.
1 parent 110e5b0 commit ae37cfd

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;
@@ -602,6 +603,52 @@ public function testDumpingMultiLineStringAsScalarBlockTaggedValue()
602603
$this->assertSameData($data, $this->parser->parse($expected, Yaml::PARSE_CUSTOM_TAGS));
603604
}
604605

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+
605652
public function testDumpingInlinedMultiLineIfRnBreakLineInTaggedValue()
606653
{
607654
$data = [

0 commit comments

Comments
 (0)