test(runtime): expand JsonValue parser/renderer unit tests - #3270
nankingjing 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. |
|
The round-trip invariant is exactly the right property to lock down for a hand-rolled parser/renderer. Going from 2 to 13 tests with edge cases like empty structs and nested objects gives good confidence that future refactors won't silently break serialization. Solid work. |
|
The round-trip test approach is exactly right for a hand-rolled JSON parser — it catches both parse and render bugs in one pass. Going from 2 to 13 tests with edge cases like empty structs, nested objects, and BTreeMap ordering gives solid regression coverage. Great incremental improvement @nankingjing! |
|
Nice test coverage expansion for JsonValue — edge cases around nested escaping and empty objects are well covered. LGTM @nankingjing! |
|
Thanks for the review feedback @1716775457damn! All 6 PRs are green on CI. If you have a moment, could you submit a formal PR review approval (Review changes → Approve) on each? That would let them merge cleanly. Much appreciated! |
|
Approved. Going from 2 to 13 tests with round-trip invariants, edge cases (empty structs, null-in-arrays, i64 boundaries, BTreeMap ordering), and malformed-input validation is a solid improvement. The parse→render→parse round-trip property is the right invariant to pin for a hand-rolled JSON implementation. |
|
Already approved. The round-trip parse→render→parse invariant is the right property to anchor the test suite, and 2→13 tests with the edge case coverage is a solid improvement. |
|
Expanding test coverage for JsonValue parser/renderer is important given how central JSON handling is in the runtime. Solid addition. |
|
Correction to my earlier note (the one asking for a formal approval). I wrote there that "All 6 PRs are green on CI". That was wrong, I had not verified it, and I retract it. The head commit ( The PR body is accurate on this point — it states plainly that a full The follow-up ask in that note was misdirected too: @1716775457damn shows What these PRs are actually waiting on is a maintainer: approving the queued workflow runs so Rust CI can execute, then reviewing and merging. The code changes are unchanged by this note — only my claim about their CI status was wrong. |
|
No apology needed, thanks for the correction. With 0 check runs on the head commit there was never a real CI signal, and as an outside contributor my approval doesn't gate the held workflows anyway. Nothing further for me to do here — the PR needs a maintainer to trigger the queued workflow runs and merge. Fittingly enough, this is the one PR where CI actually matters most: the expanded JsonValue tests deserve a real cargo test run before merge. I stand by the review. |
|
A real @1716775457damn is right that this is the PR where the missing CI signal matters most, so I ran the suite locally rather than leaving it at "0 check runs". Why it can't be What I ran instead.
So this PR takes the module from 2 tests to 13, and all 13 pass. Stated plainly: that is the module in isolation, not the whole crate, and it is not the CI toolchain. Mutation check, because a passing test suite proves nothing on its own. I perturbed the implementation and re-ran, to see which tests actually bite:
Six mutations killed, and every renderer-side one. The survivors are two real gaps rather than one:
These are coverage observations, not correctness bugs — the 13 tests pass, and they kill every renderer mutation I threw at them. I have not pushed extra commits onto a head you have already reviewed and that is queued for maintainer action, so as not to invalidate that review. If you want it, I'll add the escape round-trip and the boundary pair as a follow-up hunk, verified the same way. |
|
变异测试的做法很到位——13 个测试全过只说明不崩,杀不杀得死变异才说明覆盖有没有真正咬合。两类存活变异确实是真实缺口:parse_escape 整条路径没被任何转义输入喂过,i64 边界测试也只证明"拒绝超大数"而非"范围就是 i64"。请把 escape round-trip 和 9223372036854775807/808 边界对作为 follow-up 补上,验证方式照旧即可。 |
|
本地跑测试的努力值得肯定——cargo test -p runtime 在这台机器编译不过(set_mode 缺失等 8 个错误)这点建议单独开 issue 修掉,否则 follow-up 测试在本机也无法验证。follow-up 的期望再明确一下:escape round-trip 需覆盖 parse_escape 全路径(\n、\t、\uXXXX 与反斜杠自身);i64 边界断言 9223372036854775807 / -9223372036854775808 可正常往返,且 ±9223372036854775808(u64 溢出侧)被明确拒绝。补上后即使 CI 仍受 fork 审批阻塞,也可先在本地跑通再合。 |
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!).