|
1 | 1 | Import-Module PSScriptAnalyzer |
2 | 2 | $writeHostName = "PSMisleadingBacktick" |
3 | 3 | $directory = Split-Path -Parent $MyInvocation.MyCommand.Path |
4 | | -$violationsFilepath = Join-Path $directory 'MisleadingBacktick.ps1' |
5 | | -$violations = Invoke-ScriptAnalyzer $violationsFilepath | Where-Object {$_.RuleName -eq $writeHostName} |
| 4 | +$violationFilepath = Join-Path $directory 'MisleadingBacktick.ps1' |
| 5 | +$violations = Invoke-ScriptAnalyzer $violationFilepath | Where-Object {$_.RuleName -eq $writeHostName} |
6 | 6 | $noViolations = Invoke-ScriptAnalyzer $directory\NoMisleadingBacktick.ps1 | Where-Object {$_.RuleName -eq $clearHostName} |
7 | 7 |
|
8 | 8 | Describe "Avoid Misleading Backticks" { |
9 | 9 | Context "When there are violations" { |
10 | 10 | It "has 5 misleading backtick violations" { |
11 | | - Import-Module .\PSScriptAnalyzerTestHelper.psm1 |
12 | 11 | $violations.Count | Should Be 5 |
13 | | - |
14 | | - $idx = 0 |
15 | | - $violations[$idx].SuggestedCorrections.Count | Should Be 1 |
16 | | - $violations[$idx].SuggestedCorrections[0].Text | Should Be '' |
17 | | - Get-ExtentText $violations[$idx].SuggestedCorrections[0] $violationsFilepath | Should BeExactly ' ' |
18 | | - |
19 | | - $idx = 1 |
20 | | - $violations[$idx].SuggestedCorrections.Count | Should Be 1 |
21 | | - $violations[$idx].SuggestedCorrections[0].Text | Should Be '' |
22 | | - Get-ExtentText $violations[$idx].SuggestedCorrections[0] $violationsFilepath | Should BeExactly ' ' |
23 | | - |
24 | | - $idx = 2 |
25 | | - $violations[$idx].SuggestedCorrections.Count | Should Be 1 |
26 | | - $violations[$idx].SuggestedCorrections[0].Text | Should Be '' |
27 | | - Get-ExtentText $violations[$idx].SuggestedCorrections[0] $violationsFilepath | Should BeExactly ' ' |
28 | | - |
29 | | - $idx = 3 |
30 | | - $violations[$idx].SuggestedCorrections.Count | Should Be 1 |
31 | | - $violations[$idx].SuggestedCorrections[0].Text | Should Be '' |
32 | | - Get-ExtentText $violations[$idx].SuggestedCorrections[0] $violationsFilepath | Should BeExactly ' ' |
33 | | - |
34 | | - $idx = 4 |
35 | | - $violations[$idx].SuggestedCorrections.Count | Should Be 1 |
36 | | - $violations[$idx].SuggestedCorrections[0].Text | Should Be '' |
37 | | - Get-ExtentText $violations[$idx].SuggestedCorrections[0] $violationsFilepath | Should BeExactly ' ' |
38 | | - |
39 | 12 | } |
| 13 | + |
| 14 | + It "suggests correction" { |
| 15 | + Import-Module .\PSScriptAnalyzerTestHelper.psm1 |
| 16 | + Test-CorrectionExtent $violationFilepath $violations[0] 1 ' ' '' |
| 17 | + Test-CorrectionExtent $violationFilepath $violations[1] 1 ' ' '' |
| 18 | + Test-CorrectionExtent $violationFilepath $violations[2] 1 ' ' '' |
| 19 | + Test-CorrectionExtent $violationFilepath $violations[3] 1 ' ' '' |
| 20 | + Test-CorrectionExtent $violationFilepath $violations[4] 1 ' ' '' |
| 21 | + } |
40 | 22 | } |
41 | 23 |
|
42 | 24 | Context "When there are no violations" { |
|
0 commit comments