Skip to content

Commit

Permalink
Enhancement: Assert that empty arrays and objects are collapsed
Browse files Browse the repository at this point in the history
  • Loading branch information
localheinz committed Jan 5, 2018
1 parent c1a4ba8 commit 2268811
Showing 1 changed file with 80 additions and 0 deletions.
80 changes: 80 additions & 0 deletions test/Unit/PrinterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,86 @@ public function testPrintPrintsObjectPrettyWithUnEscapeUnicodeAndUnEscapeSlashes
$this->assertSame($original, $printed);
}

public function testPrintCollapsesEmptyArray()
{
$original = <<<'JSON'
[
]
JSON;

$expected = <<<'JSON'
[]
JSON;

$printer = new Printer();

$printed = $printer->print(
$original,
true,
true
);

$this->assertSame($expected, $printed);
}

public function testPrintCollapsesEmptyObject()
{
$original = <<<'JSON'
{
}
JSON;

$expected = <<<'JSON'
{}
JSON;

$printer = new Printer();

$printed = $printer->print(
$original,
true,
true
);

$this->assertSame($expected, $printed);
}

public function testPrintCollapsesEmptyComplex()
{
$original = <<<'JSON'
{
"foo": {
} ,
"bar": [ ]
}
JSON;

$expected = <<<'JSON'
{
"foo": {},
"bar": []
}
JSON;

$printer = new Printer();

$printed = $printer->print(
$original,
true,
true
);

$this->assertSame($expected, $printed);
}

/**
* @see https://github.com/zendframework/zend-json/pull/37
*/
Expand Down

0 comments on commit 2268811

Please sign in to comment.