Skip to content

Commit d56ca93

Browse files
committed
Add tests for diagnostic messages related to casing of functions, parameters, and operators
1 parent b382add commit d56ca93

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

Tests/Rules/UseCorrectCasing.tests.ps1

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,27 @@ Describe "UseCorrectCasing" {
103103
Should -BeExactly '$A++; $B--'
104104
}
105105

106+
It "Shows relevant diagnostic message for function/command name casing" {
107+
$settings = @{ 'Rules' = @{ 'PSUseCorrectCasing' = @{ 'Enable' = $true; CheckCommands = $true; CheckKeywords = $true; CheckOperators = $true } } }
108+
$violations = Invoke-ScriptAnalyzer -ScriptDefinition 'WHERE-OBJECT Name -EQ "Value"' -Settings $settings
109+
$violations.Count | Should -Be 1
110+
$violations[0].Message | Should -Be "Function/Cmdlet 'WHERE-OBJECT' does not match its exact casing 'Where-Object'."
111+
}
112+
113+
It "Shows relevant diagnostic message for parameter casing" {
114+
$settings = @{ 'Rules' = @{ 'PSUseCorrectCasing' = @{ 'Enable' = $true; CheckCommands = $true; CheckKeywords = $true; CheckOperators = $true } } }
115+
$violations = Invoke-ScriptAnalyzer -ScriptDefinition 'Where-Object Name -eq "Value"' -Settings $settings
116+
$violations.Count | Should -Be 1
117+
$violations[0].Message | Should -Be "Parameter '-eq' of function/cmdlet 'Where-Object' does not match its exact casing 'EQ'."
118+
}
119+
120+
It "Shows relevant diagnostic message for operator casing" {
121+
$settings = @{ 'Rules' = @{ 'PSUseCorrectCasing' = @{ 'Enable' = $true; CheckCommands = $true; CheckKeywords = $true; CheckOperators = $true } } }
122+
$violations = Invoke-ScriptAnalyzer -ScriptDefinition '$a -EQ 1' -Settings $settings
123+
$violations.Count | Should -Be 1
124+
$violations[0].Message | Should -Be "Operator '-EQ' does not match the expected case '-eq'."
125+
}
126+
106127
Context "Inconsistent Keywords" {
107128
It "Corrects keyword case" {
108129
Invoke-Formatter 'ForEach ($x IN $y) { $x }' |

0 commit comments

Comments
 (0)