Fix multiline basic string patching tests and fix line handling#131
Fix multiline basic string patching tests and fix line handling#131DecimalTurn wants to merge 22 commits intolatestfrom
Conversation
There was a problem hiding this comment.
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()ingenerateString()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.
adcfa8f to
a4354e7
Compare
…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.
…ion multiline strings
…as line-continuation markers during conversion
a4354e7 to
efa11c0
Compare
…rings to various values
…continuation segments
…n + copy button + switch to local installation as source
…h parsing in tests
…tests Remove dead code paths in packing/reassembly logic: - indentMatch null check (regex with * always matches) - leading-space skip loop (guard rejects leading spaces upstream) - tail trailing-WS suppression (last packed line always ends with word)
There was a problem hiding this comment.
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-backslashmodule 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.
| if (escaped.length > 0) { | ||
| if (escaped[0] === ' ') return null; | ||
| const trailingSpaces = escaped.length - escaped.trimEnd().length; | ||
| if (trailingSpaces !== tailProto.trailingWs.length) return null; | ||
| } |
| 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; |
| <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> |
No description provided.