From ef2f8abed24ea78011b9879a305fa9e93330e457 Mon Sep 17 00:00:00 2001 From: Andrew Dupont Date: Fri, 19 May 2023 14:32:27 -0700 Subject: [PATCH] =?UTF-8?q?Update=20`TreeSitterLanguageMode`=20spec?= =?UTF-8?q?=E2=80=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit …not to expect empty tokens. I made a change in 29cfcad that neglected to apply any scopes for a range that was zero characters long. My instincts tell me that this is a safe change to make, but it does affect any tests that used `tokensForScreenRow` and expected it to report information about zero-length tokens. So the expected results needed to be updated. --- spec/tree-sitter-language-mode-spec.js | 29 +++++++++++++++++--------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/spec/tree-sitter-language-mode-spec.js b/spec/tree-sitter-language-mode-spec.js index bdfd95db3..32a1e2c12 100644 --- a/spec/tree-sitter-language-mode-spec.js +++ b/spec/tree-sitter-language-mode-spec.js @@ -41,6 +41,8 @@ describe('TreeSitterLanguageMode', () => { editor = await atom.workspace.open(''); buffer = editor.getBuffer(); editor.displayLayer.reset({ foldCharacter: '…' }); + atom.config.set('core.useTreeSitterParsers', true); + atom.config.set('core.useExperimentalModernTreeSitter', false); }); describe('highlighting', () => { @@ -249,7 +251,7 @@ describe('TreeSitterLanguageMode', () => { [{ text: 'a(', scopes: [] }], [{ text: 'b,', scopes: [] }], [{ text: 'c', scopes: [] }], - [{ text: '', scopes: [] }] + [] ]); buffer.append(')'); @@ -307,7 +309,7 @@ describe('TreeSitterLanguageMode', () => { expectTokensToEqual(editor, [ [{ text: '// abc', scopes: ['comment'] }], - [{ text: '', scopes: [] }], + [], [ { text: 'a(', scopes: [] }, { text: '"b"', scopes: ['string'] }, @@ -319,7 +321,7 @@ describe('TreeSitterLanguageMode', () => { buffer.insert([2, 0], ' '); expectTokensToEqual(editor, [ [{ text: '// abc', scopes: ['comment'] }], - [{ text: '', scopes: [] }], + [], [ { text: ' ', scopes: ['leading-whitespace'] }, { text: 'a(', scopes: [] }, @@ -391,7 +393,7 @@ describe('TreeSitterLanguageMode', () => { { text: '…', scopes: ['fold-marker'] }, { text: ' */', scopes: ['comment'] } ], - [{ text: '', scopes: [] }], + [], [{ text: 'hello', scopes: ['function'] }, { text: '();', scopes: [] }] ]); }); @@ -482,12 +484,18 @@ describe('TreeSitterLanguageMode', () => { await new Promise(process.nextTick); expectTokensToEqual(editor, [ - [{ text: 'abc', scopes: ['variable'] }, { text: ';', scopes: [] }] + [ + { text: 'abc', scopes: ['variable'] }, + { text: ';', scopes: [] } + ] ]); buffer.setTextInRange([[0, 3], [0, 3]], '()'); expectTokensToEqual(editor, [ - [{ text: 'abc()', scopes: ['variable'] }, { text: ';', scopes: [] }] + [ + { text: 'abc()', scopes: ['variable'] }, + { text: ';', scopes: [] } + ] ]); buffer.setTextInRange([[0, 0], [0, 0]], 'new '); @@ -614,8 +622,7 @@ describe('TreeSitterLanguageMode', () => { { text: ' = ', scopes: [] }, { text: 'html', scopes: ['function'] }, { text: ' ', scopes: [] }, - { text: '`', scopes: ['string'] }, - { text: '', scopes: ['string', 'html'] } + { text: '`', scopes: ['string'] } ], [ { text: 'a ', scopes: ['string', 'html'] }, @@ -734,8 +741,7 @@ describe('TreeSitterLanguageMode', () => { { text: ' = ', scopes: [] }, { text: 'html', scopes: ['function'] }, { text: ' ', scopes: [] }, - { text: '`', scopes: ['string'] }, - { text: '', scopes: ['string', 'html'] } + { text: '`', scopes: ['string'] } ], [ { text: 'a ', scopes: ['string', 'html'] }, @@ -2557,6 +2563,9 @@ function expectTokensToEqual(editor, expectedTokenLines) { })); } + // console.log('EXPECTED:', expectedTokenLines); + // console.log('ACTUAL:', tokenLines); + for (let row = startRow; row <= lastRow; row++) { const tokenLine = tokenLines[row]; const expectedTokenLine = expectedTokenLines[row];