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 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 plugin/test/brackets.test.js (limited to 'plugin/test/brackets.test.js') 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]); +}); -- cgit v1.3.1-4-g156e