Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit ba22f0c

Browse filesBrowse files
committed
Test for Issue #26065: leading spaces in YAML multi-line string literals
When dumping an object to YAML. If the first line of a mult-line string literal starts with spaces then the YAML spec says you need to use a [block indentation indicator][1]. [1]: http://www.yaml.org/spec/1.2/spec.html#id2793979
1 parent 717e1c3 commit ba22f0c
Copy full SHA for ba22f0c

File tree

2 files changed

+15
-66
lines changed
Filter options

2 files changed

+15
-66
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Yaml/Tests/DumperTest.php
+11-66Lines changed: 11 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -77,35 +77,6 @@ public function testIndentationInConstructor()
7777
$this->assertEquals($expected, $dumper->dump($this->array, 4, 0));
7878
}
7979

80-
/**
81-
* @group legacy
82-
*/
83-
public function testSetIndentation()
84-
{
85-
$this->dumper->setIndentation(7);
86-
87-
$expected = <<<'EOF'
88-
'': bar
89-
foo: '#bar'
90-
'foo''bar': { }
91-
bar:
92-
- 1
93-
- foo
94-
foobar:
95-
foo: bar
96-
bar:
97-
- 1
98-
- foo
99-
foobar:
100-
foo: bar
101-
bar:
102-
- 1
103-
- foo
104-
105-
EOF;
106-
$this->assertEquals($expected, $this->dumper->dump($this->array, 4, 0));
107-
}
108-
10980
public function testSpecifications()
11081
{
11182
$files = $this->parser->parse(file_get_contents($this->path.'/index.yml'));
@@ -213,16 +184,6 @@ public function testObjectSupportEnabled()
213184
$this->assertEquals('{ foo: !php/object \'O:30:"Symfony\Component\Yaml\Tests\A":1:{s:1:"a";s:3:"foo";}\', bar: 1 }', $dump, '->dump() is able to dump objects');
214185
}
215186

216-
/**
217-
* @group legacy
218-
*/
219-
public function testObjectSupportEnabledPassingTrue()
220-
{
221-
$dump = $this->dumper->dump(array('foo' => new A(), 'bar' => 1), 0, 0, false, true);
222-
223-
$this->assertEquals('{ foo: !php/object \'O:30:"Symfony\Component\Yaml\Tests\A":1:{s:1:"a";s:3:"foo";}\', bar: 1 }', $dump, '->dump() is able to dump objects');
224-
}
225-
226187
public function testObjectSupportDisabledButNoExceptions()
227188
{
228189
$dump = $this->dumper->dump(array('foo' => new A(), 'bar' => 1));
@@ -238,33 +199,6 @@ public function testObjectSupportDisabledWithExceptions()
238199
$this->dumper->dump(array('foo' => new A(), 'bar' => 1), 0, 0, Yaml::DUMP_EXCEPTION_ON_INVALID_TYPE);
239200
}
240201

241-
/**
242-
* @group legacy
243-
* @expectedException \Symfony\Component\Yaml\Exception\DumpException
244-
*/
245-
public function testObjectSupportDisabledWithExceptionsPassingTrue()
246-
{
247-
$this->dumper->dump(array('foo' => new A(), 'bar' => 1), 0, 0, true);
248-
}
249-
250-
public function testEmptyArray()
251-
{
252-
$dump = $this->dumper->dump(array());
253-
$this->assertEquals('{ }', $dump);
254-
255-
$dump = $this->dumper->dump(array(), 0, 0, Yaml::DUMP_EMPTY_ARRAY_AS_SEQUENCE);
256-
$this->assertEquals('[]', $dump);
257-
258-
$dump = $this->dumper->dump(array(), 9, 0, Yaml::DUMP_EMPTY_ARRAY_AS_SEQUENCE);
259-
$this->assertEquals('[]', $dump);
260-
261-
$dump = $this->dumper->dump(new \ArrayObject(), 0, 0, Yaml::DUMP_EMPTY_ARRAY_AS_SEQUENCE | Yaml::DUMP_OBJECT_AS_MAP);
262-
$this->assertEquals('{ }', $dump);
263-
264-
$dump = $this->dumper->dump(new \stdClass(), 0, 0, Yaml::DUMP_EMPTY_ARRAY_AS_SEQUENCE | Yaml::DUMP_OBJECT_AS_MAP);
265-
$this->assertEquals('{ }', $dump);
266-
}
267-
268202
/**
269203
* @dataProvider getEscapeSequences
270204
*/
@@ -454,6 +388,17 @@ public function testDumpMultiLineStringAsScalarBlock()
454388
$this->assertSame(file_get_contents(__DIR__.'/Fixtures/multiple_lines_as_literal_block.yml'), $this->dumper->dump($data, 2, 0, Yaml::DUMP_MULTI_LINE_LITERAL_BLOCK));
455389
}
456390

391+
public function testDumpMultiLineStringAsScalarBlockWhenFirstLineHasLeadingSpace()
392+
{
393+
$data = array(
394+
'data' => array(
395+
'multi_line' => " the first line has leading spaces\nThe second line does not.",
396+
),
397+
);
398+
399+
$this->assertSame(file_get_contents(__DIR__.'/Fixtures/multiple_lines_as_literal_block_leading_space_in_first_line.yml'), $this->dumper->dump($data, 2, 0, Yaml::DUMP_MULTI_LINE_LITERAL_BLOCK));
400+
}
401+
457402
public function testCarriageReturnIsMaintainedWhenDumpingAsMultiLineLiteralBlock()
458403
{
459404
$this->assertSame("- \"a\\r\\nb\\nc\"\n", $this->dumper->dump(array("a\r\nb\nc"), 2, 0, Yaml::DUMP_MULTI_LINE_LITERAL_BLOCK));
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
data:
2+
multi_line: |4
3+
the first line has leading spaces
4+
The second line does not.

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.