Skip to content

Commit 746b2e9

Browse files
committed
(GH-1417) Add tests for CRLF documents
Previously the test fixtures were failing on some Windows systems due to git changing the line endings. This commit adds a new test fixture, and runs the same tests on the same content document, but each with a different line-ending (CRLF and LF).
1 parent 77da510 commit 746b2e9

File tree

4 files changed

+80
-3
lines changed

4 files changed

+80
-3
lines changed

test/features/folding.test.ts

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,32 @@ suite("Features", () => {
3636
assert.notEqual(psGrammar, null);
3737
});
3838

39-
test("Can detect all of the foldable regions in a document", async () => {
40-
// Integration test against the test fixture 'folding.ps1' that contains
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
4141
// all of the different types of folding available
42-
const uri = vscode.Uri.file(path.join(fixturePath, "folding.ps1"));
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 = [
47+
{ start: 1, end: 6, kind: 1 },
48+
{ start: 7, end: 46, kind: 3 },
49+
{ start: 8, end: 13, kind: 1 },
50+
{ start: 14, end: 17, kind: 3 },
51+
{ start: 21, end: 23, kind: 1 },
52+
{ start: 25, end: 35, kind: 3 },
53+
{ start: 27, end: 31, kind: 3 },
54+
{ start: 37, end: 39, kind: 3 },
55+
{ start: 42, end: 45, kind: 3 },
56+
];
57+
58+
assertFoldingRegions(result, expected);
59+
});
60+
61+
test("Can detect all of the foldable regions in a document with LF line endings", async () => {
62+
// Integration test against the test fixture 'folding-lf.ps1' that contains
63+
// all of the different types of folding available
64+
const uri = vscode.Uri.file(path.join(fixturePath, "folding-lf.ps1"));
4365
const document = await vscode.workspace.openTextDocument(uri);
4466
const result = await provider.provideFoldingRanges(document, null, null);
4567

test/fixtures/.gitattributes

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Set the default behavior, in case people don't have core.autocrlf set.
2+
* text=auto
3+
4+
# These test fixtures require crlf
5+
folding-crlf.ps1 text eol=crlf
6+
7+
# These test fixtures require lf
8+
folding-lf.ps1 text eol=lf
File renamed without changes.

test/fixtures/folding-lf.ps1

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
function short-func {};
2+
<#
3+
.SYNOPSIS
4+
Displays a list of WMI Classes based upon a search criteria
5+
.EXAMPLE
6+
Get-WmiClasses -class disk -ns rootcimv2"
7+
#>
8+
function New-VSCodeCannotFold {
9+
<#
10+
.SYNOPSIS
11+
Displays a list of WMI Classes based upon a search criteria
12+
.EXAMPLE
13+
Get-WmiClasses -class disk -ns rootcimv2"
14+
#>
15+
$I = @'
16+
cannot fold
17+
18+
'@
19+
20+
# this won't be folded
21+
22+
# This should be foldable
23+
# This should be foldable
24+
# This should be foldable
25+
26+
#region This fools the indentation folding.
27+
Write-Host "Hello"
28+
# region
29+
Write-Host "Hello"
30+
# comment1
31+
Write-Host "Hello"
32+
#endregion
33+
Write-Host "Hello"
34+
# comment2
35+
Write-Host "Hello"
36+
# endregion
37+
38+
$c = {
39+
Write-Host "Hello"
40+
}
41+
42+
# Array fools indentation folding
43+
$d = @(
44+
'element1',
45+
'elemet2'
46+
)
47+
}

0 commit comments

Comments
 (0)