Skip to content

Commit c4b6fab

Browse files
committed
Rewrote Variable Handler, all tests passing except a stringconstant splat reference
1 parent db284e0 commit c4b6fab

File tree

8 files changed

+518
-622
lines changed

8 files changed

+518
-622
lines changed

src/PowerShellEditorServices/Services/TextDocument/RenameService.cs

Lines changed: 69 additions & 603 deletions
Large diffs are not rendered by default.

src/PowerShellEditorServices/Utility/AstExtensions.cs

Lines changed: 439 additions & 13 deletions
Large diffs are not rendered by default.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
FunctionThatIsNotDefinedInThisScope -TestParameter 'test'

test/PowerShellEditorServices.Test.Shared/Refactoring/Variables/RefactorVariableTestCases.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public class RefactorVariableTestCases
1818
new ("VariableInForloopDuplicateAssignment.ps1", Line: 9, Column: 14),
1919
new ("VariableInLoop.ps1", Line: 1, Column: 1),
2020
new ("VariableInParam.ps1", Line: 24, Column: 16),
21-
new ("VariableInPipeline.ps1", Line: 2, Column: 23),
21+
new ("VariableInPipeline.ps1", Line: 3, Column: 23),
2222
new ("VariableInScriptblockScoped.ps1", Line: 2, Column: 16),
2323
new ("VariableNestedFunctionScriptblock.ps1", Line: 4, Column: 20),
2424
new ("VariableNestedScopeFunction.ps1", Line: 1, Column: 1),
@@ -31,6 +31,7 @@ public class RefactorVariableTestCases
3131
new ("VariableusedInWhileLoop.ps1", Line: 2, Column: 5),
3232
new ("VariableWithinCommandAstScriptBlock.ps1", Line: 3, Column: 75),
3333
new ("VariableWithinForeachObject.ps1", Line: 2, Column: 1),
34-
new ("VariableWithinHastableExpression.ps1", Line: 3, Column: 46),
34+
new ("VariableWithinHastableExpression.ps1", Line: 3, Column: 46),
35+
new ("ParameterUndefinedFunction.ps1", Line: 1, Column: 39, ShouldFail: true),
3536
];
3637
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
$oldVarName = 5
12
1..10 |
23
Where-Object { $_ -le $oldVarName } |
34
Write-Output
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
$Renamed = 5
12
1..10 |
23
Where-Object { $_ -le $Renamed } |
34
Write-Output

test/PowerShellEditorServices.Test/Refactoring/PrepareRenameHandlerTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,9 @@ public async Task FindsVariable(RenameTestTarget s)
9898
{
9999
result = await testHandler.Handle(testParams, CancellationToken.None);
100100
}
101-
catch (HandlerErrorException)
101+
catch (HandlerErrorException err)
102102
{
103-
Assert.True(s.ShouldFail);
103+
Assert.True(s.ShouldFail, err.Message);
104104
return;
105105
}
106106
if (s.ShouldFail)

test/PowerShellEditorServices.Test/Refactoring/RenameHandlerTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,9 @@ public async void RenamedVariable(RenameTestTarget s)
9898
{
9999
response = await testHandler.Handle(request, CancellationToken.None);
100100
}
101-
catch (HandlerErrorException)
101+
catch (HandlerErrorException err)
102102
{
103-
Assert.True(s.ShouldFail);
103+
Assert.True(s.ShouldFail, $"Shouldfail is {s.ShouldFail} and error is {err.Message}");
104104
return;
105105
}
106106
if (s.ShouldFail)

0 commit comments

Comments
 (0)