FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

feat(tests): added closing bracket test for formatting presets by o-l-a-v · Pull Request #2161 · PowerShell/PSScriptAnalyzer · GitHub

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .ps1  (1) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
45 changes: 45 additions & 0 deletions Tests/Rules/PlaceCloseBrace.tests.ps1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -383,4 +383,49 @@ if ($true) {
$violations.Count | Should -Be 0
}
}

Context "When formatting presets handle if/else" {
BeforeAll {
$AllmanDefinition = @"
if (`$true)
{
'yes'
}
else
{
'no'
}
"@
$OTBSDefinition = @"
if (`$true) {
'yes'
} else {
'no'
}
"@
$StroustrupDefinition = @"
if (`$true) {
'yes'
}
else {
'no'
}
"@
Comment thread
o-l-a-v marked this conversation as resolved.
}

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
}
}
}

Back | FazBrowse Home | New Git URL