Skip to content

Commit

Permalink
Added aditional test to "ForeachToFor" refactoring (#60186)
Browse files Browse the repository at this point in the history
  • Loading branch information
DoctorKrolic authored Mar 15, 2022
1 parent d99a0af commit 8b730c5
Showing 1 changed file with 35 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ protected override CodeRefactoringProvider CreateCodeRefactoringProvider(
private readonly CodeStyleOption2<bool> onWithSilent = new CodeStyleOption2<bool>(true, NotificationOption2.Silent);

private OptionsCollection ImplicitTypeEverywhere
=> new OptionsCollection(GetLanguage())
=> new(GetLanguage())
{
{ CSharpCodeStyleOptions.VarElsewhere, onWithSilent },
{ CSharpCodeStyleOptions.VarWhenTypeIsApparent, onWithSilent },
Expand Down Expand Up @@ -1788,6 +1788,40 @@ void Method()
await TestInRegularAndScriptAsync(text, expected);
}

[WorkItem(50469, "https://github.com/dotnet/roslyn/issues/50469")]
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsConvertForEachToFor)]
public async Task PreventExplicitCastToVar()
{
var text = @"
class Test
{
void Method()
{
var items = new[] { new { x = 1 } };
foreach [||] (var item in items)
{
}
}
}
";
var expected = @"
class Test
{
void Method()
{
var items = new[] { new { x = 1 } };
for (int {|Rename:i|} = 0; i < items.Length; i++)
{
var item = items[i];
}
}
}
";
await TestInRegularAndScriptAsync(text, expected);
}

[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsConvertForEachToFor)]
public async Task NotAssignable()
{
Expand Down

0 comments on commit 8b730c5

Please sign in to comment.