Skip to content

Commit 6e6a6e8

Browse files
committed
DumperTest: Add cases with tagged multi line string literals, with bad apples.
1 parent 7b6dcc8 commit 6e6a6e8

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;
@@ -600,6 +601,52 @@ public function testDumpingMultiLineStringAsScalarBlockTaggedValue()
600601
$this->assertSameData($data, $this->parser->parse($expected, Yaml::PARSE_CUSTOM_TAGS));
601602
}
602603

604+
public function testDumpingTaggedMultiLineInList()
605+
{
606+
$data = [
607+
new TaggedValue('bar', "a\nb"),
608+
];
609+
$expected = "- !bar |\n a\n b";
610+
$this->assertSame($expected, $this->dumper->dump($data, 2, 0, Yaml::DUMP_MULTI_LINE_LITERAL_BLOCK));
611+
612+
// @todo Fix the parser, eliminate these exceptions.
613+
$this->expectException(ParseException::class);
614+
$this->expectExceptionMessage('Unable to parse at line 3 (near "!bar |").');
615+
616+
$this->parser->parse($expected, Yaml::PARSE_CUSTOM_TAGS);
617+
}
618+
619+
public function testDumpingTaggedMultiLineTrailingNewlinesInMap()
620+
{
621+
$data = [
622+
'foo' => new TaggedValue('bar', "a\nb\n\n\n"),
623+
];
624+
$expected = "foo: !bar |\n a\n b\n \n \n ";
625+
$this->assertSame($expected, $this->dumper->dump($data, 2, 0, Yaml::DUMP_MULTI_LINE_LITERAL_BLOCK));
626+
627+
// @todo Fix the parser, the result should be identical to $data.
628+
$this->assertEquals(
629+
[
630+
'foo' => new TaggedValue('bar', "a\nb\n"),
631+
],
632+
$this->parser->parse($expected, Yaml::PARSE_CUSTOM_TAGS));
633+
}
634+
635+
public function testDumpingTaggedMultiLineTrailingNewlinesInList()
636+
{
637+
$data = [
638+
new TaggedValue('bar', "a\nb\n\n\n"),
639+
];
640+
$expected = "- !bar |\n a\n b\n \n \n ";
641+
$this->assertSame($expected, $this->dumper->dump($data, 2, 0, Yaml::DUMP_MULTI_LINE_LITERAL_BLOCK));
642+
643+
// @todo Fix the parser, eliminate these exceptions.
644+
$this->expectException(ParseException::class);
645+
$this->expectExceptionMessage('Unable to parse at line 6 (near "!bar |").');
646+
647+
$this->parser->parse($expected, Yaml::PARSE_CUSTOM_TAGS);
648+
}
649+
603650
public function testDumpingInlinedMultiLineIfRnBreakLineInTaggedValue()
604651
{
605652
$data = [

0 commit comments

Comments
 (0)