Skip to content

Commit 8954204

Browse files
author
Kapil Borle
committed
Add tests for uncuddled branch statements
1 parent 7e85ccc commit 8954204

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

Tests/Rules/PlaceCloseBrace.tests.ps1

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,4 +199,59 @@ Some-Command -Param1 @{
199199
$violations.Count | Should Be 0
200200
}
201201
}
202+
203+
Context "When a close brace should be followed by a new line" {
204+
BeforeAll {
205+
$ruleConfiguration.'NoEmptyLineBefore' = $false
206+
$ruleConfiguration.'IgnoreOneLineBlock' = $false
207+
$ruleConfiguration.'NewLineAfter' = $false
208+
}
209+
210+
It "Should find a violation if a branching statement is on a new line if open brance is on same line" {
211+
$def = @'
212+
if ($true) {
213+
$true
214+
}
215+
else {
216+
$false
217+
}
218+
'@
219+
$violations = Invoke-ScriptAnalyzer -ScriptDefinition $def -Settings $settings
220+
$violations.Count | Should Be 1
221+
}
222+
223+
It "Should not find a violation if a branching statement is on a new line if open brance is not on same line" {
224+
$def = @'
225+
if ($true)
226+
{
227+
$true
228+
}
229+
else
230+
{
231+
$false
232+
}
233+
'@
234+
$violations = Invoke-ScriptAnalyzer -ScriptDefinition $def -Settings $settings
235+
$violations.Count | Should Be 0
236+
}
237+
238+
It "Should correct violation by cuddling the else branch statement" {
239+
$def = @'
240+
if ($true) {
241+
$true
242+
}
243+
else {
244+
$false
245+
}
246+
'@
247+
$expected = @'
248+
if ($true) {
249+
$true
250+
} else {
251+
$false
252+
}
253+
'@
254+
Invoke-Formatter -ScriptDefinition $def -Settings $settings | Should Be $expected
255+
}
256+
}
202257
}

0 commit comments

Comments
 (0)