|
1 | | -# Copyright (c) Microsoft Corporation. All rights reserved. |
| 1 | +# Copyright (c) Microsoft Corporation. All rights reserved. |
2 | 2 | # Licensed under the MIT License. |
3 | 3 |
|
4 | 4 | BeforeAll { |
@@ -283,6 +283,57 @@ Write-Output ` |
283 | 283 | Invoke-Formatter -ScriptDefinition $scriptDefinition -Settings $settings | |
284 | 284 | Should -Be $scriptDefinition |
285 | 285 | } |
| 286 | + |
| 287 | + It 'Should preserve a comment run containing an internal line continuation with <Kind> indentation' -TestCases @( |
| 288 | + @{ Kind = 'space'; Indentation = ' ' } |
| 289 | + @{ Kind = 'tab'; Indentation = "`t" } |
| 290 | + ) { |
| 291 | + param([string] $Kind, [string] $Indentation) |
| 292 | + $scriptDefinition = @( |
| 293 | + '<# first #> `' |
| 294 | + "$Indentation<# second #>" |
| 295 | + "Write-Output 'after'" |
| 296 | + ) -join "`n" |
| 297 | + $settings.Rules.PSUseConsistentIndentation.Kind = $Kind |
| 298 | + |
| 299 | + $violations = Invoke-ScriptAnalyzer -ScriptDefinition $scriptDefinition -Settings $settings |
| 300 | + $violations.Count | Should -Be 0 |
| 301 | + $formatted = Invoke-Formatter -ScriptDefinition $scriptDefinition -Settings $settings |
| 302 | + $formatted | Should -Be $scriptDefinition |
| 303 | + Invoke-Formatter -ScriptDefinition $formatted -Settings $settings | |
| 304 | + Should -Be $formatted |
| 305 | + } |
| 306 | + |
| 307 | + It 'Should shift a comment run containing an internal line continuation uniformly with <Kind> indentation' -TestCases @( |
| 308 | + @{ Kind = 'space'; Indentation = ' ' } |
| 309 | + @{ Kind = 'tab'; Indentation = "`t" } |
| 310 | + ) { |
| 311 | + param([string] $Kind, [string] $Indentation) |
| 312 | + $scriptDefinition = @( |
| 313 | + 'if ($a) {' |
| 314 | + '<# first #> `' |
| 315 | + "$Indentation<# second #>" |
| 316 | + "$($Indentation)Write-Output 'after'" |
| 317 | + '}' |
| 318 | + ) -join "`n" |
| 319 | + $expectedScriptDefinition = @( |
| 320 | + 'if ($a) {' |
| 321 | + "$Indentation<# first #> ``" |
| 322 | + "$Indentation$Indentation<# second #>" |
| 323 | + "$($Indentation)Write-Output 'after'" |
| 324 | + '}' |
| 325 | + ) -join "`n" |
| 326 | + $settings.Rules.PSUseConsistentIndentation.Kind = $Kind |
| 327 | + |
| 328 | + $violations = Invoke-ScriptAnalyzer -ScriptDefinition $scriptDefinition -Settings $settings |
| 329 | + $violations.Count | Should -Be 2 |
| 330 | + $formatted = Invoke-Formatter -ScriptDefinition $scriptDefinition -Settings $settings |
| 331 | + $formatted | Should -Be $expectedScriptDefinition |
| 332 | + Invoke-Formatter -ScriptDefinition $formatted -Settings $settings | |
| 333 | + Should -Be $formatted |
| 334 | + $violations = Invoke-ScriptAnalyzer -ScriptDefinition $formatted -Settings $settings |
| 335 | + $violations.Count | Should -Be 0 |
| 336 | + } |
286 | 337 | } |
287 | 338 |
|
288 | 339 | Context "When a multi-line command is given" { |
|
0 commit comments