1+ Function Get-ExtentText
2+ {
3+ Param (
4+ [Microsoft.Windows.PowerShell.ScriptAnalyzer.Generic.CorrectionExtent ] $violation ,
5+ [string ] $scriptPath
6+ )
7+ $scriptContent = Get-Content - Path $scriptPath
8+ $typeScriptPos = ' System.Management.Automation.Language.ScriptPosition'
9+ $start = New-Object - TypeName $typeScriptPos - ArgumentList @ ($scriptPath , $violation.StartLineNumber , $violation.StartColumnNumber , $scriptContent [$violation.StartLineNumber - 1 ])
10+ $end = New-Object - TypeName $typeScriptPos - ArgumentList @ ($scriptPath , $violation.EndLineNumber , $violation.EndColumnNumber , $scriptContent [$violation.EndLineNumber - 1 ])
11+ $extent = New-Object - TypeName ' System.Management.Automation.Language.ScriptExtent' - ArgumentList @ ($start , $end )
12+ return ($extent.Text )
13+ }
14+
15+ Function Test-CorrectionExtent
16+ {
17+ Param (
18+ [string ] $violationFilepath ,
19+ [Microsoft.Windows.PowerShell.ScriptAnalyzer.Generic.DiagnosticRecord ] $diagnosticRecord ,
20+ [int ] $correctionsCount ,
21+ [string ] $violationText ,
22+ [string ] $correctionText
23+ )
24+ $corrections = $diagnosticRecord.SuggestedCorrections
25+ $corrections.Count | Should Be $correctionsCount
26+ $corrections [0 ].Text | Should Be $correctionText
27+ Get-ExtentText $corrections [0 ] $violationFilepath | `
28+ Should Be $violationText
29+ }
30+
31+ Function Test-PSEditionCoreCLR
32+ {
33+ ($PSVersionTable.Keys -contains " PSEdition" ) -and ($PSVersionTable.PSEdition -ne ' Desktop' )
34+ }
35+
36+ Export-ModuleMember - Function Get-ExtentText
37+ Export-ModuleMember - Function Test-CorrectionExtent
38+ Export-ModuleMember - Function Test-PSEditionCoreCLR
0 commit comments