don't dump a scalar tag value on its own line

This commit is contained in:
Christian Flothmann 2019-09-09 13:39:48 +02:00
parent 6f332ce0e0
commit a549069a49
2 changed files with 16 additions and 9 deletions

View File

@ -115,15 +115,11 @@ class Dumper
if ($value instanceof TaggedValue) {
$output .= sprintf('%s%s !%s', $prefix, $dumpAsMap ? Inline::dump($key, $flags).':' : '-', $value->getTag());
if ($inline - 1 <= 0) {
if ($inline - 1 <= 0 || null === $value->getValue() || is_scalar($value->getValue())) {
$output .= ' '.$this->dump($value->getValue(), $inline - 1, 0, $flags)."\n";
} else {
$output .= "\n";
$output .= $this->dump($value->getValue(), $inline - 1, $dumpAsMap ? $indent + $this->indentation : $indent + 2, $flags);
if (is_scalar($value->getValue())) {
$output .= "\n";
}
}
continue;

View File

@ -532,10 +532,21 @@ YAML;
'user2' => new TaggedValue('user', 'john'),
];
$expected = <<<YAML
user1: !user
jane
user2: !user
john
user1: !user jane
user2: !user john
YAML;
$this->assertSame($expected, $this->dumper->dump($data, 2));
}
public function testDumpingNotInlinedNullTaggedValue()
{
$data = [
'foo' => new TaggedValue('bar', null),
];
$expected = <<<YAML
foo: !bar null
YAML;