Skip to content

Commit

Permalink
Colorization tests for tree sitter (#229376)
Browse files Browse the repository at this point in the history
* Colorization tests for tree sitter
Part of #210475

* Fix tests

* Actually fix tests

* Fix line endings
  • Loading branch information
alexr00 authored Sep 23, 2024
1 parent b09ef53 commit ccefcfa
Show file tree
Hide file tree
Showing 116 changed files with 11,507 additions and 74 deletions.
1 change: 1 addition & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -953,6 +953,7 @@
"vs/workbench/contrib/*/~",
"vs/workbench/contrib/terminal/terminalContribExports*",
"vscode-notebook-renderer", // Type only import
"@vscode/tree-sitter-wasm", // type import
{
"when": "hasBrowser",
"pattern": "@xterm/xterm"
Expand Down
16 changes: 14 additions & 2 deletions extensions/vscode-colorize-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
},
"icon": "media/icon.png",
"scripts": {
"vscode:prepublish": "node ../../node_modules/gulp/bin/gulp.js --gulpfile ../../build/gulpfile.extensions.js compile-extension:vscode-colorize-tests ./tsconfig.json"
"vscode:prepublish": "node ../../node_modules/gulp/bin/gulp.js --gulpfile ../../build/gulpfile.extensions.js compile-extension:vscode-colorize-tests ./tsconfig.json",
"watch": "gulp watch-extension:vscode-colorize-tests",
"compile": "gulp compile-extension:vscode-colorize-tests"
},
"dependencies": {
"jsonc-parser": "^3.2.0"
Expand Down Expand Up @@ -51,7 +53,17 @@
"path": "./producticons/test-product-icon-theme.json",
"_watch": true
}
]
],
"configuration": {
"title": "Color Tests",
"properties": {
"editor.experimental.preferTreeSitter": {
"type": "array",
"default": ["typescript"],
"description": "Enable the experimental tree-sitter parser."
}
}
}
},
"repository": {
"type": "git",
Expand Down
37 changes: 24 additions & 13 deletions extensions/vscode-colorize-tests/src/colorizer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,20 @@ import * as assert from 'assert';
import * as fs from 'fs';
import 'mocha';
import { join, normalize } from 'path';
import { commands, Uri } from 'vscode';
import { commands, Uri, workspace, ConfigurationTarget } from 'vscode';

function assertUnchangedTokens(fixturesPath: string, resultsPath: string, fixture: string, done: any) {
async function assertUnchangedTokens(fixturesPath: string, resultsPath: string, treeSitterResultsPath: string, fixture: string, done: any) {
const testFixurePath = join(fixturesPath, fixture);
const tokenizers = [{ command: '_workbench.captureSyntaxTokens', resultsPath }, { command: '_workbench.captureTreeSitterSyntaxTokens', resultsPath: treeSitterResultsPath }];

return commands.executeCommand('_workbench.captureSyntaxTokens', Uri.file(testFixurePath)).then(data => {
try {
if (!fs.existsSync(resultsPath)) {
fs.mkdirSync(resultsPath);
try {
await Promise.all(tokenizers.map(async (tokenizer) => {
const data = await commands.executeCommand(tokenizer.command, Uri.file(testFixurePath));

if (!fs.existsSync(tokenizer.resultsPath)) {
fs.mkdirSync(tokenizer.resultsPath);
}
const resultPath = join(resultsPath, fixture.replace('.', '_') + '.json');
const resultPath = join(tokenizer.resultsPath, fixture.replace('.', '_') + '.json');
if (fs.existsSync(resultPath)) {
const previousData = JSON.parse(fs.readFileSync(resultPath).toString());
try {
Expand All @@ -40,11 +43,11 @@ function assertUnchangedTokens(fixturesPath: string, resultsPath: string, fixtur
} else {
fs.writeFileSync(resultPath, JSON.stringify(data, null, '\t'));
}
done();
} catch (e) {
done(e);
}
}, done);
}));
done();
} catch (e) {
done(e);
}
}

function hasThemeChange(d: any, p: any): boolean {
Expand All @@ -61,11 +64,19 @@ suite('colorization', () => {
const testPath = normalize(join(__dirname, '../test'));
const fixturesPath = join(testPath, 'colorize-fixtures');
const resultsPath = join(testPath, 'colorize-results');
const treeSitterResultsPath = join(testPath, 'colorize-tree-sitter-results');

suiteSetup(async function () {
await workspace.getConfiguration('editor').update('experimental.preferTreeSitter', ["typescript"], ConfigurationTarget.Global);
});
suiteTeardown(async function () {
await workspace.getConfiguration('editor').update('experimental.preferTreeSitter', [], ConfigurationTarget.Global);
});

for (const fixture of fs.readdirSync(fixturesPath)) {
test(`colorize: ${fixture}`, function (done) {
commands.executeCommand('workbench.action.closeAllEditors').then(() => {
assertUnchangedTokens(fixturesPath, resultsPath, fixture, done);
assertUnchangedTokens(fixturesPath, resultsPath, treeSitterResultsPath, fixture, done);
});
});
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
[
{
"c": "rowData",
"t": "variable",
"r": {
"dark_plus": "variable: #9CDCFE",
"light_plus": "variable: #001080",
"hc_black": "variable: #9CDCFE",
"dark_modern": "variable: #9CDCFE",
"hc_light": "variable: #001080",
"light_modern": "variable: #001080"
}
},
{
"c": ".",
"t": "punctuation.delimiter",
"r": {}
},
{
"c": "push",
"t": "variable entity.name.function",
"r": {
"dark_plus": "entity.name.function: #DCDCAA",
"light_plus": "entity.name.function: #795E26",
"hc_black": "entity.name.function: #DCDCAA",
"dark_modern": "entity.name.function: #DCDCAA",
"hc_light": "entity.name.function: #5E2CBC",
"light_modern": "entity.name.function: #795E26"
}
},
{
"c": "(",
"t": "",
"r": {}
},
{
"c": "callback",
"t": "variable entity.name.function",
"r": {
"dark_plus": "entity.name.function: #DCDCAA",
"light_plus": "entity.name.function: #795E26",
"hc_black": "entity.name.function: #DCDCAA",
"dark_modern": "entity.name.function: #DCDCAA",
"hc_light": "entity.name.function: #5E2CBC",
"light_modern": "entity.name.function: #795E26"
}
},
{
"c": "(",
"t": "",
"r": {}
},
{
"c": "new",
"t": "keyword.operator.new",
"r": {
"dark_plus": "keyword.operator.new: #569CD6",
"light_plus": "keyword.operator.new: #0000FF",
"dark_vs": "keyword.operator.new: #569CD6",
"light_vs": "keyword.operator.new: #0000FF",
"hc_black": "keyword.operator.new: #569CD6",
"dark_modern": "keyword.operator.new: #569CD6",
"hc_light": "keyword.operator.new: #0F4A85",
"light_modern": "keyword.operator.new: #0000FF"
}
},
{
"c": "Cell",
"t": "variable entity.name.function",
"r": {
"dark_plus": "entity.name.function: #DCDCAA",
"light_plus": "entity.name.function: #795E26",
"hc_black": "entity.name.function: #DCDCAA",
"dark_modern": "entity.name.function: #DCDCAA",
"hc_light": "entity.name.function: #5E2CBC",
"light_modern": "entity.name.function: #795E26"
}
},
{
"c": "(",
"t": "",
"r": {}
},
{
"c": "row",
"t": "variable",
"r": {
"dark_plus": "variable: #9CDCFE",
"light_plus": "variable: #001080",
"hc_black": "variable: #9CDCFE",
"dark_modern": "variable: #9CDCFE",
"hc_light": "variable: #001080",
"light_modern": "variable: #001080"
}
},
{
"c": ",",
"t": "punctuation.delimiter",
"r": {}
},
{
"c": "col",
"t": "variable",
"r": {
"dark_plus": "variable: #9CDCFE",
"light_plus": "variable: #001080",
"hc_black": "variable: #9CDCFE",
"dark_modern": "variable: #9CDCFE",
"hc_light": "variable: #001080",
"light_modern": "variable: #001080"
}
},
{
"c": ",",
"t": "punctuation.delimiter",
"r": {}
},
{
"c": "false",
"t": "constant.language",
"r": {
"dark_plus": "constant.language: #569CD6",
"light_plus": "constant.language: #0000FF",
"dark_vs": "constant.language: #569CD6",
"light_vs": "constant.language: #0000FF",
"hc_black": "constant.language: #569CD6",
"dark_modern": "constant.language: #569CD6",
"hc_light": "constant.language: #0F4A85",
"light_modern": "constant.language: #0000FF"
}
},
{
"c": ")",
"t": "",
"r": {}
},
{
"c": ")",
"t": "",
"r": {}
},
{
"c": ")",
"t": "",
"r": {}
},
{
"c": ";",
"t": "punctuation.delimiter",
"r": {}
}
]
Loading

0 comments on commit ccefcfa

Please sign in to comment.