summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/clangd
diff options
context:
space:
mode:
authorHaojian Wu <hokein.wu@gmail.com>2019-11-11 16:42:40 +0100
committerHaojian Wu <hokein.wu@gmail.com>2019-11-11 16:47:44 +0100
commitf8c17fe1112009e793d6f9a261622423c2c62049 (patch)
treef7f4770ac4ec671266d168fa8277b86cec41329b /clang-tools-extra/clangd
parent6bcd8d4a18fc0604a2297a626c1fc808cbfb7b9b (diff)
downloadbcm5719-llvm-f8c17fe1112009e793d6f9a261622423c2c62049.tar.gz
bcm5719-llvm-f8c17fe1112009e793d6f9a261622423c2c62049.zip
[clangd] fixes semantic highlighting test
Summary: fixes https://github.com/clangd/clangd/issues/176 Patch by liu hui! Reviewers: ilya-biryukov, hokein, sammccall Reviewed By: hokein Subscribers: MaskRay, jkorous, arphaman, kadircet, usaxena95, cfe-commits Tags: #clang-tools-extra, #clang Differential Revision: https://reviews.llvm.org/D70078
Diffstat (limited to 'clang-tools-extra/clangd')
-rw-r--r--clang-tools-extra/clangd/clients/clangd-vscode/test/semantic-highlighting.test.ts50
1 files changed, 29 insertions, 21 deletions
diff --git a/clang-tools-extra/clangd/clients/clangd-vscode/test/semantic-highlighting.test.ts b/clang-tools-extra/clangd/clients/clangd-vscode/test/semantic-highlighting.test.ts
index 6bc3c45a8b6..9f3e8bd9371 100644
--- a/clang-tools-extra/clangd/clients/clangd-vscode/test/semantic-highlighting.test.ts
+++ b/clang-tools-extra/clangd/clients/clangd-vscode/test/semantic-highlighting.test.ts
@@ -84,19 +84,24 @@ suite('SemanticHighlighting Tests', () => {
return scopeRanges;
};
+ const fileUri1 = vscode.Uri.parse('file:///file1');
+ const fileUri2 = vscode.Uri.parse('file:///file2');
+ const fileUri1Str = fileUri1.toString();
+ const fileUri2Str = fileUri2.toString();
+
class MockHighlighter extends semanticHighlighting.Highlighter {
applicationUriHistory: string[] = [];
// Override to make the highlighting calls accessible to the test. Also
// makes the test not depend on visible text editors.
- applyHighlights(fileUri: string) {
- this.applicationUriHistory.push(fileUri);
+ applyHighlights(fileUri: vscode.Uri) {
+ this.applicationUriHistory.push(fileUri.toString());
}
// Override to make it accessible from the test.
- getDecorationRanges(fileUri: string) {
+ getDecorationRanges(fileUri: vscode.Uri) {
return super.getDecorationRanges(fileUri);
}
// Override to make tests not depend on visible text editors.
- getVisibleTextEditorUris() { return [ 'file1', 'file2' ]; }
+ getVisibleTextEditorUris() { return [ fileUri1, fileUri2 ]; }
}
const highlighter = new MockHighlighter(scopeTable);
const tm = new semanticHighlighting.ThemeRuleMatcher([
@@ -104,11 +109,11 @@ suite('SemanticHighlighting Tests', () => {
{scope : 'entity.type', foreground : '2'},
]);
// Recolorizes when initialized.
- highlighter.highlight('file1', []);
- assert.deepEqual(highlighter.applicationUriHistory, [ 'file1' ]);
+ highlighter.highlight(fileUri1, []);
+ assert.deepEqual(highlighter.applicationUriHistory, [ fileUri1Str ]);
highlighter.initialize(tm);
assert.deepEqual(highlighter.applicationUriHistory,
- [ 'file1', 'file1', 'file2' ]);
+ [ fileUri1Str, fileUri1Str, fileUri2Str ]);
// Groups decorations into the scopes used.
let highlightingsInLine: semanticHighlighting.SemanticHighlightingLine[] = [
{
@@ -128,10 +133,10 @@ suite('SemanticHighlighting Tests', () => {
},
];
- highlighter.highlight('file1', highlightingsInLine);
+ highlighter.highlight(fileUri1, highlightingsInLine);
assert.deepEqual(highlighter.applicationUriHistory,
- [ 'file1', 'file1', 'file2', 'file1' ]);
- assert.deepEqual(highlighter.getDecorationRanges('file1'),
+ [ fileUri1Str, fileUri1Str, fileUri2Str, fileUri1Str ]);
+ assert.deepEqual(highlighter.getDecorationRanges(fileUri1),
createHighlightingScopeRanges(highlightingsInLine));
// Keeps state separate between files.
const highlightingsInLine1:
@@ -141,26 +146,29 @@ suite('SemanticHighlighting Tests', () => {
{character : 2, length : 1, scopeIndex : 0},
]
};
- highlighter.highlight('file2', [ highlightingsInLine1 ]);
- assert.deepEqual(highlighter.applicationUriHistory,
- [ 'file1', 'file1', 'file2', 'file1', 'file2' ]);
- assert.deepEqual(highlighter.getDecorationRanges('file2'),
+ highlighter.highlight(fileUri2, [ highlightingsInLine1 ]);
+ assert.deepEqual(
+ highlighter.applicationUriHistory,
+ [ fileUri1Str, fileUri1Str, fileUri2Str, fileUri1Str, fileUri2Str ]);
+ assert.deepEqual(highlighter.getDecorationRanges(fileUri2),
createHighlightingScopeRanges([ highlightingsInLine1 ]));
// Does full colorizations.
- highlighter.highlight('file1', [ highlightingsInLine1 ]);
- assert.deepEqual(highlighter.applicationUriHistory,
- [ 'file1', 'file1', 'file2', 'file1', 'file2', 'file1' ]);
+ highlighter.highlight(fileUri1, [ highlightingsInLine1 ]);
+ assert.deepEqual(highlighter.applicationUriHistory, [
+ fileUri1Str, fileUri1Str, fileUri2Str, fileUri1Str, fileUri2Str,
+ fileUri1Str
+ ]);
// After the incremental update to line 1, the old highlightings at line 1
// will no longer exist in the array.
assert.deepEqual(
- highlighter.getDecorationRanges('file1'),
+ highlighter.getDecorationRanges(fileUri1),
createHighlightingScopeRanges(
[ highlightingsInLine1, ...highlightingsInLine.slice(1) ]));
// Closing a text document removes all highlightings for the file and no
// other files.
- highlighter.removeFileHighlightings('file1');
- assert.deepEqual(highlighter.getDecorationRanges('file1'), []);
- assert.deepEqual(highlighter.getDecorationRanges('file2'),
+ highlighter.removeFileHighlightings(fileUri1);
+ assert.deepEqual(highlighter.getDecorationRanges(fileUri1), []);
+ assert.deepEqual(highlighter.getDecorationRanges(fileUri2),
createHighlightingScopeRanges([ highlightingsInLine1 ]));
});
});
OpenPOWER on IntegriCloud