test(runtime): expand JsonValue parser/renderer unit tests#3270
test(runtime): expand JsonValue parser/renderer unit tests#3270nankingjing wants to merge 1 commit into
Conversation
The hand-rolled JsonValue parser/renderer in runtime had only two tests covering a self-contained JSON parser, renderer, accessor set, and error type. Add focused unit tests covering primitive rendering, sorted object keys, escape handling (quotes, backslashes, control chars), signed-integer and whitespace-tolerant parsing, nested structures, render->parse round-tripping, malformed-input rejection, i64 overflow rejection, accessor variant mismatches, and JsonError Display.
|
Nice coverage — the round-trip tests (parse→render→parse) are the right way to validate parser/renderer consistency. Good to see edge cases like empty structs, null in arrays, and nested objects covered. The pre_rfc_parse→ |
|
Thanks for the review! The round-trip test was the piece I most wanted in place — asserting that anything the renderer produces re-parses to the identical value pins parser/renderer consistency as a single property instead of a pile of one-directional assertions. The edge cases (empty structs, null inside arrays, i64 boundary values, malformed input) target the shapes production JSON actually hits on that hot path. Happy to extend coverage if you spot any gaps. |
What
Expands unit-test coverage for the hand-rolled JSON value type in
rust/crates/runtime/src/json.rs.Before this change the module had only two tests (
renders_and_parses_json_values,escapes_control_characters) despite implementing a full self-containedJsonValueparser, renderer, accessor set, and error type. This PR keeps both existing tests and adds eleven focused ones (13 total).Coverage added
null/bool/number/stringprimitives, empty/populated arrays, and objects (verifyingBTreeMapsorted-key determinism).\rshort escape, and the\uXXXXfallback for other control characters (U+0001).parse(render(v)) == vfor a mixed object containing a string, negative number, and an array ofbool/null.i64overflow rejection.as_*helpers returnNoneon variant mismatch.JsonErrorDisplayrenders its message.Notes
i64, objects render with sorted keys because they are backed byBTreeMap).use super::{...},.expect(...),assert!/assert_eq!).