Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfixes for ConvertSwitchStatementToExpression #38007

Merged
merged 11 commits into from
Oct 3, 2019
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Test.Utilities;
using Roslyn.Test.Utilities;
using Xunit;

namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.ConvertSwitchStatementToExpression
Expand All @@ -13,7 +14,7 @@ public async Task TestNested_01()
{
await TestInCSharp8(
@"class Program
{
{
int M(int i, int j)
{
int r;
Expand Down Expand Up @@ -95,7 +96,7 @@ int M(int i, int j)
}
}",
@"class Program
{
{
int M(int i, int j)
{
var r = i switch
Expand Down Expand Up @@ -125,35 +126,31 @@ int M(int i, int j)
y = 1;
break;
}
switch (i)
return i switch
{
default:
throw null;
case 1:
return j switch
{
10 => 10,
20 => 20,
30 => 30,
_ => 0,
};
case 2:
return j switch
{
10 => 10,
20 => 20,
30 => 30,
var _ => 0,
};
case 3:
return j switch
{
10 => 10,
20 => 20,
30 => 30,
var v => 0,
};
}
1 => j switch
{
10 => 10,
20 => 20,
30 => 30,
_ => 0,
},
2 => j switch
{
10 => 10,
20 => 20,
30 => 30,
var _ => 0,
},
3 => j switch
{
10 => 10,
20 => 20,
30 => 30,
var v => 0,
},
_ => throw null,
};
}
}");
}
Expand All @@ -168,7 +165,8 @@ System.Action<int> M(int i, int j)
{
{|FixAllInDocument:switch|} (i)
{
default:
// 1
default: // 2
return () =>
{
switch (j)
Expand All @@ -186,17 +184,80 @@ System.Action<int> M(int i, int j)
{
return i switch
{
// 1
// 2
_ => () =>
{
switch (j)
{
default:
return 3;
}
}
{
switch (j)
{
default:
return 3;
}
}

,
};
}
}");
}

[WorkItem(37907, "https:/dotnet/roslyn/issues/37907")]
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsConvertSwitchStatementToExpression)]
public async Task TestNested_03()
{
await TestInCSharp8(
@"using System;

class Program
{
public static void Main() { }
public DayOfWeek StatusValue() => DayOfWeek.Monday;
public short Value => 0;
public bool ValueBoolean()
{
bool value;
{|FixAllInDocument:switch|} (StatusValue())
{
case DayOfWeek.Monday:
switch (Value)
{
case 0:
value = false;
break;
case 1:
value = true;
break;
default:
throw new Exception();
}
break;
default:
throw new Exception();
}
return value;
}
}",
@"using System;

class Program
{
public static void Main() { }
public DayOfWeek StatusValue() => DayOfWeek.Monday;
public short Value => 0;
public bool ValueBoolean()
{
var value = (StatusValue()) switch
{
DayOfWeek.Monday => Value switch
{
0 => false,
1 => true,
_ => throw new Exception(),
},
_ => throw new Exception(),
};
return value;
}
}");
}
}
Expand Down
Loading