1
- Function Get-ExtentText
1
+ Function Get-ExtentTextFromContent
2
2
{
3
- Param (
3
+ Param (
4
4
[Microsoft.Windows.PowerShell.ScriptAnalyzer.Generic.CorrectionExtent ] $violation ,
5
- [string ] $scriptPath
5
+ [string ] $rawContent
6
6
)
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
+
8
14
$typeScriptPos = ' System.Management.Automation.Language.ScriptPosition'
9
15
$start = New-Object - TypeName $typeScriptPos - ArgumentList @ ($scriptPath , $violation.StartLineNumber , $violation.StartColumnNumber , $scriptContent [$violation.StartLineNumber - 1 ])
10
16
$end = New-Object - TypeName $typeScriptPos - ArgumentList @ ($scriptPath , $violation.EndLineNumber , $violation.EndColumnNumber , $scriptContent [$violation.EndLineNumber - 1 ])
11
17
$extent = New-Object - TypeName ' System.Management.Automation.Language.ScriptExtent' - ArgumentList @ ($start , $end )
12
- return ( $extent.Text )
18
+ $extent.Text
13
19
}
14
20
15
21
Function Test-CorrectionExtent
@@ -21,10 +27,27 @@ Function Test-CorrectionExtent
21
27
[string ] $violationText ,
22
28
[string ] $correctionText
23
29
)
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
+
24
47
$corrections = $diagnosticRecord.SuggestedCorrections
25
48
$corrections.Count | Should Be $correctionsCount
26
49
$corrections [0 ].Text | Should Be $correctionText
27
- Get-ExtentText $corrections [0 ] $violationFilepath | `
50
+ Get-ExtentTextFromContent $corrections [0 ] $rawContent | `
28
51
Should Be $violationText
29
52
}
30
53
@@ -57,6 +80,7 @@ Function Get-Count
57
80
58
81
Export-ModuleMember - Function Get-ExtentText
59
82
Export-ModuleMember - Function Test-CorrectionExtent
83
+ Export-ModuleMember - Function Test-CorrectionExtentFromContent
60
84
Export-ModuleMember - Function Test-PSEditionCoreCLR
61
85
Export-ModuleMember - Function Test-PSEditionCoreCLRLinux
62
86
Export-ModuleMember - Function Test-PSVersionV3
0 commit comments