Skip to content

Fix multiline basic string patching tests and fix line handling#131

Draft
DecimalTurn wants to merge 22 commits intolatestfrom
dev-inline-tables-patching-mls_rebased
Draft

Fix multiline basic string patching tests and fix line handling#131
DecimalTurn wants to merge 22 commits intolatestfrom
dev-inline-tables-patching-mls_rebased

Conversation

@DecimalTurn
Copy link
Copy Markdown
Owner

No description provided.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR extends multiline string format preservation during patch() so that TOML basic multiline strings using line-continuation backslashes (\<NL><ws>) can be edited while keeping their original structural formatting.

Changes:

  • Add rebuildLineContinuation() in generateString() to reconstruct multiline basic strings that use line-continuation backslashes.
  • Add/expand test coverage for editing multiline string values inside multiline inline tables when line continuations are present.
  • Add a one-off audit script to print actual patch() outputs for these cases.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 6 comments.

File Description
src/generate.ts Adds line-continuation detection and a reconstruction helper for multiline strings during format preservation.
src/tests/patch.test.ts Adds regression tests ensuring line-continuation backslashes + closing indent are preserved after edits.
scripts/audit-multiline-inline-outputs.cjs Adds an audit utility to print patch() outputs for multiline inline-table test cases.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

@DecimalTurn DecimalTurn force-pushed the dev-inline-tables-patching-mls_rebased branch 2 times, most recently from adcfa8f to a4354e7 Compare March 18, 2026 16:24
…ultiline strings

Replace the previous per-word-distribution approach in rebuildLineContinuation
with a greedy character-based line-wrapping algorithm:

- maxLength is measured as content + trailing whitespace across ALL content segments
  (including the tail), so the longest line in the original sets the budget.
- Words are packed greedily: keep adding words to the current line while
  content + 1 + nextWord stays within maxLength; always emit at least one word
  per line to avoid infinite loops on single long words.
- The output is not capped to the original line count — extra lines are
  added as needed when the new value is longer, and lines are dropped when it
  is shorter.
- Blank groups between content segments are tracked and re-inserted at their
  original inter-segment positions.
- Per-line indent is reused from the matching original segment where available;
  extra lines fall back to the last continuation or tail segment prototype.
- The escaped parameter was removed from rebuildLineContinuation since it was
  unused inside the function; the caller now passes the decoded value directly.
…as line-continuation markers during conversion
@DecimalTurn DecimalTurn force-pushed the dev-inline-tables-patching-mls_rebased branch from a4354e7 to efa11c0 Compare April 11, 2026 00:32
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds support for preserving TOML basic multiline string line-continuation (\ + newline + indentation trimming) when patching, and expands test coverage for the behavior.

Changes:

  • Introduces a dedicated line-ending-backslash module to detect and rebuild line-continuation formatted multiline basic strings.
  • Updates string generation to preserve existing line-continuation formatting when compatible with the new value.
  • Adds extensive patch tests for line-continuation edge cases and enhances the demo UI with eval/copy helpers.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

File Description
src/line-ending-backslash.ts New logic for detecting and rebuilding line-continuation multiline basic strings.
src/generate.ts Integrates line-continuation preservation into generateString.
src/tests/patch.test.ts Adds many regression/edge-case tests for line-continuation patching behavior.
demo.html Adds demo UI controls for setting editor values via expression and copying outputs.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +179 to +183
if (escaped.length > 0) {
if (escaped[0] === ' ') return null;
const trailingSpaces = escaped.length - escaped.trimEnd().length;
if (trailingSpaces !== tailProto.trailingWs.length) return null;
}
Comment on lines +689 to +699
window.applyEval = function () {
const expr = document.getElementById('eval-textarea').value;
const errEl = document.getElementById('eval-error');
errEl.textContent = '';
try {
// intentional eval: user-controlled expression in a local demo page
// eslint-disable-next-line no-eval
const result = eval(expr);
if (typeof result !== 'string') {
errEl.textContent = `Expected a string, got ${typeof result}`;
return;
Comment on lines +348 to +352
<div class="panel-header"><span>Input <span class="lang">TOML</span></span><button class="eval-btn" onclick="openEvalModal('parse-input')" title="Set value from JS expression">{ }</button></div>
<div id="parse-input" class="cm-host"></div>
</div>
<div class="panel">
<div class="panel-header">Output <span class="lang">JSON</span></div>
<div class="panel-header"><span>Output <span class="lang">JSON</span></span><button class="eval-btn" onclick="copyEditor('parse-output', this)" title="Copy output">Copy</button></div>
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.

2 participants