Skip to content

Commit 1081a49

Browse files
committed
Redo tests to be data-driven
1 parent 68b44ce commit 1081a49

File tree

12 files changed

+355
-634
lines changed

12 files changed

+355
-634
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT License.
3+
4+
namespace PowerShellEditorServices.Test.Shared.Refactoring;
5+
6+
public class RefactorFunctionTestCases
7+
{
8+
public static RenameTestTarget[] TestCases =
9+
[
10+
new("FunctionsSingle.ps1", Line: 1, Column: 5 ),
11+
new("FunctionMultipleOccurrences.ps1", Line: 1, Column: 5 ),
12+
new("FunctionInnerIsNested.ps1", Line: 5, Column: 5, "bar"),
13+
new("FunctionOuterHasNestedFunction.ps1", Line: 10, Column: 1 ),
14+
new("FunctionWithInnerFunction.ps1", Line: 5, Column: 5, "RenamedInnerFunction"),
15+
new("FunctionWithInternalCalls.ps1", Line: 1, Column: 5 ),
16+
new("FunctionCmdlet.ps1", Line: 10, Column: 1 ),
17+
new("FunctionSameName.ps1", Line: 14, Column: 3, "RenamedSameNameFunction"),
18+
new("FunctionScriptblock.ps1", Line: 5, Column: 5 ),
19+
new("FunctionLoop.ps1", Line: 5, Column: 5 ),
20+
new("FunctionForeach.ps1", Line: 5, Column: 11 ),
21+
new("FunctionForeachObject.ps1", Line: 5, Column: 11 ),
22+
new("FunctionCallWIthinStringExpression.ps1", Line: 10, Column: 1 ),
23+
new("FunctionNestedRedefinition.ps1", Line: 15, Column: 13 )
24+
];
25+
}

test/PowerShellEditorServices.Test.Shared/Refactoring/Functions/RefactorsFunctionData.cs

Lines changed: 0 additions & 109 deletions
This file was deleted.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT License.
3+
4+
#nullable enable
5+
6+
namespace PowerShellEditorServices.Test.Shared.Refactoring;
7+
8+
/// <summary>
9+
/// Describes a test case for renaming a file
10+
/// </summary>
11+
/// <param name="FileName">The test case file name e.g. testScript.ps1</param>
12+
/// <param name="Line">The line where the cursor should be positioned for the rename</param>
13+
/// <param name="Column">The column/character indent where ther cursor should be positioned for the rename</param>
14+
/// <param name="NewName">What the target symbol represented by the line and column should be renamed to. Defaults to "Renamed" if not specified</param>
15+
public record RenameTestTarget(string FileName = "UNKNOWN", int Line = -1, int Column = -1, string NewName = "Renamed")
16+
{
17+
public override string ToString() => $"{FileName.Substring(0, FileName.Length - 4)}";
18+
}

test/PowerShellEditorServices.Test.Shared/Refactoring/Utilities/RefactorUtilitiesData.cs

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,57 @@
11
// Copyright (c) Microsoft Corporation.
22
// Licensed under the MIT License.
3-
using Microsoft.PowerShell.EditorServices.Handlers;
43

