Skip to content

Commit 5ec3261

Browse files
committed
Make upper and lower case work correctly
1 parent bca6585 commit 5ec3261

File tree

2 files changed

+56
-14
lines changed

2 files changed

+56
-14
lines changed

tests/pester/Syntax.Tests.ps1

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -66,21 +66,31 @@ Describe "Syntax highlighting" {
6666
}
6767

6868
It "produces same tokens for lower case" {
69-
$stLowScopes = Get-SublimeScopesFromFile (Join-Path $tokensFolder "test-file.ps1.lower.tokens" )
70-
$diff = Compare-Object $stScopes $stLowScopes
71-
if ($diff) {
72-
$diff | Write-DiffAsWarning
69+
$stOtherScopes = Get-SublimeScopesFromFile (Join-Path $tokensFolder "test-file.ps1.lower.tokens" )
70+
Write-Host -ForegroundColor Cyan "Scopes count = $($stScopes.Length) "
71+
Write-Host -ForegroundColor Cyan "Lower scopes count = $($stOtherScopes.Length) "
72+
73+
$n = @($stScopes.Length, $stOtherScopes.Length) | Get-Max
74+
0..($n-1) | % {
75+
if (-not (Test-ScopesEqual $stScopes[$_] $stOtherScopes[$_])) {
76+
#Write-Warning "Scopes are different $($stScopes[$_]) $($stOtherScopes[$_])"
77+
$stScopes[$_] | Should be $stOtherScopes[$_]
78+
}
7379
}
74-
$diff | Should Be $null
7580
}
7681

7782
It "produces same tokens for upper case" {
78-
$stUpperScopes = Get-SublimeScopesFromFile (Join-Path $tokensFolder "test-file.ps1.upper.tokens" )
79-
$diff = Compare-Object $stScopes $stUpperScopes
80-
if ($diff) {
81-
$diff | Write-DiffAsWarning
83+
$stOtherScopes = Get-SublimeScopesFromFile (Join-Path $tokensFolder "test-file.ps1.upper.tokens" )
84+
Write-Host -ForegroundColor Cyan "Scopes count = $($stScopes.Length) "
85+
Write-Host -ForegroundColor Cyan "Upper scopes count = $($stOtherScopes.Length) "
86+
87+
$n = @($stScopes.Length, $stOtherScopes.Length) | Get-Max
88+
0..($n-1) | % {
89+
if (-not (Test-ScopesEqual $stScopes[$_] $stOtherScopes[$_])) {
90+
#Write-Warning "Scopes are different $($stScopes[$_]) $($stOtherScopes[$_])"
91+
$stScopes[$_] | Should be $stOtherScopes[$_]
92+
}
8293
}
83-
$diff | Should Be $null
8494
}
8595
}
8696
}

tests/pester/SyntaxHelper.psm1

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,16 +157,48 @@ function Test-ScopeDisclosure
157157
return $false
158158
}
159159

160-
function Write-DiffAsWarning
160+
function Test-ScopesEqual
161+
{
162+
[CmdletBinding()]
163+
param(
164+
$leftScope,
165+
$rightScope
166+
)
167+
if ($leftScope.startOffset -ne $rightScope.startOffset) {return $false}
168+
if ($leftScope.endOffset -ne $rightScope.endOffset) {return $false}
169+
if ($leftScope.Text -ne $rightScope.Text) {return $false}
170+
#TODO: this is week, need to make stronger
171+
#if ($leftScope.Kind.Split('.')[0] -ne $rightScope.Kind.Split('.')[0]) {return $false}
172+
return $true
173+
}
174+
175+
function Get-Max
161176
{
162177
[CmdletBinding()]
163178
param(
164179
[Parameter(ValueFromPipeline)]
165-
$diff
180+
$object
166181
)
167182

168-
process
183+
begin
184+
{
185+
$max = $null
186+
}
187+
188+
process
189+
{
190+
if (-not $max)
191+
{
192+
$max = $object
193+
} else {
194+
if ($object -gt $max) {
195+
$max = $object
196+
}
197+
}
198+
}
199+
200+
end
169201
{
170-
Write-Warning "$($diff.SideIndicator) | $($diff.InputObject)"
202+
return $max
171203
}
172204
}

0 commit comments

Comments
 (0)