@@ -2,7 +2,7 @@ module ChunkReaderTests
22using Test
33using JSON
44using OpenAPI
5- using OpenAPI. Clients: AbstractChunkReader, JSONChunkReader, LineChunkReader, RFC7464ChunkReader
5+ using OpenAPI. Clients: AbstractChunkReader, JSONChunkReader, LineChunkReader, RFC7464ChunkReader, _read_json_chunk
66
77function linechunk1 ()
88 buff = Base. BufferStream ()
@@ -182,6 +182,102 @@ function rfc7464chunk2()
182182 @test length (results) == 2
183183end
184184
185+ function read_json_chunk_object ()
186+ io = IOBuffer (" {\" key\" : \" value\" }" )
187+ @test String (_read_json_chunk (io)) == " {\" key\" : \" value\" }"
188+ @test eof (io)
189+ end
190+
191+ function read_json_chunk_nested_object ()
192+ io = IOBuffer (" {\" a\" : {\" b\" : 1}}" )
193+ @test String (_read_json_chunk (io)) == " {\" a\" : {\" b\" : 1}}"
194+ @test eof (io)
195+ end
196+
197+ function read_json_chunk_array ()
198+ io = IOBuffer (" [1, 2, 3]" )
199+ @test String (_read_json_chunk (io)) == " [1, 2, 3]"
200+ @test eof (io)
201+ end
202+
203+ function read_json_chunk_nested_array ()
204+ io = IOBuffer (" [[1,2],[3,4]]" )
205+ @test String (_read_json_chunk (io)) == " [[1,2],[3,4]]"
206+ @test eof (io)
207+ end
208+
209+ function read_json_chunk_string ()
210+ io = IOBuffer (" \" hello\" " )
211+ @test String (_read_json_chunk (io)) == " \" hello\" "
212+ @test eof (io)
213+ end
214+
215+ function read_json_chunk_string_escaped_quote ()
216+ # embedded escaped quote: "say \"hi\""
217+ io = IOBuffer (" \" say \\\" hi\\\"\" " )
218+ @test String (_read_json_chunk (io)) == " \" say \\\" hi\\\"\" "
219+ @test eof (io)
220+ end
221+
222+ function read_json_chunk_string_escaped_backslash ()
223+ # embedded escaped backslash: "path\\file"
224+ io = IOBuffer (" \" path\\\\ file\" " )
225+ @test String (_read_json_chunk (io)) == " \" path\\\\ file\" "
226+ @test eof (io)
227+ end
228+
229+ function read_json_chunk_integer ()
230+ io = IOBuffer (" 42" )
231+ @test String (_read_json_chunk (io)) == " 42"
232+ @test eof (io)
233+ end
234+
235+ function read_json_chunk_float ()
236+ io = IOBuffer (" 3.14" )
237+ @test String (_read_json_chunk (io)) == " 3.14"
238+ @test eof (io)
239+ end
240+
241+ function read_json_chunk_true ()
242+ io = IOBuffer (" true" )
243+ @test String (_read_json_chunk (io)) == " true"
244+ @test eof (io)
245+ end
246+
247+ function read_json_chunk_false ()
248+ io = IOBuffer (" false" )
249+ @test String (_read_json_chunk (io)) == " false"
250+ @test eof (io)
251+ end
252+
253+ function read_json_chunk_null ()
254+ io = IOBuffer (" null" )
255+ @test String (_read_json_chunk (io)) == " null"
256+ @test eof (io)
257+ end
258+
259+ function read_json_chunk_stops_at_boundary ()
260+ # reads exactly one chunk and leaves the stream positioned at the next value
261+ io = IOBuffer (" {\" a\" :1}{\" b\" :2}" )
262+ @test String (_read_json_chunk (io)) == " {\" a\" :1}"
263+ @test String (_read_json_chunk (io)) == " {\" b\" :2}"
264+ @test eof (io)
265+ end
266+
267+ function read_json_chunk_braces_in_string ()
268+ # braces inside a string value must not affect depth tracking
269+ io = IOBuffer (" {\" key\" : \" value{nested}\" }" )
270+ @test String (_read_json_chunk (io)) == " {\" key\" : \" value{nested}\" }"
271+ @test eof (io)
272+ end
273+
274+ function read_json_chunk_brackets_in_string ()
275+ # brackets inside a string value must not affect depth tracking
276+ io = IOBuffer (" {\" key\" : \" [not an array]\" }" )
277+ @test String (_read_json_chunk (io)) == " {\" key\" : \" [not an array]\" }"
278+ @test eof (io)
279+ end
280+
185281function runtests ()
186282 linechunk1 ()
187283 linechunk2 ()
@@ -192,6 +288,21 @@ function runtests()
192288 jsonchunk4 ()
193289 rfc7464chunk1 ()
194290 rfc7464chunk2 ()
291+ read_json_chunk_object ()
292+ read_json_chunk_nested_object ()
293+ read_json_chunk_array ()
294+ read_json_chunk_nested_array ()
295+ read_json_chunk_string ()
296+ read_json_chunk_string_escaped_quote ()
297+ read_json_chunk_string_escaped_backslash ()
298+ read_json_chunk_integer ()
299+ read_json_chunk_float ()
300+ read_json_chunk_true ()
301+ read_json_chunk_false ()
302+ read_json_chunk_null ()
303+ read_json_chunk_stops_at_boundary ()
304+ read_json_chunk_braces_in_string ()
305+ read_json_chunk_brackets_in_string ()
195306end
196307
197308end # module ChunkReaderTests
0 commit comments