Skip to content

Commit 4a52d0b

Browse files
committed
test(json): cover whitespace parsing
1 parent ddd6e36 commit 4a52d0b

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

json/parse_error_test.mbt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff 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
}

json/parse_test.mbt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff 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:\t1 ,\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
///|

0 commit comments

Comments
 (0)