Skip to content

Commit ef0e3bd

Browse files
committed
(maint) Refactor folding test fixtures
Previously there was some duplication in the folder test fixtures. This commit refactors the expectation to be more DRY. This commit also adds an expectation on the line endings as we're depending on git to clone correctly. Without this we may get false positive results.
1 parent f574a43 commit ef0e3bd

File tree

1 file changed

+28
-31
lines changed

1 file changed

+28
-31
lines changed

test/features/folding.test.ts

+28-31
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ import { MockLogger } from "../test_utils";
1212
const fixturePath = path.join(__dirname, "..", "..", "..", "test", "fixtures");
1313

1414
function assertFoldingRegions(result, expected): void {
15-
assert.equal(result.length, expected.length);
16-
1715
for (let i = 0; i < expected.length; i++) {
1816
const failMessage = `expected ${JSON.stringify(expected[i])}, actual ${JSON.stringify(result[i])}`;
1917
assert.equal(result[i].start, expected[i].start, failMessage);
2018
assert.equal(result[i].end, expected[i].end, failMessage);
2119
assert.equal(result[i].kind, expected[i].kind, failMessage);
2220
}
21+
22+
assert.equal(result.length, expected.length);
2323
}
2424

2525
suite("Features", () => {
@@ -36,14 +36,8 @@ suite("Features", () => {
3636
assert.notEqual(psGrammar, null);
3737
});
3838

39-
test("Can detect all of the foldable regions in a document with CRLF line endings", async () => {
40-
// Integration test against the test fixture 'folding-crlf.ps1' that contains
41-
// all of the different types of folding available
42-
const uri = vscode.Uri.file(path.join(fixturePath, "folding-crlf.ps1"));
43-
const document = await vscode.workspace.openTextDocument(uri);
44-
const result = await provider.provideFoldingRanges(document, null, null);
45-
46-
const expected = [
39+
suite("For a single document", async () => {
40+
const expectedFoldingRegions = [
4741
{ start: 1, end: 6, kind: 1 },
4842
{ start: 7, end: 51, kind: 3 },
4943
{ start: 8, end: 13, kind: 1 },
@@ -56,30 +50,33 @@ suite("Features", () => {
5650
{ start: 47, end: 50, kind: 3 },
5751
];
5852

59-
assertFoldingRegions(result, expected);
60-
});
53+
test("Can detect all of the foldable regions in a document with CRLF line endings", async () => {
54+
// Integration test against the test fixture 'folding-crlf.ps1' that contains
55+
// all of the different types of folding available
56+
const uri = vscode.Uri.file(path.join(fixturePath, "folding-crlf.ps1"));
57+
const document = await vscode.workspace.openTextDocument(uri);
58+
const result = await provider.provideFoldingRanges(document, null, null);
6159

62-
test("Can detect all of the foldable regions in a document with LF line endings", async () => {
63-
// Integration test against the test fixture 'folding-lf.ps1' that contains
64-
// all of the different types of folding available
65-
const uri = vscode.Uri.file(path.join(fixturePath, "folding-lf.ps1"));
66-
const document = await vscode.workspace.openTextDocument(uri);
67-
const result = await provider.provideFoldingRanges(document, null, null);
60+
// Ensure we have CRLF line endings as we're depending on git
61+
// to clone the test fixtures correctly
62+
assert.notEqual(document.getText().indexOf("\r\n"), -1);
6863

69-
const expected = [
70-
{ start: 1, end: 6, kind: 1 },
71-
{ start: 7, end: 51, kind: 3 },
72-
{ start: 8, end: 13, kind: 1 },
73-
{ start: 14, end: 17, kind: 3 },
74-
{ start: 19, end: 22, kind: 3 },
75-
{ start: 26, end: 28, kind: 1 },
76-
{ start: 30, end: 40, kind: 3 },
77-
{ start: 32, end: 36, kind: 3 },
78-
{ start: 42, end: 44, kind: 3 },
79-
{ start: 47, end: 50, kind: 3 },
80-
];
64+
assertFoldingRegions(result, expectedFoldingRegions);
65+
});
66+
67+
test("Can detect all of the foldable regions in a document with LF line endings", async () => {
68+
// Integration test against the test fixture 'folding-lf.ps1' that contains
69+
// all of the different types of folding available
70+
const uri = vscode.Uri.file(path.join(fixturePath, "folding-lf.ps1"));
71+
const document = await vscode.workspace.openTextDocument(uri);
72+
const result = await provider.provideFoldingRanges(document, null, null);
73+
74+
// Ensure we do not CRLF line endings as we're depending on git
75+
// to clone the test fixtures correctly
76+
assert.equal(document.getText().indexOf("\r\n"), -1);
8177

82-
assertFoldingRegions(result, expected);
78+
assertFoldingRegions(result, expectedFoldingRegions);
79+
});
8380
});
8481
});
8582
});

0 commit comments

Comments
 (0)