Skip to content

Commit 52ba0d0

Browse files
committed
feat(tests): added dedicated test for code formatting presets
1 parent 5e8ed23 commit 52ba0d0

File tree

1 file changed

+149
-0
lines changed

1 file changed

+149
-0
lines changed
Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
# Copyright (c) Microsoft Corporation. All rights reserved.
2+
# Licensed under the MIT License.
3+
4+
BeforeAll {
5+
$testRootDirectory = Split-Path -Parent $PSScriptRoot
6+
Import-Module (Join-Path $testRootDirectory "PSScriptAnalyzerTestHelper.psm1")
7+
8+
$Allman = @'
9+
enum Color
10+
{
11+
Black,
12+
White
13+
}
14+
15+
function Test-Code
16+
{
17+
[CmdletBinding()]
18+
param
19+
(
20+
[int] $ParameterOne
21+
)
22+
end
23+
{
24+
if (10 -gt $ParameterOne)
25+
{
26+
"Greater"
27+
}
28+
else
29+
{
30+
"Lesser"
31+
}
32+
}
33+
}
34+
'@
35+
36+
$OTBS = @'
37+
enum Color {
38+
Black,
39+
White
40+
}
41+
42+
function Test-Code {
43+
[CmdletBinding()]
44+
param(
45+
[int] $ParameterOne
46+
)
47+
end {
48+
if (10 -gt $ParameterOne) {
49+
"Greater"
50+
} else {
51+
"Lesser"
52+
}
53+
}
54+
}
55+
'@
56+
$OTPS = @'
57+
enum Color {
58+
Black,
59+
White
60+
}
61+
62+
function Test-Code {
63+
[CmdletBinding()]
64+
param(
65+
[int] $ParameterOne
66+
)
67+
end {
68+
if (10 -gt $ParameterOne) {
69+
"Greater"
70+
}
71+
else {
72+
"Lesser"
73+
}
74+
}
75+
}
76+
'@
77+
$Stroustrup = @'
78+
enum Color {
79+
Black,
80+
White
81+
}
82+
83+
function Test-Code
84+
{
85+
[CmdletBinding()]
86+
param(
87+
[int]$ParameterOne
88+
)
89+
end {
90+
if(10 -gt $ParameterOne) {
91+
"Greater"
92+
}
93+
else {
94+
"Lesser"
95+
}
96+
}
97+
}
98+
'@
99+
}
100+
101+
Describe "CodeFormattingPresets" {
102+
Context "Allman" {
103+
It "To Allman from OTBS" {
104+
Invoke-Formatter -ScriptDefinition $OTBS -Settings 'CodeFormattingAllman' | Should -Be $Allman
105+
}
106+
It "To Allman from OTPS" {
107+
Invoke-Formatter -ScriptDefinition $OTPS -Settings 'CodeFormattingAllman' | Should -Be $Allman
108+
}
109+
It "To Allman from Stroustrup" {
110+
Invoke-Formatter -ScriptDefinition $Stroustrup -Settings 'CodeFormattingAllman' | Should -Be $Allman
111+
}
112+
}
113+
114+
Context "OTBS" {
115+
It "To OTBS from Allman" {
116+
Invoke-Formatter -ScriptDefinition $Allman -Settings 'CodeFormattingOTBS' | Should -Be $OTBS
117+
}
118+
It "To OTBS from OTPS" {
119+
Invoke-Formatter -ScriptDefinition $OTPS -Settings 'CodeFormattingOTBS' | Should -Be $OTBS
120+
}
121+
It "To OTBS from Stroustrup" {
122+
Invoke-Formatter -ScriptDefinition $Stroustrup -Settings 'CodeFormattingOTBS' | Should -Be $OTBS
123+
}
124+
}
125+
126+
Context "OTPS" {
127+
It "To OTPS from Allman" {
128+
Invoke-Formatter -ScriptDefinition $Allman -Settings 'CodeFormattingOTPS' | Should -Be $OTPS
129+
}
130+
It "To OTPS from OTBS" {
131+
Invoke-Formatter -ScriptDefinition $OTBS -Settings 'CodeFormattingOTPS' | Should -Be $OTPS
132+
}
133+
It "To OTPS from Stroustrup" {
134+
Invoke-Formatter -ScriptDefinition $Stroustrup -Settings 'CodeFormattingOTPS' | Should -Be $OTPS
135+
}
136+
}
137+
138+
Context "Stroustrup" {
139+
It "To Stroustrup from Allman" {
140+
Invoke-Formatter -ScriptDefinition $Allman -Settings 'CodeFormattingStroustrup' | Should -Be $Stroustrup
141+
}
142+
It "To Stroustrup from OTBS" {
143+
Invoke-Formatter -ScriptDefinition $OTBS -Settings 'CodeFormattingStroustrup' | Should -Be $Stroustrup
144+
}
145+
It "To Stroustrup from OTPS" {
146+
Invoke-Formatter -ScriptDefinition $OTPS -Settings 'CodeFormattingStroustrup' | Should -Be $Stroustrup
147+
}
148+
}
149+
}

0 commit comments

Comments
 (0)