Skip to content

Commit e545d5b

Browse files
author
Kapil Borle
committed
Add tests for tabbed indentation
1 parent ffa9006 commit e545d5b

File tree

1 file changed

+44
-9
lines changed

1 file changed

+44
-9
lines changed

Tests/Rules/UseConsistentIndentation.tests.ps1

Lines changed: 44 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,19 @@ Import-Module (Join-Path $testRootDirectory "PSScriptAnalyzerTestHelper.psm1")
66

77
$indentationUnit = ' '
88
$indentationSize = 4
9+
$ruleConfiguration = @{
10+
Enable = $true
11+
InsertSpaces = $true
12+
IndentationSize = 4
13+
}
14+
915
$settings = @{
1016
IncludeRules = @("PSUseConsistentIndentation")
11-
Rules = @{
12-
PSUseConsistentIndentation = @{
13-
Enable = $true
14-
IndentationSize = 4
15-
}
17+
Rules = @{
18+
PSUseConsistentIndentation = $ruleConfiguration
1619
}
1720
}
1821

19-
2022
Describe "UseConsistentIndentation" {
2123
Context "When top level indentation is not consistent" {
2224
BeforeAll {
@@ -159,13 +161,46 @@ $x = "this " + `
159161
$violations = Invoke-ScriptAnalyzer -ScriptDefinition $def -Settings $settings
160162
$violations.Count | Should Be 1
161163
$params = @{
162-
RawContent = $def
164+
RawContent = $def
163165
DiagnosticRecord = $violations[0]
164166
CorrectionsCount = 1
165-
ViolationText = "`"Should be indented properly`""
166-
CorrectionText = (New-Object -TypeName String -ArgumentList $indentationUnit,$indentationSize) + "`"Should be indented properly`""
167+
ViolationText = "`"Should be indented properly`""
168+
CorrectionText = (New-Object -TypeName String -ArgumentList $indentationUnit, $indentationSize) + "`"Should be indented properly`""
167169
}
168170
Test-CorrectionExtentFromContent @params
169171
}
170172
}
173+
174+
Context "When tabs instead of spaces are used for indentation" {
175+
BeforeAll {
176+
$ruleConfiguration.'InsertSpaces' = $false
177+
}
178+
179+
It "Should indent using tabs" {
180+
$def = @'
181+
function foo
182+
{
183+
get-childitem
184+
$x=1+2
185+
$hashtable = @{
186+
property1 = "value"
187+
anotherProperty = "another value"
188+
}
189+
}
190+
'@
191+
${t} = "`t"
192+
$expected = @"
193+
function foo
194+
{
195+
${t}get-childitem
196+
${t}`$x=1+2
197+
${t}`$hashtable = @{
198+
${t}${t}property1 = "value"
199+
${t}${t}anotherProperty = "another value"
200+
${t}}
201+
}
202+
"@
203+
Invoke-Formatter -ScriptDefinition $def -Settings $settings | Should Be $expected
204+
}
205+
}
171206
}

0 commit comments

Comments
 (0)