@@ -128,15 +128,79 @@ public function testEscapedBackslashesInQuotedValue()
128128 $ this ->assertSame ($ array , $ this ->parser ->parse ($ string ));
129129 }
130130
131+ public function testEmptyArray ()
132+ {
133+ $ array = [];
134+ $ string = '{} ' ;
135+
136+ $ this ->assertSame ($ array , $ this ->parser ->parse ($ string ));
137+ }
138+
139+ public function testArrayContainingEmptyArray ()
140+ {
141+ $ array = [[], [1 ], []];
142+ $ string = '{{},{1},{}} ' ;
143+
144+ $ cast = function (string $ value ): int {
145+ return (int ) $ value ;
146+ };
147+
148+ $ this ->assertSame ($ array , $ this ->parser ->parse ($ string , $ cast ));
149+ }
150+
151+ public function testArrayWithEmptyString ()
152+ {
153+ $ array = ['' ];
154+ $ string = '{""} ' ;
155+
156+ $ this ->assertSame ($ array , $ this ->parser ->parse ($ string ));
157+ }
158+
159+ public function testMalformedNestedArray ()
160+ {
161+ $ this ->expectException (ParseException::class);
162+ $ this ->expectExceptionMessage ('Unexpected end of data ' );
163+
164+ $ string = '{{} ' ;
165+ $ this ->parser ->parse ($ string );
166+ }
167+
168+ public function testEmptyString ()
169+ {
170+ $ this ->expectException (ParseException::class);
171+ $ this ->expectExceptionMessage ('Unexpected end of data ' );
172+
173+ $ string = ' ' ;
174+ $ this ->parser ->parse ($ string );
175+ }
176+
177+ public function testNoOpeningBracket ()
178+ {
179+ $ this ->expectException (ParseException::class);
180+ $ this ->expectExceptionMessage ('Missing opening bracket ' );
181+
182+ $ string = '"one", "two"} ' ;
183+ $ this ->parser ->parse ($ string );
184+ }
185+
131186 public function testNoClosingBracket ()
132187 {
133188 $ this ->expectException (ParseException::class);
134- $ this ->expectExceptionMessage ('Missing opening or closing brackets ' );
189+ $ this ->expectExceptionMessage ('Unexpected end of data ' );
135190
136191 $ string = '{"one", "two" ' ;
137192 $ this ->parser ->parse ($ string );
138193 }
139194
195+ public function testExtraClosingBracket ()
196+ {
197+ $ this ->expectException (ParseException::class);
198+ $ this ->expectExceptionMessage ('Data left in buffer after parsing ' );
199+
200+ $ string = '{"one", "two"}} ' ;
201+ $ this ->parser ->parse ($ string );
202+ }
203+
140204 public function testTrailingData ()
141205 {
142206 $ this ->expectException (ParseException::class);
0 commit comments