5-
namespace PowerShellEditorServices.Test.Shared.Refactoring.Utilities
4+
namespace PowerShellEditorServices.Test.Shared.Refactoring
65
{
76
internal static class RenameUtilitiesData
87
{
9-
10-
public static readonly RenameSymbolParams GetVariableExpressionAst = new()
8+
public static readonly RenameTestTarget GetVariableExpressionAst = new()
119
{
1210
Column = 11,
1311
Line = 15,
14-
RenameTo = "Renamed",
12+
NewName = "Renamed",
1513
FileName = "TestDetection.ps1"
1614
};
17-
public static readonly RenameSymbolParams GetVariableExpressionStartAst = new()
15+
public static readonly RenameTestTarget GetVariableExpressionStartAst = new()
1816
{
1917
Column = 1,
2018
Line = 15,
21-
RenameTo = "Renamed",
19+
NewName = "Renamed",
2220
FileName = "TestDetection.ps1"
2321
};
24-
public static readonly RenameSymbolParams GetVariableWithinParameterAst = new()
22+
public static readonly RenameTestTarget GetVariableWithinParameterAst = new()
2523
{
2624
Column = 21,
2725
Line = 3,
28-
RenameTo = "Renamed",
26+
NewName = "Renamed",
2927
FileName = "TestDetection.ps1"
3028
};
31-
public static readonly RenameSymbolParams GetHashTableKey = new()
29+
public static readonly RenameTestTarget GetHashTableKey = new()
3230
{
3331
Column = 9,
3432
Line = 16,
35-
RenameTo = "Renamed",
33+
NewName = "Renamed",
3634
FileName = "TestDetection.ps1"
3735
};
38-
public static readonly RenameSymbolParams GetVariableWithinCommandAst = new()
36+
public static readonly RenameTestTarget GetVariableWithinCommandAst = new()
3937
{
4038
Column = 29,
4139
Line = 6,
42-
RenameTo = "Renamed",
40+
NewName = "Renamed",
4341
FileName = "TestDetection.ps1"
4442
};
45-
public static readonly RenameSymbolParams GetCommandParameterAst = new()
43+
public static readonly RenameTestTarget GetCommandParameterAst = new()
4644
{
4745
Column = 12,
4846
Line = 21,
49-
RenameTo = "Renamed",
47+
NewName = "Renamed",
5048
FileName = "TestDetection.ps1"
5149
};
52-
public static readonly RenameSymbolParams GetFunctionDefinitionAst = new()
50+
public static readonly RenameTestTarget GetFunctionDefinitionAst = new()
5351
{
5452
Column = 12,
5553
Line = 1,
56-
RenameTo = "Renamed",
54+
NewName = "Renamed",
5755
FileName = "TestDetection.ps1"
5856
};
5957
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT License.
3+
namespace PowerShellEditorServices.Test.Shared.Refactoring;
4+
public class RefactorVariableTestCases
5+
{
6+
public static RenameTestTarget[] TestCases =
7+
[
8+
new ("SimpleVariableAssignment.ps1", Line: 1, Column: 1 ),
9+
new ("VariableRedefinition.ps1", Line: 1, Column: 1 ),
10+
new ("VariableNestedScopeFunction.ps1", Line: 1, Column: 1 ),
11+
new ("VariableInLoop.ps1", Line: 1, Column: 1 ),
12+
new ("VariableInPipeline.ps1", Line: 23, Column: 2 ),
13+
new ("VariableInScriptblockScoped.ps1", Line: 36, Column: 3 ),
14+
new ("VariablewWithinHastableExpression.ps1", Line: 46, Column: 3 ),
15+
new ("VariableNestedFunctionScriptblock.ps1", Line: 20, Column: 4 ),
16+
new ("VariableWithinCommandAstScriptBlock.ps1", Line: 75, Column: 3 ),
17+
new ("VariableWithinForeachObject.ps1", Line: 1, Column: 2 ),
18+
new ("VariableusedInWhileLoop.ps1", Line: 5, Column: 2 ),
19+
new ("VariableInParam.ps1", Line: 16, Column: 24 ),
20+
new ("VariableCommandParameter.ps1", Line: 9, Column: 10 ),
21+
new ("VariableCommandParameter.ps1", Line: 17, Column: 3 ),
22+
new ("VariableScriptWithParamBlock.ps1", Line: 30, Column: 1 ),
23+
new ("VariableNonParam.ps1", Line: 1, Column: 7 ),
24+
new ("VariableParameterCommandWithSameName.ps1", Line: 13, Column: 9 ),
25+
new ("VariableCommandParameterSplatted.ps1", Line: 10, Column: 21 ),
26+
new ("VariableCommandParameterSplatted.ps1", Line: 5, Column: 16 ),
27+
new ("VariableInForeachDuplicateAssignment.ps1", Line: 18, Column: 6 ),
28+
new ("VariableInForloopDuplicateAssignment.ps1", Line: 14, Column: 9 ),
29+
new ("VariableNestedScopeFunctionRefactorInner.ps1", Line: 5, Column: 3 ),
30+
new ("VariableSimpleFunctionParameter.ps1", Line: 9, Column: 6 ),
31+
new ("VariableDotNotationFromInnerFunction.ps1", Line: 26, Column: 11 ),
32+
new ("VariableDotNotationFromInnerFunction.ps1", Line: 1, Column: 1 )
33+
];
34+
}

0 commit comments

Comments
 (0)