Skip to content

Commit

Permalink
Improve test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
pcrov committed Mar 27, 2018
1 parent 8baeee5 commit e2c8e9d
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 3 deletions.
11 changes: 11 additions & 0 deletions test/InputStream/StreamTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,17 @@ public function testStreamInput()
fclose($handle);
}

public function testEmptyStreamInput()
{
$handle = fopen('php://memory','r+');
fwrite($handle, "");
rewind($handle);
$stream = new Stream($handle);

$this->assertNull($stream->read());
fclose($handle);
}

public function testNotResourceFailure()
{
$this->expectException(InvalidArgumentException::class);
Expand Down
6 changes: 6 additions & 0 deletions test/InputStream/StringInputTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,10 @@ public function testStringInput()
$stringInput = new StringInput($string);
$this->assertSame($string, $stringInput->read());
}

public function testEmptyString()
{
$stringInput = new StringInput("");
$this->assertNull($stringInput->read());
}
}
15 changes: 12 additions & 3 deletions test/JsonReaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,28 +52,37 @@ public function read()
};
}

/** @doesNotPerformAssertions */
public function testJson()
{
$reader = $this->reader;
$reader->json(file_get_contents(__DIR__ . "/../composer.json"));
$this->assertSame(0, $reader->depth());
$this->assertSame(JsonReader::NONE, $reader->type());
$this->assertNull($reader->name());
$this->assertNull($reader->value());
while ($reader->read());
}

/** @doesNotPerformAssertions */
public function testOpen()
{
$reader = $this->reader;
$reader->open(__DIR__ . "/../composer.json");
$this->assertSame(0, $reader->depth());
$this->assertSame(JsonReader::NONE, $reader->type());
$this->assertNull($reader->name());
$this->assertNull($reader->value());
while ($reader->read());
}

/** @doesNotPerformAssertions */
public function testStream()
{
$reader = $this->reader;
$handle = fopen((__DIR__ . "/../composer.json"), "rb");
$reader->stream($handle);
$this->assertSame(0, $reader->depth());
$this->assertSame(JsonReader::NONE, $reader->type());
$this->assertNull($reader->name());
$this->assertNull($reader->value());
while ($reader->read());
fclose($handle);
}
Expand Down
13 changes: 13 additions & 0 deletions test/Parser/JsonParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,19 @@ public function provideTestParserError()
],
"Line 42: Unexpected token T_FALSE."
],
"object members with missing comma" => [
[
[Tokenizer::T_BEGIN_OBJECT, null, 42],
[Tokenizer::T_STRING, "name", 42],
[Tokenizer::T_COLON, null, 42],
[Tokenizer::T_STRING, "value", 42],
[Tokenizer::T_STRING, "name", 42],
[Tokenizer::T_COLON, null, 42],
[Tokenizer::T_STRING, "value", 42],
[Tokenizer::T_END_OBJECT, null, 42],
],
"Line 42: Unexpected token T_STRING."
],
];
}

Expand Down
36 changes: 36 additions & 0 deletions test/Parser/LexerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,10 @@ public function provideTestTokenization()
"\"\x7f\"",
[Tokenizer::T_STRING, "\x7f", 1]
],
"string with escape sequence followed by text" => [
'"\t foo"',
[Tokenizer::T_STRING, "\t foo", 1]
],
"simple number" => [
'42',
[Tokenizer::T_NUMBER, "42", 1]
Expand Down Expand Up @@ -224,6 +228,14 @@ public function provideTestLexerError()
'-',
"Line 1: Unexpected end of file."
],
"negative sign followed by non-digit" => [
'-a',
"Line 1: Unexpected 'a'."
],
"number truncated after decimal point" => [
'0.',
"Line 1: Unexpected end of file."
],
"number with malformed fractional part" => [
'0.a',
"Line 1: Unexpected 'a'."
Expand All @@ -232,6 +244,14 @@ public function provideTestLexerError()
'0.4eb',
"Line 1: Unexpected 'b'."
],
"number with truncated exponent" => [
'0.4e',
"Line 1: Unexpected end of file."
],
"number with truncated signed exponent" => [
'0.4e+',
"Line 1: Unexpected end of file."
],
"invalid escape sequence" => [
'"\h"',
"Line 1: Unexpected 'h'."
Expand All @@ -244,6 +264,10 @@ public function provideTestLexerError()
'"\u454' . "\u{1F418}\"",
"Line 1: Unexpected '\u{1F418}'."
],
"truncated unicode escape sequence" => [
'"\u',
"Line 1: Unexpected end of file."
],
"string with record separator control character" => [
"\"\x1e\"",
"Line 1: Unexpected control character \\u{1E}."
Expand Down Expand Up @@ -292,13 +316,25 @@ public function provideTestLexerError()
"\u{1F418}",
"Line 1: Unexpected '\u{1F418}'."
],
"bare invalid UTF-8 byte, high out of range" => [
"\xFF",
"Line 1: Ill-formed UTF-8 sequence 0xFF."
],
"bare invalid UTF-8 first byte, two byte sequence" => [
"\xC0\x80",
"Line 1: Ill-formed UTF-8 sequence 0xC0 0x80."
],
"bare invalid UTF-8 two byte sequence, second byte not a continuation byte" => [
"\xE0\x00",
"Line 1: Ill-formed UTF-8 sequence 0xE0."
],
"bare invalid UTF-8 four byte sequence, second byte high out of range" => [
"\xF4\x90\x80\x80",
"Line 1: Ill-formed UTF-8 sequence 0xF4 0x90 0x80 0x80."
],
"string truncated at escape sequence" => [
'"\\',
"Line 1: Unexpected end of file."
]
];
}
Expand Down

0 comments on commit e2c8e9d

Please sign in to comment.