Skip to content

Commit 5832be4

Browse files
committed
Add more tests
1 parent 5e71bf3 commit 5832be4

File tree

1 file changed

+40
-1
lines changed

1 file changed

+40
-1
lines changed

Tests/Rules/UseSingularNounsReservedVerbs.tests.ps1

+40-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) Microsoft Corporation. All rights reserved.
1+
# Copyright (c) Microsoft Corporation. All rights reserved.
22
# Licensed under the MIT License.
33

44
BeforeAll {
@@ -51,6 +51,45 @@ Write-Output "Adding some data"
5151
$nounNoViolations.Count | Should -Be 0
5252
}
5353
}
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+
}
5493
}
5594

5695
Describe "UseApprovedVerbs" {

0 commit comments

Comments
 (0)