1- Function Get-ExtentText
1+ Function Get-ExtentTextFromContent
22{
3- Param (
3+ Param (
44 [Microsoft.Windows.PowerShell.ScriptAnalyzer.Generic.CorrectionExtent ] $violation ,
5- [string ] $scriptPath
5+ [string ] $rawContent
66 )
7- $scriptContent = Get-Content - Path $scriptPath
7+ $scriptContent = New-Object - TypeName ' System.Collections.ArrayList'
8+ $stringReader = New-Object - TypeName ' System.IO.StringReader' - ArgumentList @ ($rawContent )
9+ while ($stringReader.Peek () -ne -1 )
10+ {
11+ $scriptContent.Add ($stringReader.ReadLine ()) | Out-Null
12+ }
13+
814 $typeScriptPos = ' System.Management.Automation.Language.ScriptPosition'
915 $start = New-Object - TypeName $typeScriptPos - ArgumentList @ ($scriptPath , $violation.StartLineNumber , $violation.StartColumnNumber , $scriptContent [$violation.StartLineNumber - 1 ])
1016 $end = New-Object - TypeName $typeScriptPos - ArgumentList @ ($scriptPath , $violation.EndLineNumber , $violation.EndColumnNumber , $scriptContent [$violation.EndLineNumber - 1 ])
1117 $extent = New-Object - TypeName ' System.Management.Automation.Language.ScriptExtent' - ArgumentList @ ($start , $end )
12- return ( $extent.Text )
18+ $extent.Text
1319}
1420
1521Function Test-CorrectionExtent
@@ -21,10 +27,27 @@ Function Test-CorrectionExtent
2127 [string ] $violationText ,
2228 [string ] $correctionText
2329 )
30+
31+ Test-CorrectionExtentFromContent (Get-Content $violationFilepath - Raw) `
32+ $diagnosticRecord `
33+ $correctionsCount `
34+ $violationText `
35+ $correctionText
36+ }
37+
38+ Function Test-CorrectionExtentFromContent {
39+ param (
40+ [string ] $rawContent ,
41+ [Microsoft.Windows.PowerShell.ScriptAnalyzer.Generic.DiagnosticRecord ] $diagnosticRecord ,
42+ [int ] $correctionsCount ,
43+ [string ] $violationText ,
44+ [string ] $correctionText
45+ )
46+
2447 $corrections = $diagnosticRecord.SuggestedCorrections
2548 $corrections.Count | Should Be $correctionsCount
2649 $corrections [0 ].Text | Should Be $correctionText
27- Get-ExtentText $corrections [0 ] $violationFilepath | `
50+ Get-ExtentTextFromContent $corrections [0 ] $rawContent | `
2851 Should Be $violationText
2952}
3053
@@ -57,6 +80,7 @@ Function Get-Count
5780
5881Export-ModuleMember - Function Get-ExtentText
5982Export-ModuleMember - Function Test-CorrectionExtent
83+ Export-ModuleMember - Function Test-CorrectionExtentFromContent
6084Export-ModuleMember - Function Test-PSEditionCoreCLR
6185Export-ModuleMember - Function Test-PSEditionCoreCLRLinux
6286Export-ModuleMember - Function Test-PSVersionV3
0 commit comments