From 06c7c722e970fb73b1fe2141fc0bd8fbc2ca369e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olav=20R=C3=B8nnestad=20Birkeland?= <6450056+o-l-a-v@users.noreply.github.com> Date: Sat, 7 Mar 2026 13:36:32 +0100 Subject: [PATCH 1/2] feat(tests): added closing bracket test for formatting presets --- Tests/Rules/PlaceCloseBrace.tests.ps1 | 45 +++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/Tests/Rules/PlaceCloseBrace.tests.ps1 b/Tests/Rules/PlaceCloseBrace.tests.ps1 index 85ccb8979..0d256e9f4 100644 --- a/Tests/Rules/PlaceCloseBrace.tests.ps1 +++ b/Tests/Rules/PlaceCloseBrace.tests.ps1 @@ -383,4 +383,49 @@ if ($true) { $violations.Count | Should -Be 0 } } + + Context "When formatting presets handles if else" { + BeforeAll { + $AllmanDefinition = @" +if (`$true) +{ + 'yes' +} +else +{ + 'no' +} +"@ + $OTBSDefinition = @" +if (`$true) { + 'yes' +} else { + 'no' +} +"@ + $StroustrupDefinition = @" +if (`$true) { + 'yes' +} +else { + 'no' +} +"@ + } + + It "Allman should have all opening and closing braces on a new line" { + Invoke-Formatter -ScriptDefinition $OTBSDefinition -Settings 'CodeFormattingAllman' | Should -Be $AllmanDefinition + Invoke-Formatter -ScriptDefinition $StroustrupDefinition -Settings 'CodeFormattingAllman' | Should -Be $AllmanDefinition + } + + It "OTBS should place else on same line as the if closing bracket" { + Invoke-Formatter -ScriptDefinition $AllmanDefinition -Settings 'CodeFormattingOTBS' | Should -Be $OTBSDefinition + Invoke-Formatter -ScriptDefinition $StroustrupDefinition -Settings 'CodeFormattingOTBS' | Should -Be $OTBSDefinition + } + + It "Stroustrup should place else on a new line after the if closing bracket" { + Invoke-Formatter -ScriptDefinition $AllmanDefinition -Settings 'CodeFormattingStroustrup' | Should -Be $StroustrupDefinition + Invoke-Formatter -ScriptDefinition $OTBSDefinition -Settings 'CodeFormattingStroustrup' | Should -Be $StroustrupDefinition + } + } } From 6d09139cdd1b6fc2763b3823f90d557c669e44ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olav=20R=C3=B8nnestad=20Birkeland?= <6450056+o-l-a-v@users.noreply.github.com> Date: Sat, 7 Mar 2026 13:47:16 +0100 Subject: [PATCH 2/2] Update Tests/Rules/PlaceCloseBrace.tests.ps1 Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- Tests/Rules/PlaceCloseBrace.tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/Rules/PlaceCloseBrace.tests.ps1 b/Tests/Rules/PlaceCloseBrace.tests.ps1 index 0d256e9f4..fb741ee2a 100644 --- a/Tests/Rules/PlaceCloseBrace.tests.ps1 +++ b/Tests/Rules/PlaceCloseBrace.tests.ps1 @@ -384,7 +384,7 @@ if ($true) { } } - Context "When formatting presets handles if else" { + Context "When formatting presets handle if/else" { BeforeAll { $AllmanDefinition = @" if (`$true)