Skip to content

test(runtime): expand JsonValue parser/renderer unit tests#3270

Open
nankingjing wants to merge 1 commit into
ultraworkers:mainfrom
nankingjing:json-value-unit-tests
Open

test(runtime): expand JsonValue parser/renderer unit tests#3270
nankingjing wants to merge 1 commit into
ultraworkers:mainfrom
nankingjing:json-value-unit-tests

Conversation

@nankingjing

Copy link
Copy Markdown

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-contained JsonValue parser, renderer, accessor set, and error type. This PR keeps both existing tests and adds eleven focused ones (13 total).

Coverage added

  • Renderingnull/bool/number/string primitives, empty/populated arrays, and objects (verifying BTreeMap sorted-key determinism).
  • String escaping – double-quote and backslash escaping, the dedicated \r short escape, and the \uXXXX fallback for other control characters (U+0001).
  • Parsing – primitives, signed integers, surrounding-whitespace tolerance, and nested arrays/objects (with accessor drill-down).
  • Round-trippingparse(render(v)) == v for a mixed object containing a string, negative number, and an array of bool/null.
  • Error paths – empty input, truncated literal, trailing content, unterminated string, unterminated array, and i64 overflow rejection.
  • Accessorsas_* helpers return None on variant mismatch.
  • Error typeJsonError Display renders its message.

Notes

  • Pure unit tests only; no production code changed and no new dependencies.
  • Assertions were derived directly from the current implementation's behavior (e.g. the parser is integer-only via i64, objects render with sorted keys because they are backed by BTreeMap).
  • Follows the existing test style in the module (use super::{...}, .expect(...), assert!/assert_eq!).

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant