@@ -128,15 +128,79 @@ public function testEscapedBackslashesInQuotedValue()
128
128
$ this ->assertSame ($ array , $ this ->parser ->parse ($ string ));
129
129
}
130
130
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
+
131
186
public function testNoClosingBracket ()
132
187
{
133
188
$ this ->expectException (ParseException::class);
134
- $ this ->expectExceptionMessage ('Missing opening or closing brackets ' );
189
+ $ this ->expectExceptionMessage ('Unexpected end of data ' );
135
190
136
191
$ string = '{"one", "two" ' ;
137
192
$ this ->parser ->parse ($ string );
138
193
}
139
194
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
+
140
204
public function testTrailingData ()
141
205
{
142
206
$ this ->expectException (ParseException::class);
0 commit comments