Skip to content

Commit e1b8c78

Browse files
authored
Refactors formatter tests into multiple files (#387)
1 parent 0acc29a commit e1b8c78

File tree

7 files changed

+2166
-2136
lines changed

7 files changed

+2166
-2136
lines changed

packages/language-support/src/tests/formatting/commentsv2.test.ts

+484
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/*
2+
* This file is a WIP of the next iteration of the cypher-formatter.
3+
* It's being kept as a separate file to enable having two separate version at once
4+
* since it would be difficult to consolidate the new and the old version
5+
*/
6+
7+
import { formatQuery } from '../../formatting/formattingv2';
8+
9+
// The @ represents the position of the cursor
10+
describe('tests for correct cursor position', () => {
11+
test('cursor at beginning', () => {
12+
const query = 'RETURN -1, -2, -3';
13+
const result = formatQuery(query, 0);
14+
expect(result.newCursorPos).toEqual(0);
15+
});
16+
test('cursor at end', () => {
17+
const query = 'RETURN -1, -2, -3';
18+
const result = formatQuery(query, query.length - 1);
19+
expect(result.newCursorPos).toEqual(result.formattedString.length - 1);
20+
});
21+
test('cursor at newline', () => {
22+
const query = `MATCH (n:Person)
23+
WHERE n.name = "Steve"
24+
RETURN n
25+
@LIMIT 12;`;
26+
const cursorPos = query.search('@');
27+
const result = formatQuery(query.replace('@', ''), cursorPos);
28+
const formated = `MATCH (n:Person)
29+
WHERE n.name = "Steve"
30+
RETURN n@LIMIT 12;`;
31+
expect(result.newCursorPos).toEqual(formated.search('@'));
32+
});
33+
34+
test('cursor start of line with spaces newline', () => {
35+
const query = `UNWIND range(1,100) as _
36+
CALL {
37+
MATCH (source:object) WHERE source.id= $id1
38+
MATCH (target:object) WHERE target.id= $id2
39+
@MATCH path = (source)-[*1..10]->(target)
40+
WITH path, reduce(weight = 0, r IN relationships(path) | weight + r.weight) as Weight
41+
ORDER BY Weight LIMIT 3
42+
RETURN length(path) as l, Weight
43+
}
44+
RETURN count(*)`;
45+
const cursorPos = query.search('@');
46+
const result = formatQuery(query.replace('@', ''), cursorPos);
47+
const formated = `UNWIND range(1, 100) AS _
48+
CALL {
49+
MATCH (source:object)
50+
WHERE source.id = $id1
51+
MATCH (target:object)
52+
WHERE target.id = $id2
53+
@MATCH path = (source)-[*1..10]->(target)
54+
WITH path, REDUCE (weight = 0, r IN relationships(path) | weight + r.weight)
55+
AS Weight ORDER BY Weight LIMIT 3
56+
RETURN length(path) AS l, Weight
57+
}
58+
RETURN count(*)`;
59+
expect(result.newCursorPos).toEqual(formated.search('@'));
60+
});
61+
62+
test('cursor start of line without spaces', () => {
63+
const query = `MATCH (variable :Label)-[:REL_TYPE]->()
64+
WHERE variable.property = "String"
65+
OR namespaced.function() = false
66+
OR $para@meter > 2
67+
RETURN variable;`;
68+
const cursorPos = query.search('@');
69+
const result = formatQuery(query.replace('@', ''), cursorPos);
70+
const formated = `MATCH (variable:Label)-[:REL_TYPE]->()
71+
WHERE variable.property = "String" OR namespaced.function() = false OR
72+
$para@meter > 2
73+
RETURN variable;`;
74+
expect(result.newCursorPos).toEqual(formated.search('@'));
75+
});
76+
});

0 commit comments

Comments
 (0)