Skip to content

Commit

Permalink
(GH-1417) Add tests for CRLF documents
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
glennsarti committed Jul 10, 2018
1 parent 77da510 commit 746b2e9
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 3 deletions.
28 changes: 25 additions & 3 deletions test/features/folding.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,32 @@ suite("Features", () => {
assert.notEqual(psGrammar, null);
});

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

const expected = [
{ start: 1, end: 6, kind: 1 },
{ start: 7, end: 46, kind: 3 },
{ start: 8, end: 13, kind: 1 },
{ start: 14, end: 17, kind: 3 },
{ start: 21, end: 23, kind: 1 },
{ start: 25, end: 35, kind: 3 },
{ start: 27, end: 31, kind: 3 },
{ start: 37, end: 39, kind: 3 },
{ start: 42, end: 45, kind: 3 },
];

assertFoldingRegions(result, expected);
});

test("Can detect all of the foldable regions in a document with LF line endings", async () => {
// Integration test against the test fixture 'folding-lf.ps1' that contains
// all of the different types of folding available
const uri = vscode.Uri.file(path.join(fixturePath, "folding-lf.ps1"));
const document = await vscode.workspace.openTextDocument(uri);
const result = await provider.provideFoldingRanges(document, null, null);

Expand Down
8 changes: 8 additions & 0 deletions test/fixtures/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Set the default behavior, in case people don't have core.autocrlf set.
* text=auto

# These test fixtures require crlf
folding-crlf.ps1 text eol=crlf

# These test fixtures require lf
folding-lf.ps1 text eol=lf
File renamed without changes.
47 changes: 47 additions & 0 deletions test/fixtures/folding-lf.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
function short-func {};
<#
.SYNOPSIS
Displays a list of WMI Classes based upon a search criteria
.EXAMPLE
Get-WmiClasses -class disk -ns rootcimv2"
#>
function New-VSCodeCannotFold {
<#
.SYNOPSIS
Displays a list of WMI Classes based upon a search criteria
.EXAMPLE
Get-WmiClasses -class disk -ns rootcimv2"
#>
$I = @'
cannot fold
'@

# this won't be folded

# This should be foldable
# This should be foldable
# This should be foldable

#region This fools the indentation folding.
Write-Host "Hello"
# region
Write-Host "Hello"
# comment1
Write-Host "Hello"
#endregion
Write-Host "Hello"
# comment2
Write-Host "Hello"
# endregion

$c = {
Write-Host "Hello"
}

# Array fools indentation folding
$d = @(
'element1',
'elemet2'
)
}

0 comments on commit 746b2e9

Please sign in to comment.