Skip to content

test(json, builtin, debug): use Json(...) in test blocks - #4209

Merged
bobzhang merged 1 commit into
mainfrom
refactor/json-tests-json-constructor
Sep 7, 2026
Merged

test(json, builtin, debug): use Json(...) in test blocks#4209
bobzhang merged 1 commit into
mainfrom
refactor/json-tests-json-constructor

Conversation

@bobzhang

@bobzhang bobzhang commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

What

Refactor test code to construct Json string/bool values with the preferred
Json(...) constructor instead of the Json::string(...) /
Json::boolean(...) helpers, inside test { ... } blocks only.

Bool and String both implement ToJson, so Json(true) is exactly
Json::boolean(true) and Json("x") is exactly Json::string("x") — the
refactor is behavior-neutral and no snapshot or expectation changed.

Scope

  • Changed: 63 call sites across 9 test files (json/*_test.mbt,
    builtin/json_test.mbt, debug/debug_test.mbt), each inside a
    test { ... } block.
  • Intentionally left untouched:
    • library code that uses these helpers for real construction
      (json/parse.mbt, ToJson impls in builtin, bigint, ...);
    • doc comments / generated .mbti / doc examples;
    • test-support helpers defined outside test blocks (QuickCheck
      generators/shrinkers in json/quickcheck_test.mbt, bench fixtures in
      json/stringify_indent_bench_test.mbt, the ToJson impl in
      json/json_encode_decode_test.mbt).

Validation

  • moon check: clean (0 errors, 0 warnings)
  • moon fmt --check: clean
  • moon test: json 219/219, builtin 2988/2988, debug 71/71

Generated with SeekMoon

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>
Copilot AI lite review requested due to automatic review settings September 7, 2026 09:45

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 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("...") to Json("...").
  • Replaced boolean JSON construction in tests from Json::boolean(true/false) to Json(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.

@coveralls

Copy link
Copy Markdown
Collaborator

Coverage Report for CI Build 6573

Warning

Build has drifted: This PR's base is out of sync with its target branch, so coverage data may include unrelated changes.
Quick fix: rebase this PR. Learn more →

Coverage remained the same at 89.24%

Details

  • Coverage remained the same as the base build.
  • Patch coverage: No coverable lines changed in this PR.
  • No coverage regressions found.

Uncovered Changes

No uncovered changes found.

Coverage Regressions

No coverage regressions found.


Coverage Stats

Coverage Status
Relevant Lines: 18280
Covered Lines: 16313
Line Coverage: 89.24%
Coverage Strength: 282394.85 hits per line

💛 - Coveralls

@bobzhang
bobzhang merged commit fa1d806 into main Sep 7, 2026
21 checks passed
@bobzhang
bobzhang deleted the refactor/json-tests-json-constructor branch September 7, 2026 11:07
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.

3 participants