Skip to content

Commit 0e5d2f1

Browse files
committed
Unificate CRLF approach to make it independent on git checkout mode
1 parent 1a11295 commit 0e5d2f1

File tree

1 file changed

+5
-38
lines changed

1 file changed

+5
-38
lines changed

tests/pester/SyntaxHelper.psm1

Lines changed: 5 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,8 @@ function Get-TokensFromFile
66
[string] $filePath
77
)
88

9-
$tokens = $null
10-
$errors = $null
11-
$ast = [System.Management.Automation.Language.Parser]::ParseFile((Resolve-Path $filePath).Path, [ref]$tokens, [ref]$errors)
12-
13-
return $tokens
9+
# Adjust offsets for CRLF
10+
Get-TokensFromInput (cat -raw $filePath).Replace("`r`n","`n")
1411
}
1512

1613
function Get-SublimeScopesFromFile
@@ -53,42 +50,12 @@ function Select-TokenByOffset
5350

5451
process
5552
{
56-
if (((Get-TokenStartOffset $token) -le $offset) -and ((Get-TokenEndOffset $token) -gt $offset)) {
53+
if (($token.Extent.startOffset -le $offset) -and ($token.Extent.endOffset -gt $offset)) {
5754
return $token
5855
}
5956
}
6057
}
6158

62-
function Get-TokenStartOffset
63-
{
64-
[CmdletBinding()]
65-
param(
66-
[Parameter(ValueFromPipeline)]
67-
[System.Management.Automation.Language.Token] $token
68-
)
69-
70-
process
71-
{
72-
# Adjust offsets for CRLF
73-
return $token.Extent.StartOffset - $token.Extent.StartLineNumber + 1
74-
}
75-
}
76-
77-
function Get-TokenEndOffset
78-
{
79-
[CmdletBinding()]
80-
param(
81-
[Parameter(ValueFromPipeline)]
82-
[System.Management.Automation.Language.Token] $token
83-
)
84-
85-
process
86-
{
87-
# Adjust offsets for CRLF
88-
return $token.Extent.EndOffset - $token.Extent.EndLineNumber + 1
89-
}
90-
}
91-
9259
function Convert-TokenToScope
9360
{
9461
[CmdletBinding()]
@@ -106,8 +73,8 @@ function Convert-TokenToScope
10673

10774
$h = @{
10875
text = $token.Text
109-
startOffset = Get-TokenStartOffset $token
110-
endOffset = Get-TokenEndOffset $token
76+
startOffset = $token.Extent.startOffset
77+
endOffset = $token.Extent.endOffset
11178
kind = $token.Kind
11279
}
11380

0 commit comments

Comments
 (0)