Skip to content

Commit

Permalink
test: trim trailing comma, use expectException* as method instead
Browse files Browse the repository at this point in the history
  • Loading branch information
adhocore committed Apr 5, 2021
1 parent 3e2c03c commit 65dd125
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions tests/CommentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,11 @@ public function testDecode($json)
$this->assertArrayHasKey('b', $actual);
}

/**
* @expectedException \RuntimeException
* @expectedExceptionMessage JSON decode failed
*/
public function testDecodeThrows()
{
$this->expectException(\RuntimeException::class);
$this->expectExceptionMessage('JSON decode failed');

(new Comment)->decode('{"a":1, /* comment */, "b":}', true);
}

Expand All @@ -55,7 +54,7 @@ public function testParse()
}', true);

$this->assertNotEmpty($parsed);
$this->assertInternalType('array', $parsed);
$this->assertTrue(is_array($parsed));
$this->assertArrayHasKey('a//b', $parsed);
$this->assertSame('/*value*/', $parsed['a//b']);
}
Expand All @@ -67,30 +66,34 @@ public function theTests()
'json' => '{"a":1,"b":2}',
'expect' => '{"a":1,"b":2}',
],
'with trail only' => [
'json' => '{"a":1,"b":2,,}',
'expect' => '{"a":1,"b":2}',
],
'single line comment' => [
'json' => '{"a":1,
// comment
"b":2,
// comment
"c":3}',
"c":3,,}',
'expect' => '{"a":1,
"b":2,
"c":3}',
],
'single line comment at end' => [
'json' => '{"a":1,
"b":2,// comment
"c":3}',
"c":[1,2,,]}',
'expect' => '{"a":1,
"b":2,
"c":3}',
"c":[1,2]}',
],
'real multiline comment' => [
'json' => '{"a":1,
/*
* comment
*/
"b":2, "c":3}',
"b":2, "c":3,}',
'expect' => '{"a":1,
' . '
"b":2, "c":3}',
Expand All @@ -102,7 +105,7 @@ public function theTests()
"b":2, "c":3}',
],
'inline multiline comment at end' => [
'json' => '{"a":1, "b":2, "c":3/* comment */}',
'json' => '{"a":1, "b":2, "c":3/* comment */,}',
'expect' => '{"a":1, "b":2, "c":3}',
],
'comment inside string' => [
Expand Down

0 comments on commit 65dd125

Please sign in to comment.