Browse Source

Add DelegateConstruction tests

pull/892/merge
Siegfried Pammer 8 years ago
parent
commit
911cdbca66
  1. 1
      ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj
  2. 6
      ICSharpCode.Decompiler.Tests/PrettyTestRunner.cs
  3. 61
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/DelegateConstruction.cs
  4. 1400
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/DelegateConstruction.il
  5. 1150
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/DelegateConstruction.opt.il
  6. 1144
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/DelegateConstruction.opt.roslyn.il
  7. 1362
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/DelegateConstruction.roslyn.il

1
ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj

@ -51,6 +51,7 @@ @@ -51,6 +51,7 @@
<ItemGroup>
<Compile Include="DataFlowTest.cs" />
<Compile Include="TestCases\Pretty\DelegateConstruction.cs" />
<Compile Include="Helpers\CodeAssert.cs" />
<Compile Include="Helpers\SdkUtility.cs" />
<Compile Include="Helpers\RemoveCompilerAttribute.cs" />

6
ICSharpCode.Decompiler.Tests/PrettyTestRunner.cs

@ -97,6 +97,12 @@ namespace ICSharpCode.Decompiler.Tests @@ -97,6 +97,12 @@ namespace ICSharpCode.Decompiler.Tests
Run(cscOptions: cscOptions);
}
[Test, Ignore]
public void DelegateConstruction([ValueSource("defaultOptions")] CompilerOptions cscOptions)
{
Run(cscOptions: cscOptions);
}
[Test]
public void AnonymousTypes([Values(CompilerOptions.None, CompilerOptions.Optimize)] CompilerOptions cscOptions)
{

61
ICSharpCode.Decompiler.Tests/DelegateConstruction.cs → ICSharpCode.Decompiler.Tests/TestCases/Pretty/DelegateConstruction.cs

@ -22,19 +22,19 @@ using System.Linq; @@ -22,19 +22,19 @@ using System.Linq;
public static class DelegateConstruction
{
class InstanceTests
private class InstanceTests
{
public Action CaptureOfThis()
{
return delegate {
CaptureOfThis();
return (Action)delegate {
this.CaptureOfThis();
};
}
public Action CaptureOfThisAndParameter(int a)
{
return delegate {
CaptureOfThisAndParameter(a);
return (Action)delegate {
this.CaptureOfThisAndParameter(a);
};
}
@ -42,8 +42,8 @@ public static class DelegateConstruction @@ -42,8 +42,8 @@ public static class DelegateConstruction
{
foreach (int item in Enumerable.Empty<int>()) {
if (item > 0) {
return delegate {
CaptureOfThisAndParameter(item + a);
return (Action)delegate {
this.CaptureOfThisAndParameter(item + a);
};
}
}
@ -55,8 +55,8 @@ public static class DelegateConstruction @@ -55,8 +55,8 @@ public static class DelegateConstruction
foreach (int item in Enumerable.Empty<int>()) {
int copyOfItem = item;
if (item > 0) {
return delegate {
CaptureOfThisAndParameter(item + a + copyOfItem);
return (Action)delegate {
this.CaptureOfThisAndParameter(item + a + copyOfItem);
};
}
}
@ -66,7 +66,7 @@ public static class DelegateConstruction @@ -66,7 +66,7 @@ public static class DelegateConstruction
public void LambdaInForLoop()
{
for (int i = 0; i < 100000; i++) {
Bar(() => Foo());
this.Bar((Func<int>)(() => this.Foo()));
}
}
@ -117,14 +117,11 @@ public static class DelegateConstruction @@ -117,14 +117,11 @@ public static class DelegateConstruction
public static List<Action<int>> AnonymousMethodStoreWithinLoop()
{
List<Action<int>> list = new List<Action<int>>();
for (int i = 0; i < 10; i++)
{
for (int i = 0; i < 10; i++) {
int counter;
list.Add(delegate(int x)
{
list.Add((Action<int>)delegate(int x) {
counter = x;
}
);
});
}
return list;
}
@ -133,21 +130,17 @@ public static class DelegateConstruction @@ -133,21 +130,17 @@ public static class DelegateConstruction
{
List<Action<int>> list = new List<Action<int>>();
int counter;
for (int i = 0; i < 10; i++)
{
list.Add(delegate(int x)
{
for (int i = 0; i < 10; i++) {
list.Add((Action<int>)delegate(int x) {
counter = x;
}
);
});
}
return list;
}
public static Action StaticAnonymousMethodNoClosure()
{
return delegate
{
return (Action)delegate {
Console.WriteLine();
};
}
@ -156,16 +149,15 @@ public static class DelegateConstruction @@ -156,16 +149,15 @@ public static class DelegateConstruction
{
// i is captured variable,
// j is parameter in anonymous method
// k is local in anonymous method,
// l is local in main method
// l is local in anonymous method,
// k is local in main method
// Ensure that the decompiler doesn't introduce name conflicts
List<Action<int>> list = new List<Action<int>>();
for (int l = 0; l < 10; l++) {
for (int k = 0; k < 10; k++) {
int i;
for (i = 0; i < 10; i++) {
list.Add(
delegate (int j) {
for (int k = 0; k < i; k += j) {
list.Add((Action<int>)delegate(int j) {
for (int l = 0; l < i; l += j) {
Console.WriteLine();
}
});
@ -177,8 +169,7 @@ public static class DelegateConstruction @@ -177,8 +169,7 @@ public static class DelegateConstruction
{
List<Action<int>> list = new List<Action<int>>();
for (int k = 0; k < 10; k++) {
list.Add(
delegate(int i) {
list.Add((Action<int>)delegate(int i) {
Console.WriteLine(i);
});
}
@ -186,7 +177,7 @@ public static class DelegateConstruction @@ -186,7 +177,7 @@ public static class DelegateConstruction
public static Action<int> NameConflict3(int i)
{
return delegate(int j) {
return (Action<int>)delegate(int j) {
for (int k = 0; k < j; k++) {
Console.WriteLine(k);
}
@ -195,11 +186,11 @@ public static class DelegateConstruction @@ -195,11 +186,11 @@ public static class DelegateConstruction
public static Func<int, Func<int, int>> CurriedAddition(int a)
{
return b => c => a + b + c;
return (Func<int, Func<int, int>>)((int b) => (Func<int, int>)((int c) => a + b + c));
}
public static Func<int, Func<int, Func<int, int>>> CurriedAddition2(int a)
{
return b => c => d => a + b + c + d;
return (Func<int, Func<int, Func<int, int>>>)((int b) => (Func<int, Func<int, int>>)((int c) => (Func<int, int>)((int d) => a + b + c + d)));
}
}

1400
ICSharpCode.Decompiler.Tests/TestCases/Pretty/DelegateConstruction.il

File diff suppressed because it is too large Load Diff

1150
ICSharpCode.Decompiler.Tests/TestCases/Pretty/DelegateConstruction.opt.il

File diff suppressed because it is too large Load Diff

1144
ICSharpCode.Decompiler.Tests/TestCases/Pretty/DelegateConstruction.opt.roslyn.il

File diff suppressed because it is too large Load Diff

1362
ICSharpCode.Decompiler.Tests/TestCases/Pretty/DelegateConstruction.roslyn.il

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save