File tree Expand file tree Collapse file tree 2 files changed +21
-0
lines changed
Expand file tree Collapse file tree 2 files changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -18,6 +18,9 @@ test "parse error branches" {
1818 guard (try ? @json .parse ("" )) is Err (InvalidEof ) else {
1919 fail ("expected InvalidEof for empty input" )
2020 }
21+ guard (try ? @json .parse (" \t\r\n " )) is Err (InvalidEof ) else {
22+ fail ("expected InvalidEof for whitespace-only input" )
23+ }
2124 guard (try ? @json .parse ("@" )) is Err (InvalidChar (_ , _ )) else {
2225 fail ("expected InvalidChar for invalid start" )
2326 }
Original file line number Diff line number Diff line change @@ -225,6 +225,24 @@ test "parses whitespace" {
225225 let json = test_parse ("{\t \n\r }" )
226226 assert_eq (json , Json ::object ({}))
227227}
228+
229+ ///|
230+ test "parses leading and trailing whitespace" {
231+ let json = test_parse (" \n\t [1, 2]\r " )
232+ assert_eq (json , Json ::array ([Json ::number (1.0 ), Json ::number (2.0 )]))
233+ }
234+
235+ ///|
236+ test "parses whitespace around separators" {
237+ let json = test_parse ("{\" a\" \n :\t 1 ,\r\" b\" : [ true , false ] }" )
238+ assert_eq (
239+ json ,
240+ Json ::object ({
241+ "a" : Json ::number (1.0 ),
242+ "b" : Json ::array ([Json ::boolean (true ), Json ::boolean (false )]),
243+ }),
244+ )
245+ }
228246//endregion
229247
230248///|
You can’t perform that action at this time.
0 commit comments