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