test(json, builtin, debug): use Json(...) in test blocks - #4209
Conversation
Replace `Json::boolean(...)` and `Json::string(...)` with the `Json(value)` constructor inside `test { ... }` blocks. Bool and String implement `ToJson`, so the produced values are identical and no test expectations change.
Scope is limited to test blocks: library code (e.g. the parser builders in `json/parse.mbt` and the `ToJson` impls in `builtin`), doc examples, and test-support helpers defined outside `test` blocks (QuickCheck generators/shrinkers, bench fixtures) are left untouched.
Co-Authored-By: SeekMoon <seekmoon@moonbitlang.com>
There was a problem hiding this comment.
🟢 Approval recommended
The changes are a behavior-neutral, consistently-applied test-only refactor to the preferred Json(...) construction style with no issues found in the updated call sites.
Pull request overview
Refactors MoonBit JSON-related tests to use the preferred Json(...) constructor for String/Bool values (via ToJson) instead of Json::string(...) / Json::boolean(...), keeping changes scoped to test blocks and preserving behavior.
Changes:
- Replaced string JSON construction in tests from
Json::string("...")toJson("..."). - Replaced boolean JSON construction in tests from
Json::boolean(true/false)toJson(true/false). - Applied the refactor consistently across json/builtin/debug test suites without touching non-test helpers.
File summaries
| File | Description |
|---|---|
| json/quickcheck_test.mbt | Updates a test document fixture to use Json("a") inside a shrinker test. |
| json/parse_test.mbt | Switches string/bool expected values to Json(...) in parser assertions. |
| json/lex_string_test.mbt | Updates surrogate/escape parsing assertions to compare against Json(...). |
| json/json_traverse_test.mbt | Replaces primitive Json::string/boolean constructions with Json(...) in traversal tests. |
| json/json_test.mbt | Updates stringifying tests to create string Json via Json(s). |
| json/from_json_test.mbt | Refactors various decode/error-handling tests to use Json(...) for string/bool inputs. |
| json/escape_quickcheck_wbtest.mbt | Updates quickcheck roundtrip test to construct json input via Json(...). |
| debug/debug_test.mbt | Updates debug repr test to use Json(true) for boolean JSON. |
| builtin/json_test.mbt | Updates equality/to_json-related tests to use Json(...) for string/bool JSON values. |
Review details
- Files reviewed: 9/9 changed files
- Comments generated: 0
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Coverage Report for CI Build 6573Warning Build has drifted: This PR's base is out of sync with its target branch, so coverage data may include unrelated changes. Coverage remained the same at 89.24%Details
Uncovered ChangesNo uncovered changes found. Coverage RegressionsNo coverage regressions found. Coverage Stats
💛 - Coveralls |
What
Refactor test code to construct
Jsonstring/bool values with the preferredJson(...)constructor instead of theJson::string(...)/Json::boolean(...)helpers, insidetest { ... }blocks only.BoolandStringboth implementToJson, soJson(true)is exactlyJson::boolean(true)andJson("x")is exactlyJson::string("x")— therefactor is behavior-neutral and no snapshot or expectation changed.
Scope
json/*_test.mbt,builtin/json_test.mbt,debug/debug_test.mbt), each inside atest { ... }block.(
json/parse.mbt,ToJsonimpls inbuiltin,bigint, ...);.mbti/ doc examples;testblocks (QuickCheckgenerators/shrinkers in
json/quickcheck_test.mbt, bench fixtures injson/stringify_indent_bench_test.mbt, theToJsonimpl injson/json_encode_decode_test.mbt).Validation
moon check: clean (0 errors, 0 warnings)moon fmt --check: cleanmoon test: json 219/219, builtin 2988/2988, debug 71/71Generated with SeekMoon