Skip to content

Commit dca518b

Browse files
author
Kapil Borle
committed
Update UseWhitespace rule test cases
1 parent 00dd0c4 commit dca518b

File tree

1 file changed

+25
-17
lines changed

1 file changed

+25
-17
lines changed

Tests/Rules/UseWhitespace.tests.ps1

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,15 @@ Describe "UseWhitespace" {
2424
}
2525

2626
It "Should find a violation if an open brace does not follow whitespace" {
27-
$def = @'
27+
$def = @'
2828
if ($true){}
2929
'@
3030
$violations = Invoke-ScriptAnalyzer -ScriptDefinition $def -Settings $settings
3131
$violations.Count | Should Be 1
3232
}
3333

34-
It "Should find no violation if an open brace follows a whitespace" {
35-
$def = @'
34+
It "Should not find violation if an open brace follows a whitespace" {
35+
$def = @'
3636
if($true) {}
3737
'@
3838
$violations = Invoke-ScriptAnalyzer -ScriptDefinition $def -Settings $settings
@@ -49,16 +49,16 @@ if($true) {}
4949
$ruleConfiguration.CheckOperator = $false
5050
}
5151

52-
It "Should find no violation if an open brace follows a whitespace" {
53-
$def = @'
52+
It "Should find violation in an if statement" {
53+
$def = @'
5454
if($true) {}
5555
'@
5656
$violations = Invoke-ScriptAnalyzer -ScriptDefinition $def -Settings $settings
5757
$violations.Count | Should Be 1
5858
}
5959

60-
It "Should not find a violation if no whitespace is present before open paren of a function definition" {
61-
$def = @'
60+
It "Should not find a violation in a function definition" {
61+
$def = @'
6262
function foo($param1) {
6363
6464
}
@@ -67,8 +67,8 @@ function foo($param1) {
6767
$violations.Count | Should Be 0
6868
}
6969

70-
It "Should not find a violation if no whitespace is present before open paren of a param block" {
71-
$def = @'
70+
It "Should not find a violation in a param block" {
71+
$def = @'
7272
function foo() {
7373
param( )
7474
}
@@ -77,11 +77,19 @@ function foo() {
7777
$violations.Count | Should Be 0
7878
}
7979

80-
It "Should not find a violation if no whitespace is present in a nested open paren" {
81-
$def = @'
80+
It "Should not find a violation in a nested open paren" {
81+
$def = @'
8282
function foo($param) {
8383
((Get-Process))
8484
}
85+
'@
86+
$violations = Invoke-ScriptAnalyzer -ScriptDefinition $def -Settings $settings
87+
$violations.Count | Should Be 0
88+
}
89+
90+
It "Should not find a violation on a method call" {
91+
$def = @'
92+
$x.foo("bar")
8593
'@
8694
$violations = Invoke-ScriptAnalyzer -ScriptDefinition $def -Settings $settings
8795
$violations.Count | Should Be 0
@@ -96,39 +104,39 @@ function foo($param) {
96104
}
97105

98106
It "Should find a violation if no whitespace around an assignment operator" {
99-
$def = @'
107+
$def = @'
100108
$x=1
101109
'@
102110
$violations = Invoke-ScriptAnalyzer -ScriptDefinition $def -Settings $settings
103111
$violations.Count | Should Be 1
104112
}
105113

106114
It "Should find a violation if no whitespace before an assignment operator" {
107-
$def = @'
115+
$def = @'
108116
$x= 1
109117
'@
110118
$violations = Invoke-ScriptAnalyzer -ScriptDefinition $def -Settings $settings
111119
$violations.Count | Should Be 1
112120
}
113121

114122
It "Should find a violation if no whitespace after an assignment operator" {
115-
$def = @'
123+
$def = @'
116124
$x =1
117125
'@
118126
$violations = Invoke-ScriptAnalyzer -ScriptDefinition $def -Settings $settings
119127
$violations.Count | Should Be 1
120128
}
121129

122130
It "Should find a violation if there is a whitespaces not of size 1 around an assignment operator" {
123-
$def = @'
131+
$def = @'
124132
$x = 1
125133
'@
126134
$violations = Invoke-ScriptAnalyzer -ScriptDefinition $def -Settings $settings
127135
$violations.Count | Should Be 1
128136
}
129137

130-
It "Should find no violation if there are whitespaces of size 1 around an assignment operator" {
131-
$def = @'
138+
It "Should not find violation if there are whitespaces of size 1 around an assignment operator" {
139+
$def = @'
132140
$x = 1
133141
'@
134142
$violations = Invoke-ScriptAnalyzer -ScriptDefinition $def -Settings $settings

0 commit comments

Comments
 (0)