diff options
| author | _ov4 <ov4@ov4.org> | 2026-10-14 02:53:33 +0000 |
|---|---|---|
| committer | _ov4 <ov4@ov4.org> | 2026-10-14 02:53:33 +0000 |
| commit | 3ef7f8b778dce23af25965b379126b9dd95d1c27 (patch) | |
| tree | 3e3700201b9a3a52bc0d78895d1e345e06fe0ead /plugin/test | |
| parent | d5851e995363e6f637a5f35cafe3ddaf8934705a (diff) | |
feat(plugin): indent try-catch blocks
Indent TRY and CATCH bodies, align CATCH and ENDTRY with their TRY, and
trigger on-type formatting when either keyword is completed. Document the
supported blocks and verify nesting, selection context and Enter indentation.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Diffstat (limited to 'plugin/test')
| -rw-r--r-- | plugin/test/indentation.test.js | 39 |
1 files changed, 36 insertions, 3 deletions
diff --git a/plugin/test/indentation.test.js b/plugin/test/indentation.test.js index 9a50cb3..1a9d91e 100644 --- a/plugin/test/indentation.test.js +++ b/plugin/test/indentation.test.js @@ -24,6 +24,36 @@ test('split THEN/DO, single-line TYPE, comments and strings do not add extra lev assert.deepEqual(lineDepths(lines), [0, 0, 0, 0, 1, 1, 2, 2, 1, 0, 0, 0]); }); +test('try and catch bodies nest with existing blocks and THROW keeps their depth', () => { + const lines = [ + 'PROCEDURE Demo()', 'TRY', 'IF Ready THEN', 'THROW', 'ENDIF', + 'CATCH', 'TRY', 'THROW', 'CATCH', 'WHILE Ready DO', 'THROW', + 'ENDWHILE', 'ENDTRY', 'ENDTRY', 'OUTPUT "Done"', 'ENDPROCEDURE' + ]; + assert.deepEqual(lineDepths(lines), [0, 1, 2, 3, 2, 1, 2, 3, 2, 3, 4, 3, 2, 1, 1, 0]); + assert.deepEqual(lineDepths([ + 'CATCH', 'ENDTRY', 'try', 'TRYValue <- 1', 'TRY // CATCH ENDTRY', + '// ENDTRY', 'OUTPUT "CATCH ENDTRY"', 'CATCH // TRY', 'THROW', + 'ENDTRY', 'OUTPUT "Done"' + ]), [0, 0, 0, 0, 0, 1, 1, 0, 1, 0, 0]); +}); + +test('catch selection uses earlier TRY context and formatting is idempotent', () => { + const lines = ['IF Ready THEN', ' TRY', ' THROW', ' CATCH', + ' OUTPUT "Caught"', ' ENDTRY', 'ENDIF']; + const edits = indentationEdits(lines, 3, 5); + assert.deepEqual(edits, [ + { line: 3, length: 4, text: '\t' }, + { line: 4, length: 1, text: '\t\t' }, + { line: 5, length: 3, text: '\t' } + ]); + for (const edit of edits) lines[edit.line] = edit.text + lines[edit.line].slice(edit.length); + assert.equal(lines[1], ' TRY'); + assert.equal(lines[2], ' THROW'); + assert.equal(lines[4], '\t\tOUTPUT "Caught"'); + assert.deepEqual(indentationEdits(lines, 3, 5), []); +}); + test('range formatting reads earlier context, preserves text and is idempotent', () => { const lines = ['IF X THEN', ' WHILE Y DO', ' OUTPUT "x" // keep spaces', ' ENDWHILE', 'ENDIF']; const edits = indentationEdits(lines, 2, 3); @@ -38,7 +68,10 @@ test('range formatting reads earlier context, preserves text and is idempotent', }); test('blank lines are empty when formatted and indented at the caret after Enter', () => { - const lines = ['IF X THEN', ' ']; - assert.deepEqual(indentationEdits(lines, 1, 1), [{ line: 1, length: 3, text: '' }]); - assert.deepEqual(indentationEdits(lines, 1, 1, true), [{ line: 1, length: 3, text: '\t' }]); + for (const header of [['IF X THEN'], ['TRY'], ['TRY', 'THROW', 'CATCH']]) { + const lines = [...header, ' ']; + const line = header.length; + assert.deepEqual(indentationEdits(lines, line, line), [{ line, length: 3, text: '' }]); + assert.deepEqual(indentationEdits(lines, line, line, true), [{ line, length: 3, text: '\t' }]); + } }); |
