Skip to content

Commit da625d9

Browse files
committed
Added Tests for the new Rule; Fixed minor bugs in the rule
1 parent 0d5d993 commit da625d9

7 files changed

+47
-6
lines changed

Rules/Strings.Designer.cs

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Rules/Strings.resx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -745,13 +745,13 @@
745745
<value>UseUTF8EncodingForHelpFile</value>
746746
</data>
747747
<data name="UseBOMForUnicodeEncodedFileCommonName" xml:space="preserve">
748-
<value>test</value>
748+
<value>Use BOM encoding for non-ASCII files</value>
749749
</data>
750750
<data name="UseBOMForUnicodeEncodedFileDescription" xml:space="preserve">
751-
<value>test</value>
751+
<value>For a file encoded with a format other than ASCII, ensure BOM is present to ensure that any application consuming this file can interpret it correctly.</value>
752752
</data>
753753
<data name="UseBOMForUnicodeEncodedFileError" xml:space="preserve">
754-
<value>test</value>
754+
<value>Missing BOM encoding for non-ASCII encoded file '{0}'</value>
755755
</data>
756756
<data name="UseBOMForUnicodeEncodedFileName" xml:space="preserve">
757757
<value>UseBOMForUnicodeEncodedFile</value>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Test Script
Binary file not shown.
Binary file not shown.
Binary file not shown.
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
Import-Module PSScriptAnalyzer
2+
$violationMessageOne = "Missing BOM encoding for non-ASCII encoded file 'BOMAbsent_UTF16EncodedScript.ps1'"
3+
$violationMessageTwo = "Missing BOM encoding for non-ASCII encoded file 'BOMAbsent_UnknownEncodedScript.ps1'"
4+
$violationName = "PSUseBOMForUnicodeEncodedFile"
5+
$directory = Split-Path -Parent $MyInvocation.MyCommand.Path
6+
$violationsOne = Invoke-ScriptAnalyzer "$directory\TestFiles\BOMAbsent_UTF16EncodedScript.ps1" | Where-Object {$_.RuleName -eq $violationName}
7+
$violationsTwo = Invoke-ScriptAnalyzer "$directory\TestFiles\BOMAbsent_UnknownEncodedScript.ps1" | Where-Object {$_.RuleName -eq $violationName}
8+
$noViolationsOne = Invoke-ScriptAnalyzer "$directory\TestFiles\BOMPresent_UTF16EncodedScript.ps1" | Where-Object {$_.RuleName -eq $violationName}
9+
$noViolationsTwo = Invoke-ScriptAnalyzer "$directory\TestFiles\BOMAbsent_ASCIIEncodedScript.ps1" | Where-Object {$_.RuleName -eq $violationName}
10+
11+
Describe "UseBOMForUnicodeEncodedFile" {
12+
Context "When there are violations" {
13+
It "has 1 rule violation for BOM Absent - UTF16 Encoded file" {
14+
$violationsOne.Count | Should Be 1
15+
}
16+
17+
It "has the correct description message for BOM Absent - UTF16 Encoded file" {
18+
$violationsOne[0].Message | Should Match $violationMessageOne
19+
}
20+
21+
It "has 1 rule violation for BOM Absent - Unknown Encoded file" {
22+
$violationsTwo.Count | Should Be 1
23+
}
24+
25+
It "has the correct description message for BOM Absent - Unknown Encoded file" {
26+
$violationsTwo[0].Message | Should Match $violationMessageTwo
27+
}
28+
29+
}
30+
31+
Context "When there are no violations" {
32+
It "returns no violations for BOM Present - UTF16 Encoded File" {
33+
$noViolationsOne.Count | Should Be 0
34+
}
35+
36+
It "returns no violations for BOM Absent - ASCII Encoded File" {
37+
$noViolationsTwo.Count | Should Be 0
38+
}
39+
}
40+
}

0 commit comments

Comments
 (0)