@@ -29,7 +29,7 @@ Describe "MoveUsingStatements" {
2929
3030 $TestCases = @ (
3131 @ {
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'
3333 PSM1File = " function x {`n }`n " +
3434 " using namespace System.IO`n`n " + # UsingMustBeAtStartOfScript
3535 " function y {`n }`n " +
@@ -38,7 +38,7 @@ Describe "MoveUsingStatements" {
3838 ErrorAfter = 0
3939 },
4040 @ {
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'
4242 PSM1File = " function x {`r`n }`r`n " +
4343 " USING namespace System.IO`r`n`r`n " + # UsingMustBeAtStartOfScript
4444 " function y {`r`n }`r`n " +
@@ -47,16 +47,32 @@ Describe "MoveUsingStatements" {
4747 ErrorAfter = 0
4848 },
4949 @ {
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'
5167 PSM1File = " using namespace System.IO`r`n`r`n " +
5268 " 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 "
5571 ErrorBefore = 0
5672 ErrorAfter = 0
5773 },
5874 @ {
59- TestCaseName = ' Move using statements even if types are used'
75+ TestCaseName = ' Moves using statements even if types are used'
6076 PSM1File = " function x {`r`n }`r`n " +
6177 " using namespace System.IO`r`n`r`n " + # UsingMustBeAtStartOfScript
6278 " function y {`r`n }`r`n " +
@@ -66,18 +82,18 @@ Describe "MoveUsingStatements" {
6682 ErrorAfter = 0
6783 },
6884 @ {
69- TestCaseName = ' Move using statements even when there are (other) parse errors'
85+ TestCaseName = ' Moves using statements even when there are (other) parse errors'
7086 PSM1File = " using namespace System.IO`r`n`r`n " +
71- " function x { `r`n }`r`n " +
87+ " function x {`r`n }`r`n " +
7288 " 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
7490 ErrorBefore = 2
7591 ErrorAfter = 1
7692 }
7793 )
7894
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 )
8197
8298 $testModuleFile = " $TestDrive /MyModule.psm1"
8399 Set-Content $testModuleFile - value $PSM1File - Encoding UTF8
@@ -99,6 +115,10 @@ Describe "MoveUsingStatements" {
99115 [ref ]$ErrorFound
100116 )
101117 $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+ }
102122 }
103123 }
104124
0 commit comments