Skip to content

Commit 688a881

Browse files
author
Kapil Borle
committed
Add tests for UseWhitespace rule
1 parent 1b80017 commit 688a881

1 file changed

Lines changed: 80 additions & 3 deletions

File tree

Lines changed: 80 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,86 @@
11
Import-Module PSScriptAnalyzer
2-
$ruleName = "UseWhitespace"
2+
$ruleName = "PSUseWhitespace"
3+
$ruleConfiguration = @{
4+
Enable = $true
5+
CheckOpenBrace = $true
6+
}
7+
8+
$settings = @{
9+
IncludeRules = @($ruleName)
10+
Rules = @{
11+
PSUseWhitespace = $ruleConfiguration
12+
}
13+
}
314

415
Describe "UseWhitespace" {
5-
Context "" {
6-
It "" {
16+
Context "When no whitespace is present before if block open brace" {
17+
BeforeAll {
18+
$def = @'
19+
if ($true){}
20+
'@
21+
$violations = Invoke-ScriptAnalyzer -ScriptDefinition $def -Settings $settings
22+
}
23+
24+
It "Should find a violation" {
25+
$violations.Count | Should Be 1
26+
}
27+
}
28+
29+
Context "When no whitespace is present before open paren of an if block" {
30+
BeforeAll {
31+
$def = @'
32+
if($true) {}
33+
'@
34+
$violations = Invoke-ScriptAnalyzer -ScriptDefinition $def -Settings $settings
35+
}
36+
37+
It "Should find a violation" {
38+
$violations.Count | Should Be 1
39+
}
40+
}
41+
42+
Context "When no whitespace is present before open paren of a function definition" {
43+
BeforeAll {
44+
$def = @'
45+
function foo($param1) {
46+
47+
}
48+
'@
49+
$violations = Invoke-ScriptAnalyzer -ScriptDefinition $def -Settings $settings
50+
}
51+
52+
It "Should not find a violation" {
53+
$violations.Count | Should Be 0
54+
}
55+
}
56+
57+
Context "When no whitespace is present before open of a param block" {
58+
BeforeAll {
59+
$def = @'
60+
function foo() {
61+
param( )
62+
}
63+
'@
64+
$violations = Invoke-ScriptAnalyzer -ScriptDefinition $def -Settings $settings
65+
}
66+
67+
It "Should not find a violation" {
68+
$violations.Count | Should Be 0
69+
}
70+
}
71+
72+
Context "When no whitespace is present in a nested open paren" {
73+
BeforeAll {
74+
$def = @'
75+
function foo($param) {
76+
((Get-Process))
77+
}
78+
'@
79+
$violations = Invoke-ScriptAnalyzer -ScriptDefinition $def -Settings $settings
80+
}
81+
82+
It "Should not find a violation" {
83+
$violations.Count | Should Be 0
784
}
885
}
986
}

0 commit comments

Comments
 (0)