@@ -82,6 +82,57 @@ function foo {
8282 Invoke-Formatter - ScriptDefinition $def - Range @ (3 , 1 , 4 , 1 ) | Should - Be $expected
8383 }
8484
85+ It " Should track the range when an edit deletes its last line" {
86+ $text = New-Object - TypeName " Microsoft.Windows.PowerShell.ScriptAnalyzer.EditableText" - ArgumentList " first`n`n last"
87+ $correctionType = " Microsoft.Windows.PowerShell.ScriptAnalyzer.Generic.CorrectionExtent" -as [type ]
88+ $correction = [Activator ]::CreateInstance(
89+ $correctionType ,
90+ [object []]@ (2 , 2 , 1 , 1 , [string []]@ (), $null , $null ))
91+ $correctionsType = [System.Collections.Generic.List `` 1 ].MakeGenericType($correctionType )
92+ $corrections = [Activator ]::CreateInstance($correctionsType )
93+ $corrections.Add ($correction )
94+ $range = New-Object - TypeName " Microsoft.Windows.PowerShell.ScriptAnalyzer.Range" - ArgumentList 1 , 1 , 2 , 1
95+ $arguments = [object []]@ (
96+ $text.PSObject.BaseObject ,
97+ $corrections.PSObject.BaseObject ,
98+ 0 ,
99+ $range.PSObject.BaseObject )
100+ $fixMethod = (" Microsoft.Windows.PowerShell.ScriptAnalyzer.ScriptAnalyzer" -as [type ]).GetMethod(
101+ ' Fix' ,
102+ [Reflection.BindingFlags ]' NonPublic, Static' )
103+
104+ $fixMethod.Invoke ($null , $arguments ) | Out-Null
105+
106+ $text.ToString () | Should - Be " first`n last"
107+ $arguments [3 ].End.Line | Should - Be 1
108+ }
109+
110+ It " Should collapse the range when an edit deletes all selected lines" {
111+ $text = New-Object - TypeName " Microsoft.Windows.PowerShell.ScriptAnalyzer.EditableText" - ArgumentList " first`n last"
112+ $correctionType = " Microsoft.Windows.PowerShell.ScriptAnalyzer.Generic.CorrectionExtent" -as [type ]
113+ $correction = [Activator ]::CreateInstance(
114+ $correctionType ,
115+ [object []]@ (2 , 2 , 1 , 5 , [string []]@ (), $null , $null ))
116+ $correctionsType = [System.Collections.Generic.List `` 1 ].MakeGenericType($correctionType )
117+ $corrections = [Activator ]::CreateInstance($correctionsType )
118+ $corrections.Add ($correction )
119+ $range = New-Object - TypeName " Microsoft.Windows.PowerShell.ScriptAnalyzer.Range" - ArgumentList 2 , 1 , 2 , 5
120+ $arguments = [object []]@ (
121+ $text.PSObject.BaseObject ,
122+ $corrections.PSObject.BaseObject ,
123+ 0 ,
124+ $range.PSObject.BaseObject )
125+ $fixMethod = (" Microsoft.Windows.PowerShell.ScriptAnalyzer.ScriptAnalyzer" -as [type ]).GetMethod(
126+ ' Fix' ,
127+ [Reflection.BindingFlags ]' NonPublic, Static' )
128+
129+ $fixMethod.Invoke ($null , $arguments ) | Out-Null
130+
131+ $text.ToString () | Should - Be " first"
132+ $arguments [3 ].Start.Line | Should - Be 1
133+ $arguments [3 ].End.Line | Should - Be 1
134+ }
135+
85136 It " Should apply all corrections when earlier fixes expand the selected line" {
86137 $def = " if(`$ a){'x'}`n if(`$ b){'y'}"
87138 $expected = " if(`$ a){'x'}`n if (`$ b) { 'y' }"
0 commit comments