diff options
| author | _ov4 <ov4@ov4.org> | 2026-10-27 14:00:49 +0000 |
|---|---|---|
| committer | _ov4 <ov4@ov4.org> | 2026-10-27 14:00:49 +0000 |
| commit | 5d37ebcc02f6ca2ce1ced93f803dd1daf634d866 (patch) | |
| tree | 4c955f89e1f43aefe66064e34e547625eba3bc1b /plugin/test | |
| parent | 3d7d1d7cf8685f0d9230cd89d06017869da1c6d8 (diff) | |
feat(editor): support PP directives in VS Code and Bundle
Share preprocessor highlighting through the existing grammar, keep conditional
blocks at the ordinary indentation depth, and exercise switches in Bundle's
native runner test.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'plugin/test')
| -rw-r--r-- | plugin/test/highlighting.test.js | 26 | ||||
| -rw-r--r-- | plugin/test/indentation.test.js | 10 |
2 files changed, 30 insertions, 6 deletions
diff --git a/plugin/test/highlighting.test.js b/plugin/test/highlighting.test.js index c8ee3f7..1edac7b 100644 --- a/plugin/test/highlighting.test.js +++ b/plugin/test/highlighting.test.js @@ -155,13 +155,27 @@ test('supported keywords reuse C++ scopes without matching identifiers or quoted } }); -test('library directives require their own line and ellipses use the C++ variadic scope', () => { - assert.ok(scopesAt('\t#LIB ', '#').includes('punctuation.definition.directive.cpp')); - assert.ok(scopesAt('\t#LIB ', 'LIB').includes('keyword.control.directive.pragma.cpp')); - for (const text of ['#lib', '#LIBRARY', '#LIB // comment', 'X #LIB', '// #LIB', 'OUTPUT "#LIB"']) { - assert.ok(!scopesAt(text, '#') - .includes('punctuation.definition.directive.cpp'), text); +test('preprocessor directives reuse C++ scopes and shield switch names from ordinary keywords', () => { + for (const [word, scope] of [ + ['PP_DEFINE', 'keyword.control.directive.define.cpp'], + ['PP_UNDEF', 'keyword.control.directive.undef.cpp'], + ['PP_IFDEF', 'keyword.control.directive.conditional.cpp'], + ['PP_IFNDEF', 'keyword.control.directive.conditional.cpp'], + ['PP_ENDIF', 'keyword.control.directive.conditional.cpp'] + ]) { + assert.ok(scopesAt(`\t${word} __LIB // comment`, word).includes(scope)); + for (const text of [word.toLowerCase(), `${word}Value`, `_${word}`, `X ${word}`, `// ${word}`, `OUTPUT "${word}"`]) { + assert.ok(!scopesAt(text, word.toLowerCase() === text ? text : word).includes(scope), text); + } } + for (const word of ['__LIB', 'FUNCTION', 'INTEGER']) { + assert.ok(scopesAt(`PP_DEFINE ${word}`, word).includes('entity.name.function.preprocessor.cpp')); + } + assert.ok(scopesAt('PP_IFDEF Flag // PP_ENDIF', 'PP_ENDIF').some(s => s.startsWith('comment.'))); + assert.ok(!scopesAt('#LIB', 'LIB').some(s => s.startsWith('keyword.control.directive.'))); +}); + +test('ellipses use the C++ variadic scope', () => { for (const text of ['TEMPLATE <Types...>', 'EXTERN "C" EXTERN_PROCEDURE print(C_INT, ...)', 'CALL print(Values...)']) { assert.ok(scopesAt(text, '...').includes('punctuation.vararg-ellipses.cpp'), text); } diff --git a/plugin/test/indentation.test.js b/plugin/test/indentation.test.js index 9140ed3..e71540f 100644 --- a/plugin/test/indentation.test.js +++ b/plugin/test/indentation.test.js @@ -82,3 +82,13 @@ test('escaped quotes keep block keywords inside literals masked', () => { 'THEN', String.raw`OUTPUT "escaped \" ENDIF //"`, 'ENDIF' ]), [0, 0, 1, 0]); }); + +test('preprocessor conditions preserve ordinary block depth without adding indentation', () => { + const lines = [ + 'PP_DEFINE Flag', 'PP_IFDEF Flag', 'PROCEDURE Demo()', 'PP_IFNDEF Other', + 'IF Ready THEN', 'OUTPUT 1', 'ENDIF', 'PP_ENDIF', 'PP_UNDEF Flag', + 'ENDPROCEDURE', 'PP_ENDIF' + ]; + assert.deepEqual(lineDepths(lines), [0, 0, 0, 1, 1, 2, 1, 1, 1, 0, 0]); + assert.deepEqual(indentationEdits(['PP_IFDEF Flag', 'OUTPUT 1', 'PP_ENDIF'], 0, 2), []); +}); |
