-
Notifications
You must be signed in to change notification settings - Fork 408
Expand file tree
/
Copy pathAvoidExclaimOperator.tests.ps1
More file actions
54 lines (49 loc) · 1.82 KB
/
AvoidExclaimOperator.tests.ps1
File metadata and controls
54 lines (49 loc) · 1.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
BeforeAll {
$ruleName = "PSAvoidExclaimOperator"
$ruleSettings = @{
Enable = $true
}
$settings = @{
IncludeRules = @($ruleName)
Rules = @{ $ruleName = $ruleSettings }
}
}
Describe "AvoidExclaimOperator" {
Context "When the rule is not enabled explicitly" {
It "Should not find violations" {
$def = '!$true'
$violations = Invoke-ScriptAnalyzer -ScriptDefinition $def
$violations.Count | Should -Be 0
}
}
Context "Given a line with the exclaim operator" {
It "Should find one violation" {
$def = '!$true'
$violations = Invoke-ScriptAnalyzer -ScriptDefinition $def -Settings $settings
$violations.Count | Should -Be 1
}
}
Context "Given a line with the exclaim operator" {
It "Should replace the exclaim operator with the -not operator" {
$def = '!$true'
$expected = '-not $true'
Invoke-Formatter -ScriptDefinition $def -Settings $settings | Should -Be $expected
}
}
Context "Given a line with the exlaim operator followed by a space" {
It "Should replace the exclaim operator without adding an additional space" {
$def = '! $true'
$expected = '-not $true'
Invoke-Formatter -ScriptDefinition $def -Settings $settings | Should -Be $expected
}
}
Context "Given a line with a string containing an exclamation point" {
It "Should not replace it" {
$def = '$MyVar = "Should not replace!"'
$expected = '$MyVar = "Should not replace!"'
Invoke-Formatter -ScriptDefinition $def -Settings $settings | Should -Be $expected
}
}
}