From 9ec4fbddd559d93b3d6b072dc8f56d2a572585bd Mon Sep 17 00:00:00 2001 From: _ov4 Date: Tue, 13 Oct 2026 06:02:56 +0000 Subject: feat(plugin): color bracket pairs and mark unmatched brackets red Co-Authored-By: Claude Fable 5.1 --- plugin/test/brackets.test.js | 31 +++++++++++++++++++++++++++++++ plugin/test/highlighting.test.js | 1 + 2 files changed, 32 insertions(+) create mode 100644 plugin/test/brackets.test.js (limited to 'plugin/test') diff --git a/plugin/test/brackets.test.js b/plugin/test/brackets.test.js new file mode 100644 index 0000000..acb18d0 --- /dev/null +++ b/plugin/test/brackets.test.js @@ -0,0 +1,31 @@ +'use strict'; + +const assert = require('node:assert/strict'); +const { test } = require('node:test'); +const { unmatchedBrackets } = require('../src/brackets'); + +test('mixed nesting matches across lines and repaired brackets stop being errors', () => { + assert.deepEqual(unmatchedBrackets('A[(B + C)\n + D[1]]'), []); + assert.deepEqual(unmatchedBrackets('A['), [1]); + assert.deepEqual(unmatchedBrackets('A[1]'), []); + assert.deepEqual(unmatchedBrackets('(\n)'), []); +}); + +test('unpaired opening, closing and crossed bracket types are all reported', () => { + assert.deepEqual(unmatchedBrackets('(['), [0, 1]); + assert.deepEqual(unmatchedBrackets(')]'), [0, 1]); + assert.deepEqual(unmatchedBrackets('([)]'), [0, 1, 2, 3]); + assert.deepEqual(unmatchedBrackets('(]'), [0, 1]); +}); + +test('comments and quotes are ignored with correct UTF-16 offsets after Unicode and CRLF', () => { + assert.deepEqual(unmatchedBrackets('OUTPUT "[( //" // )]\nOUTPUT \'[\''), []); + const unfinished = 'OUTPUT "unfinished [\r\nA['; + assert.deepEqual(unmatchedBrackets(unfinished), [unfinished.length - 1]); + const unicode = 'OUTPUT "你好😀"\r\nA['; + assert.deepEqual(unmatchedBrackets(unicode), [unicode.length - 1]); + // Backslashes do not escape CIE quotes. + assert.deepEqual(unmatchedBrackets('"x\\"['), [4]); + const quoteChar = "OUTPUT ''' ["; + assert.deepEqual(unmatchedBrackets(quoteChar), [quoteChar.length - 1]); +}); diff --git a/plugin/test/highlighting.test.js b/plugin/test/highlighting.test.js index df18f6a..89e031a 100644 --- a/plugin/test/highlighting.test.js +++ b/plugin/test/highlighting.test.js @@ -58,4 +58,5 @@ test('comments, strings, lowercase and keyword prefixes cannot become keywords', assert.ok(grammar.tokenizeLine('IF X THEN', state).tokens[0].scopes.includes( 'keyword.control.cie-pseudocode')); assert.ok(scopesAt('OUTPUT "x\\" + 1', '+').includes('keyword.operator.cie-pseudocode')); + assert.ok(scopesAt("OUTPUT ''' + 1", '+').includes('keyword.operator.cie-pseudocode')); }); -- cgit v1.3.1-4-g156e