Update TreeSitterLanguageMode spec…

…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.
This commit is contained in:
Andrew Dupont 2023-05-19 14:32:27 -07:00
parent 8afe2f6fc4
commit ef2f8abed2

View File

@ -41,6 +41,8 @@ describe('TreeSitterLanguageMode', () => {
editor = await atom.workspace.open(''); editor = await atom.workspace.open('');
buffer = editor.getBuffer(); buffer = editor.getBuffer();
editor.displayLayer.reset({ foldCharacter: '…' }); editor.displayLayer.reset({ foldCharacter: '…' });
atom.config.set('core.useTreeSitterParsers', true);
atom.config.set('core.useExperimentalModernTreeSitter', false);
}); });
describe('highlighting', () => { describe('highlighting', () => {
@ -249,7 +251,7 @@ describe('TreeSitterLanguageMode', () => {
[{ text: 'a(', scopes: [] }], [{ text: 'a(', scopes: [] }],
[{ text: 'b,', scopes: [] }], [{ text: 'b,', scopes: [] }],
[{ text: 'c', scopes: [] }], [{ text: 'c', scopes: [] }],
[{ text: '', scopes: [] }] []
]); ]);
buffer.append(')'); buffer.append(')');
@ -307,7 +309,7 @@ describe('TreeSitterLanguageMode', () => {
expectTokensToEqual(editor, [ expectTokensToEqual(editor, [
[{ text: '// abc', scopes: ['comment'] }], [{ text: '// abc', scopes: ['comment'] }],
[{ text: '', scopes: [] }], [],
[ [
{ text: 'a(', scopes: [] }, { text: 'a(', scopes: [] },
{ text: '"b"', scopes: ['string'] }, { text: '"b"', scopes: ['string'] },
@ -319,7 +321,7 @@ describe('TreeSitterLanguageMode', () => {
buffer.insert([2, 0], ' '); buffer.insert([2, 0], ' ');
expectTokensToEqual(editor, [ expectTokensToEqual(editor, [
[{ text: '// abc', scopes: ['comment'] }], [{ text: '// abc', scopes: ['comment'] }],
[{ text: '', scopes: [] }], [],
[ [
{ text: ' ', scopes: ['leading-whitespace'] }, { text: ' ', scopes: ['leading-whitespace'] },
{ text: 'a(', scopes: [] }, { text: 'a(', scopes: [] },
@ -391,7 +393,7 @@ describe('TreeSitterLanguageMode', () => {
{ text: '…', scopes: ['fold-marker'] }, { text: '…', scopes: ['fold-marker'] },
{ text: ' */', scopes: ['comment'] } { text: ' */', scopes: ['comment'] }
], ],
[{ text: '', scopes: [] }], [],
[{ text: 'hello', scopes: ['function'] }, { text: '();', scopes: [] }] [{ text: 'hello', scopes: ['function'] }, { text: '();', scopes: [] }]
]); ]);
}); });
@ -482,12 +484,18 @@ describe('TreeSitterLanguageMode', () => {
await new Promise(process.nextTick); await new Promise(process.nextTick);
expectTokensToEqual(editor, [ expectTokensToEqual(editor, [
[{ text: 'abc', scopes: ['variable'] }, { text: ';', scopes: [] }] [
{ text: 'abc', scopes: ['variable'] },
{ text: ';', scopes: [] }
]
]); ]);
buffer.setTextInRange([[0, 3], [0, 3]], '()'); buffer.setTextInRange([[0, 3], [0, 3]], '()');
expectTokensToEqual(editor, [ expectTokensToEqual(editor, [
[{ text: 'abc()', scopes: ['variable'] }, { text: ';', scopes: [] }] [
{ text: 'abc()', scopes: ['variable'] },
{ text: ';', scopes: [] }
]
]); ]);
buffer.setTextInRange([[0, 0], [0, 0]], 'new '); buffer.setTextInRange([[0, 0], [0, 0]], 'new ');
@ -614,8 +622,7 @@ describe('TreeSitterLanguageMode', () => {
{ text: ' = ', scopes: [] }, { text: ' = ', scopes: [] },
{ text: 'html', scopes: ['function'] }, { text: 'html', scopes: ['function'] },
{ text: ' ', scopes: [] }, { text: ' ', scopes: [] },
{ text: '`', scopes: ['string'] }, { text: '`', scopes: ['string'] }
{ text: '', scopes: ['string', 'html'] }
], ],
[ [
{ text: 'a ', scopes: ['string', 'html'] }, { text: 'a ', scopes: ['string', 'html'] },
@ -734,8 +741,7 @@ describe('TreeSitterLanguageMode', () => {
{ text: ' = ', scopes: [] }, { text: ' = ', scopes: [] },
{ text: 'html', scopes: ['function'] }, { text: 'html', scopes: ['function'] },
{ text: ' ', scopes: [] }, { text: ' ', scopes: [] },
{ text: '`', scopes: ['string'] }, { text: '`', scopes: ['string'] }
{ text: '', scopes: ['string', 'html'] }
], ],
[ [
{ text: 'a ', scopes: ['string', 'html'] }, { 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++) { for (let row = startRow; row <= lastRow; row++) {
const tokenLine = tokenLines[row]; const tokenLine = tokenLines[row];
const expectedTokenLine = expectedTokenLines[row]; const expectedTokenLine = expectedTokenLines[row];