Skip to content

Commit 2d2f716

Browse files
author
Kapil Borle
committed
Test open brace in a one line if-else statement
1 parent 1329e30 commit 2d2f716

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

Tests/Rules/PlaceOpenBrace.tests.ps1

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ $ruleConfiguration = @{
33
Enable = $true
44
OnSameLine = $true
55
NewLineAfter = $true
6+
IgnoreOneLineIf = $true
67
}
78

89
$settings = @{
@@ -42,7 +43,7 @@ function foo ($param1) {
4243
}
4344
'@
4445
$ruleConfiguration.'OnSameLine' = $false
45-
$ruleConfiguration.'NewLineAfter' = $true
46+
$ruleConfiguration.'NewLineAfter' = $true
4647
$violations = Invoke-ScriptAnalyzer -ScriptDefinition $def -Settings $settings
4748
$defShouldIgnore = @'
4849
Get-Process | % { "blah" }
@@ -61,6 +62,15 @@ Get-Process | % { "blah" }
6162
It "Should ignore violations for a command element" {
6263
$violationsShouldIgnore.Count | Should Be 0
6364
}
65+
66+
It "Should ignore violations for one line if statement" {
67+
$def = @'
68+
$x = if ($true) { "blah" } else { "blah blah" }
69+
'@
70+
$ruleConfiguration.'IgnoreOneLineIf' = $true
71+
$violations = Invoke-ScriptAnalyzer -ScriptDefinition $def -Settings $settings
72+
$violations.Count | Should Be 0
73+
}
6474
}
6575

6676
Context "When a new line should follow an open brace" {

0 commit comments

Comments
 (0)