Skip to content

Commit 94b95eb

Browse files
committed
Adds test for a bug with an empty query in VSCode
1 parent 87817aa commit 94b95eb

File tree

2 files changed

+93
-0
lines changed

2 files changed

+93
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
MATCH (n) RETURN m
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
import * as assert from 'assert';
2+
import * as vscode from 'vscode';
3+
import { eventually, getDocumentUri, openDocument } from '../helpers';
4+
5+
type InclusionTestArgs = {
6+
textFile: string;
7+
expected: vscode.Diagnostic[];
8+
};
9+
10+
export async function testSyntaxValidation({
11+
textFile,
12+
expected,
13+
}: InclusionTestArgs) {
14+
await eventually(
15+
() =>
16+
new Promise((resolve, reject) => {
17+
const docUri = getDocumentUri(textFile);
18+
const diagnostics: vscode.Diagnostic[] =
19+
vscode.languages.getDiagnostics(docUri);
20+
21+
try {
22+
// We need to test diagnostics one by one
23+
// because the ones returned by VSCode contain
24+
// more information we don't care about in the tests
25+
assert.equal(diagnostics.length, expected.length);
26+
diagnostics.forEach((diagnostic, i) => {
27+
const expectedDiagnostic = expected[i];
28+
assert.equal(diagnostic.message, expectedDiagnostic.message);
29+
assert.deepEqual(diagnostic.range, expectedDiagnostic.range);
30+
assert.equal(diagnostic.severity, expectedDiagnostic.severity);
31+
});
32+
resolve();
33+
} catch (e) {
34+
reject();
35+
}
36+
}),
37+
);
38+
}
39+
40+
suite('Syntax validation spec', () => {
41+
test('Correctly validates empty cypher statement', async () => {
42+
const textFile = 'syntax-validation.cypher';
43+
const docUri = getDocumentUri(textFile);
44+
45+
await openDocument(docUri);
46+
47+
const editor = vscode.window.activeTextEditor;
48+
49+
await editor.edit((editBuilder) =>
50+
editBuilder.replace(
51+
// Select the whole file
52+
new vscode.Range(
53+
new vscode.Position(0, 0),
54+
new vscode.Position(100, 0),
55+
),
56+
'MATCH (n)',
57+
),
58+
);
59+
60+
// We need to wait here because diagnostics are eventually
61+
// consistent i.e. they don't show up immediately
62+
await testSyntaxValidation({
63+
textFile: 'syntax-validation.cypher',
64+
expected: [
65+
new vscode.Diagnostic(
66+
new vscode.Range(
67+
new vscode.Position(0, 0),
68+
new vscode.Position(0, 9),
69+
),
70+
'Query cannot conclude with MATCH (must be a RETURN clause, an update clause, a unit subquery call, or a procedure call with no YIELD)',
71+
vscode.DiagnosticSeverity.Error,
72+
),
73+
],
74+
});
75+
76+
await editor.edit((editBuilder) =>
77+
editBuilder.replace(
78+
// Select the whole file
79+
new vscode.Range(
80+
new vscode.Position(0, 0),
81+
new vscode.Position(100, 0),
82+
),
83+
'',
84+
),
85+
);
86+
87+
await testSyntaxValidation({
88+
textFile: 'syntax-validation.cypher',
89+
expected: [],
90+
});
91+
});
92+
});

0 commit comments

Comments
 (0)