diff options
Diffstat (limited to 'plugin/test')
| -rw-r--r-- | plugin/test/brackets.test.js | 9 | ||||
| -rw-r--r-- | plugin/test/highlighting.test.js | 25 | ||||
| -rw-r--r-- | plugin/test/indentation.test.js | 7 |
3 files changed, 35 insertions, 6 deletions
diff --git a/plugin/test/brackets.test.js b/plugin/test/brackets.test.js index e144335..a62e657 100644 --- a/plugin/test/brackets.test.js +++ b/plugin/test/brackets.test.js @@ -24,8 +24,11 @@ test('comments and quotes are ignored with correct UTF-16 offsets after Unicode assert.deepEqual(unmatchedBrackets(unfinished), [unfinished.length - 1]); const unicode = 'OUTPUT "Hello๐"\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(String.raw`OUTPUT "x\"[(//"`), []); + const backslash = String.raw`OUTPUT "x\\" [`; + assert.deepEqual(unmatchedBrackets(backslash), [backslash.length - 1]); + const quoteChar = String.raw`OUTPUT '\'' [`; assert.deepEqual(unmatchedBrackets(quoteChar), [quoteChar.length - 1]); + const escaped = 'OUTPUT "๐\\"["\r\nA['; + assert.deepEqual(unmatchedBrackets(escaped), [escaped.length - 1]); }); diff --git a/plugin/test/highlighting.test.js b/plugin/test/highlighting.test.js index bfdf0a2..8be3d9c 100644 --- a/plugin/test/highlighting.test.js +++ b/plugin/test/highlighting.test.js @@ -122,10 +122,29 @@ test('comments, strings, lowercase and keyword prefixes cannot become keywords', assert.ok(!scopesAt(text, text.split(' ')[0]).some( s => /^(keyword|storage)\./.test(s)), text); } - // CIE has neither backslash escapes nor multiline string literals. + // An unfinished literal must not carry its string scope onto the next line. let state = grammar.tokenizeLine('OUTPUT "unfinished').ruleStack; 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')); +}); + +test('literal escapes protect quotes and reuse C++ escape and suffix scopes', () => { + for (const escape of [String.raw`\'`, String.raw`\"`, String.raw`\\`, String.raw`\?`, + ...['a', 'b', 'f', 'n', 'r', 't', 'v', '0', '101', 'x4142', 'u0041', 'U0001F600'] + .map(value => `\\${value}`)]) { + const text = `OUTPUT "${escape} IF // [" + 1`; + assert.ok(scopesAt(text, escape).includes('constant.character.escape'), escape); + assert.ok(scopesAt(text, 'IF').includes('string.quoted.double.cie-pseudocode'), escape); + assert.ok(scopesAt(text, '+').includes('keyword.operator.cie-pseudocode'), escape); + } + assert.ok(scopesAt(String.raw`OUTPUT '\'' + 1`, '+').includes('keyword.operator.cie-pseudocode')); + assert.ok(scopesAt(String.raw`OUTPUT '\x41'`, String.raw`\x41`).includes('constant.character.escape')); + assert.ok(scopesAt('"text"C', 'C').includes('keyword.other.suffix.literal.user-defined.string.cpp')); + for (const text of ['"text" C', '"text"c', "'x'C"]) { + assert.ok(!scopesAt(text, text.at(-1)).includes('keyword.other.suffix.literal.user-defined.string.cpp')); + } + for (const text of ['OUTPUT "unfinished', 'OUTPUT "unfinished\\', "OUTPUT '''"]) { + const state = grammar.tokenizeLine(text).ruleStack; + assert.ok(grammar.tokenizeLine('IF Ready THEN', state).tokens[0].scopes.includes('keyword.control.cie-pseudocode')); + } }); diff --git a/plugin/test/indentation.test.js b/plugin/test/indentation.test.js index 1a9d91e..9140ed3 100644 --- a/plugin/test/indentation.test.js +++ b/plugin/test/indentation.test.js @@ -75,3 +75,10 @@ test('blank lines are empty when formatted and indented at the caret after Enter assert.deepEqual(indentationEdits(lines, line, line, true), [{ line, length: 3, text: '\t' }]); } }); + +test('escaped quotes keep block keywords inside literals masked', () => { + assert.deepEqual(lineDepths([ + String.raw`IF Text = "quoted \" THEN"`, + 'THEN', String.raw`OUTPUT "escaped \" ENDIF //"`, 'ENDIF' + ]), [0, 0, 1, 0]); +}); |
