|
1 |
| -# Copyright (c) Microsoft Corporation. All rights reserved. |
| 1 | +# Copyright (c) Microsoft Corporation. All rights reserved. |
2 | 2 | # Licensed under the MIT License.
|
3 | 3 |
|
4 | 4 | BeforeAll {
|
@@ -51,6 +51,45 @@ Write-Output "Adding some data"
|
51 | 51 | $nounNoViolations.Count | Should -Be 0
|
52 | 52 | }
|
53 | 53 | }
|
| 54 | + |
| 55 | + Context "Inline tests" { |
| 56 | + BeforeAll { |
| 57 | + $testCases = @( |
| 58 | + @{ Script = 'function Get-Horses { "horses" }'; Extent = @{ StartCol = 10; EndCol = 20 }; Correction = 'Get-Horse' } |
| 59 | + @{ Script = 'function ConvertTo-StartingCriteria { "criteria" }'; Extent = @{ StartCol = 10; EndCol = 36 }; Correction = 'ConvertTo-StartingCriterion' } |
| 60 | + @{ Script = 'function Invoke-Data { "data" }' } |
| 61 | + @{ Script = 'function Get-Horse { "horses" }' } |
| 62 | + @{ Script = 'function get-horse { "horses" }' } |
| 63 | + @{ Script = 'function horse { "horses" }' } |
| 64 | + ) |
| 65 | + } |
| 66 | + |
| 67 | + It 'Correctly diagnoses and corrects <Script>' -TestCases $testCases { |
| 68 | + param([string]$Script, $Extent, $Correction) |
| 69 | + |
| 70 | + $diagnostics = Invoke-ScriptAnalyzer -ScriptDefinition $Script |
| 71 | + |
| 72 | + if (-not $Extent) |
| 73 | + { |
| 74 | + $diagnostics | Should -BeNullOrEmpty |
| 75 | + return |
| 76 | + } |
| 77 | + |
| 78 | + $expectedStartLine = if ($Extent.StartLine) { $Extent.StartLine } else { 1 } |
| 79 | + $expectedEndLine = if ($Extent.EndLine) { $Extent.EndLine } else { 1 } |
| 80 | + |
| 81 | + $diagnostics.Extent.StartLineNumber | Should -BeExactly $expectedStartLine |
| 82 | + $diagnostics.Extent.EndLineNumber | Should -BeExactly $expectedEndLine |
| 83 | + $diagnostics.Extent.StartColumnNumber | Should -BeExactly $Extent.StartCol |
| 84 | + $diagnostics.Extent.EndColumnNumber | Should -BeExactly $Extent.EndCol |
| 85 | + |
| 86 | + $diagnostics.SuggestedCorrections.StartLineNumber | Should -BeExactly $expectedStartLine |
| 87 | + $diagnostics.SuggestedCorrections.EndLineNumber | Should -BeExactly $expectedEndLine |
| 88 | + $diagnostics.SuggestedCorrections.StartColumnNumber | Should -BeExactly $Extent.StartCol |
| 89 | + $diagnostics.SuggestedCorrections.EndColumnNumber | Should -BeExactly $Extent.EndCol |
| 90 | + $diagnostics.SuggestedCorrections.Text | Should -BeExactly $Correction |
| 91 | + } |
| 92 | + } |
54 | 93 | }
|
55 | 94 |
|
56 | 95 | Describe "UseApprovedVerbs" {
|
|
0 commit comments