@@ -29,7 +29,7 @@ Describe "MoveUsingStatements" {
29
29
30
30
$TestCases = @ (
31
31
@ {
32
- TestCaseName = ' Move all using statements in `n terminated files to the top'
32
+ TestCaseName = ' Moves all using statements in `n terminated files to the top'
33
33
PSM1File = " function x {`n }`n " +
34
34
" using namespace System.IO`n`n " + # UsingMustBeAtStartOfScript
35
35
" function y {`n }`n " +
@@ -38,7 +38,7 @@ Describe "MoveUsingStatements" {
38
38
ErrorAfter = 0
39
39
},
40
40
@ {
41
- TestCaseName = ' Move all using statements in `r`n terminated files to the top'
41
+ TestCaseName = ' Moves all using statements in`r`n terminated files to the top'
42
42
PSM1File = " function x {`r`n }`r`n " +
43
43
" USING namespace System.IO`r`n`r`n " + # UsingMustBeAtStartOfScript
44
44
" function y {`r`n }`r`n " +
@@ -47,16 +47,32 @@ Describe "MoveUsingStatements" {
47
47
ErrorAfter = 0
48
48
},
49
49
@ {
50
- TestCaseName = ' Not change the content again if there are no out-of-place using statements'
50
+ TestCaseName = ' Prevents duplicate using statements'
51
+ PSM1File = " using namespace System.IO`r`n " + # UsingMustBeAtStartOfScript
52
+ " function x {`r`n }`r`n`r`n " +
53
+ " using namespace System.IO`r`n " + # UsingMustBeAtStartOfScript
54
+ " function y {`r`n }`r`n " +
55
+ " USING namespace System.IO" # UsingMustBeAtStartOfScript
56
+ ExpectedResult = " using namespace System.IO`r`n " +
57
+ " #using namespace System.IO`r`n " +
58
+ " function x {`r`n }`r`n`r`n " +
59
+ " #using namespace System.IO`r`n " +
60
+ " function y {`r`n }`r`n " +
61
+ " #USING namespace System.IO"
62
+ ErrorBefore = 2
63
+ ErrorAfter = 0
64
+ },
65
+ @ {
66
+ TestCaseName = ' Does not change the content again if there are no out-of-place using statements'
51
67
PSM1File = " using namespace System.IO`r`n`r`n " +
52
68
" using namespace System.Drawing`r`n " +
53
- " function x { `r`n }`r`n " +
54
- " function y { `r`n }`r`n "
69
+ " function x {`r`n }`r`n " +
70
+ " function y {`r`n }`r`n "
55
71
ErrorBefore = 0
56
72
ErrorAfter = 0
57
73
},
58
74
@ {
59
- TestCaseName = ' Move using statements even if types are used'
75
+ TestCaseName = ' Moves using statements even if types are used'
60
76
PSM1File = " function x {`r`n }`r`n " +
61
77
" using namespace System.IO`r`n`r`n " + # UsingMustBeAtStartOfScript
62
78
" function y {`r`n }`r`n " +
@@ -66,18 +82,18 @@ Describe "MoveUsingStatements" {
66
82
ErrorAfter = 0
67
83
},
68
84
@ {
69
- TestCaseName = ' Move using statements even when there are (other) parse errors'
85
+ TestCaseName = ' Moves using statements even when there are (other) parse errors'
70
86
PSM1File = " using namespace System.IO`r`n`r`n " +
71
- " function x { `r`n }`r`n " +
87
+ " function x {`r`n }`r`n " +
72
88
" using namespace System.Drawing`r`n " + # UsingMustBeAtStartOfScript
73
- " function y { `r`n }`r`n }" # Extra } at the end
89
+ " function y {`r`n }`r`n }" # Extra } at the end
74
90
ErrorBefore = 2
75
91
ErrorAfter = 1
76
92
}
77
93
)
78
94
79
- It ' It should <TestCaseName>' - TestCases $TestCases {
80
- param ($TestCaseName , $PSM1File , $ErrorBefore , $ErrorAfter )
95
+ It ' <TestCaseName>' - TestCases $TestCases {
96
+ param ($TestCaseName , $PSM1File , $ErrorBefore , $ErrorAfter , $ExpectedResult )
81
97
82
98
$testModuleFile = " $TestDrive /MyModule.psm1"
83
99
Set-Content $testModuleFile - value $PSM1File - Encoding UTF8
@@ -99,6 +115,10 @@ Describe "MoveUsingStatements" {
99
115
[ref ]$ErrorFound
100
116
)
101
117
$ErrorFound.Count | Should - Be $ErrorAfter
118
+ if ($ExpectedResult ) {
119
+ $ActualResult = Get-Content $testModuleFile - Raw
120
+ $ActualResult.Trim () | Should - Be $ExpectedResult - Because " there should be no duplicate using statements in:`n $ActualResult "
121
+ }
102
122
}
103
123
}
104
124
0 commit comments