Skip to content

Commit acafe85

Browse files
author
Kapil Borle
committed
Add tests for NewLineAfter behavior
1 parent dba6ce7 commit acafe85

File tree

1 file changed

+41
-8
lines changed

1 file changed

+41
-8
lines changed

Tests/Rules/PlaceCloseBrace.tests.ps1

Lines changed: 41 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -122,21 +122,21 @@ $x = if ($true) { "blah" } else { "blah blah" }
122122

123123
Context "When a close brace should be follow a new line" {
124124
BeforeAll {
125+
$ruleConfiguration.'NoEmptyLineBefore' = $false
126+
$ruleConfiguration.'IgnoreOneLineBlock' = $false
127+
$ruleConfiguration.'NewLineAfter' = $true
128+
}
129+
130+
It "Should find a violation for a close brace followed by else" {
125131
$def = @'
126132
if (Test-Path "blah") {
127133
"blah"
128134
} else {
129135
"blah blah"
130136
}
131137
'@
132-
$ruleConfiguration.'NoEmptyLineBefore' = $false
133-
$ruleConfiguration.'IgnoreOneLineBlock' = $false
134-
$ruleConfiguration.'NewLineAfter' = $true
135138
$violations = Invoke-ScriptAnalyzer -ScriptDefinition $def -Settings $settings
136-
}
137-
138-
It "Should find two violations" {
139-
$violations.Count | Should Be 2
139+
$violations.Count | Should Be 1
140140
$params = @{
141141
RawContent = $def
142142
DiagnosticRecord = $violations[0]
@@ -145,15 +145,48 @@ if (Test-Path "blah") {
145145
CorrectionText = '}' + [System.Environment]::NewLine
146146
}
147147
Test-CorrectionExtentFromContent @params
148+
}
148149

150+
It "Should find a violation for a close brace followed by elseif" {
151+
$def = @'
152+
if (Test-Path "blah") {
153+
"blah"
154+
} elseif (Test-Path "blah blah") {
155+
"blah blah"
156+
}
157+
'@
158+
$violations = Invoke-ScriptAnalyzer -ScriptDefinition $def -Settings $settings
159+
$violations.Count | Should Be 1
149160
$params = @{
150161
RawContent = $def
151-
DiagnosticRecord = $violations[1]
162+
DiagnosticRecord = $violations[0]
152163
CorrectionsCount = 1
153164
ViolationText = '}'
154165
CorrectionText = '}' + [System.Environment]::NewLine
155166
}
156167
Test-CorrectionExtentFromContent @params
157168
}
169+
170+
It "Should not find a violation for a close brace followed by a comma in an array expression" {
171+
$def = @'
172+
Some-Command -Param1 @{
173+
key1="value1"
174+
},@{
175+
key2="value2"
176+
}
177+
'@
178+
$violations = Invoke-ScriptAnalyzer -ScriptDefinition $def -Settings $settings
179+
$violations.Count | Should Be 0
180+
}
181+
182+
It "Should not find a violation for a close brace followed by parameter in a command expression" {
183+
$def = @'
184+
Some-Command -Param1 @{
185+
key="value"
186+
} -Param2
187+
'@
188+
$violations = Invoke-ScriptAnalyzer -ScriptDefinition $def -Settings $settings
189+
$violations.Count | Should Be 0
190+
}
158191
}
159192
}

0 commit comments

Comments
 (0)