Skip to content

Commit 2ef5b54

Browse files
author
Kapil Borle
committed
Add tests for indentation in multi-line pipeline
1 parent 511ee68 commit 2ef5b54

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

Tests/Rules/UseConsistentIndentation.tests.ps1

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,4 +113,35 @@ function foo {
113113
$violations.Count | Should Be 0
114114
}
115115
}
116+
117+
Context "When a multi-line command is given" {
118+
It "Should find a violation if a pipleline element is not indented correctly" {
119+
$def = @'
120+
get-process |
121+
where-object {$_.Name -match 'powershell'}
122+
'@
123+
$violations = Invoke-ScriptAnalyzer -ScriptDefinition $def -Settings $settings
124+
$violations.Count | Should Be 1
125+
}
126+
127+
It "Should ignore comment in the pipleline" {
128+
$def = @'
129+
get-process |
130+
where-object Name -match 'powershell' | # only this is indented correctly
131+
select Name,Id |
132+
format-list
133+
'@
134+
$violations = Invoke-ScriptAnalyzer -ScriptDefinition $def -Settings $settings
135+
$violations.Count | Should Be 3
136+
}
137+
138+
It "Should not find a violation on a new line that follows a pipe" {
139+
$def = @'
140+
get-process |
141+
where-object {$_.Name -match 'powershell'}
142+
'@
143+
$violations = Invoke-ScriptAnalyzer -ScriptDefinition $def -Settings $settings
144+
$violations.Count | Should Be 0
145+
}
146+
}
116147
}

0 commit comments

Comments
 (0)