Browse Source

Move some test-cases to Patterns.cs

pull/877/head
Siegfried Pammer 8 years ago
parent
commit
c56f5e8491
  1. 48
      ICSharpCode.Decompiler.Tests/TestCases/Correctness/Patterns.cs
  2. 25
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/Using.cs
  3. 77
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/Using.il
  4. 65
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/Using.opt.il
  5. 61
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/Using.opt.roslyn.il
  6. 71
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/Using.roslyn.il

48
ICSharpCode.Decompiler.Tests/TestCases/Correctness/Patterns.cs

@ -9,16 +9,36 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
/// <summary> /// <summary>
/// This file contains special cases of some patterns that cannot be tested in pretty tests. /// This file contains special cases of some patterns that cannot be tested in pretty tests.
/// </summary> /// </summary>
class Patterns static class Patterns
{ {
#region Test Helpers
class PrintOnDispose : IDisposable
{
private string v;
public PrintOnDispose(string v)
{
this.v = v;
}
public void Dispose()
{
Console.WriteLine(this.v);
}
}
#endregion
static void Main() static void Main()
{ {
SimpleUsingNullStatement(); SimpleUsingNullStatement();
NoUsing();
NoUsing2();
ForWithMultipleVariables(); ForWithMultipleVariables();
DoubleForEachWithSameVariable(new[] { "a", "b", "c" }); DoubleForEachWithSameVariable(new[] { "a", "b", "c" });
ForeachExceptForNameCollision(new[] { 42, 43, 44, 45 }); ForeachExceptForNameCollision(new[] { 42, 43, 44, 45 });
} }
#region Using
/// <summary> /// <summary>
/// Special case: Roslyn eliminates the try-finally altogether. /// Special case: Roslyn eliminates the try-finally altogether.
/// </summary> /// </summary>
@ -31,6 +51,31 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
Console.WriteLine("after using"); Console.WriteLine("after using");
} }
public static void NoUsing()
{
PrintOnDispose printOnDispose = new PrintOnDispose("Wrong");
try {
printOnDispose = new PrintOnDispose("Correct");
} finally {
printOnDispose.Dispose();
}
}
public static void NoUsing2()
{
object printOnDispose = new PrintOnDispose("NoUsing(): Wrong");
try {
printOnDispose = new PrintOnDispose("NoUsing(): Correct");
} finally {
IDisposable disposable = printOnDispose as IDisposable;
if (disposable != null) {
disposable.Dispose();
}
}
}
#endregion
#region Loops
public static void ForWithMultipleVariables() public static void ForWithMultipleVariables()
{ {
int x, y; int x, y;
@ -68,5 +113,6 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
current = 1; current = 1;
Console.WriteLine(current); Console.WriteLine(current);
} }
#endregion
} }
} }

25
ICSharpCode.Decompiler.Tests/TestCases/Pretty/Using.cs

@ -39,21 +39,6 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
} }
} }
private class PrintOnDispose : IDisposable
{
private string v;
public PrintOnDispose(string v)
{
this.v = v;
}
public void Dispose()
{
Console.WriteLine(this.v);
}
}
#if LEGACY_CSC #if LEGACY_CSC
public void SimpleUsingNullStatement() public void SimpleUsingNullStatement()
{ {
@ -121,15 +106,5 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
Console.WriteLine(t); Console.WriteLine(t);
} }
} }
public void NoUsing()
{
PrintOnDispose printOnDispose = new PrintOnDispose("Wrong");
try {
printOnDispose = new PrintOnDispose("Correct");
} finally {
printOnDispose.Dispose();
}
}
} }
} }

77
ICSharpCode.Decompiler.Tests/TestCases/Pretty/Using.il

@ -10,7 +10,7 @@
.publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4.. .publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4..
.ver 4:0:0:0 .ver 4:0:0:0
} }
.assembly vu3cz5gg .assembly dybef0h5
{ {
.custom instance void [mscorlib]System.Runtime.CompilerServices.CompilationRelaxationsAttribute::.ctor(int32) = ( 01 00 08 00 00 00 00 00 ) .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilationRelaxationsAttribute::.ctor(int32) = ( 01 00 08 00 00 00 00 00 )
.custom instance void [mscorlib]System.Runtime.CompilerServices.RuntimeCompatibilityAttribute::.ctor() = ( 01 00 01 00 54 02 16 57 72 61 70 4E 6F 6E 45 78 // ....T..WrapNonEx .custom instance void [mscorlib]System.Runtime.CompilerServices.RuntimeCompatibilityAttribute::.ctor() = ( 01 00 01 00 54 02 16 57 72 61 70 4E 6F 6E 45 78 // ....T..WrapNonEx
@ -20,15 +20,15 @@
.hash algorithm 0x00008004 .hash algorithm 0x00008004
.ver 0:0:0:0 .ver 0:0:0:0
} }
.module vu3cz5gg.dll .module dybef0h5.dll
// MVID: {FD1D14F2-B901-4ADC-A6BA-6844964F643A} // MVID: {469DF7ED-3C07-4983-A672-891B2A428600}
.custom instance void [mscorlib]System.Security.UnverifiableCodeAttribute::.ctor() = ( 01 00 00 00 ) .custom instance void [mscorlib]System.Security.UnverifiableCodeAttribute::.ctor() = ( 01 00 00 00 )
.imagebase 0x10000000 .imagebase 0x10000000
.file alignment 0x00000200 .file alignment 0x00000200
.stackreserve 0x00100000 .stackreserve 0x00100000
.subsystem 0x0003 // WINDOWS_CUI .subsystem 0x0003 // WINDOWS_CUI
.corflags 0x00000001 // ILONLY .corflags 0x00000001 // ILONLY
// Image base: 0x00F10000 // Image base: 0x003C0000
// =============== CLASS MEMBERS DECLARATION =================== // =============== CLASS MEMBERS DECLARATION ===================
@ -67,42 +67,6 @@
} // end of class UsingStruct } // end of class UsingStruct
.class auto ansi nested private beforefieldinit PrintOnDispose
extends [mscorlib]System.Object
implements [mscorlib]System.IDisposable
{
.field private string v
.method public hidebysig specialname rtspecialname
instance void .ctor(string v) cil managed
{
// Code size 17 (0x11)
.maxstack 8
IL_0000: ldarg.0
IL_0001: call instance void [mscorlib]System.Object::.ctor()
IL_0006: nop
IL_0007: nop
IL_0008: ldarg.0
IL_0009: ldarg.1
IL_000a: stfld string ICSharpCode.Decompiler.Tests.TestCases.Pretty.Using/PrintOnDispose::v
IL_000f: nop
IL_0010: ret
} // end of method PrintOnDispose::.ctor
.method public hidebysig newslot virtual final
instance void Dispose() cil managed
{
// Code size 14 (0xe)
.maxstack 8
IL_0000: nop
IL_0001: ldarg.0
IL_0002: ldfld string ICSharpCode.Decompiler.Tests.TestCases.Pretty.Using/PrintOnDispose::v
IL_0007: call void [mscorlib]System.Console::WriteLine(string)
IL_000c: nop
IL_000d: ret
} // end of method PrintOnDispose::Dispose
} // end of class PrintOnDispose
.method public hidebysig instance void .method public hidebysig instance void
SimpleUsingNullStatement() cil managed SimpleUsingNullStatement() cil managed
{ {
@ -452,39 +416,6 @@
IL_0030: ret IL_0030: ret
} // end of method Using::GenericClassUsing } // end of method Using::GenericClassUsing
.method public hidebysig instance void
NoUsing() cil managed
{
// Code size 39 (0x27)
.maxstack 1
.locals init (class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Using/PrintOnDispose V_0)
IL_0000: nop
IL_0001: ldstr "Wrong"
IL_0006: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.Using/PrintOnDispose::.ctor(string)
IL_000b: stloc.0
.try
{
IL_000c: nop
IL_000d: ldstr "Correct"
IL_0012: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.Using/PrintOnDispose::.ctor(string)
IL_0017: stloc.0
IL_0018: nop
IL_0019: leave.s IL_0025
} // end .try
finally
{
IL_001b: nop
IL_001c: ldloc.0
IL_001d: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.Using/PrintOnDispose::Dispose()
IL_0022: nop
IL_0023: nop
IL_0024: endfinally
} // end handler
IL_0025: nop
IL_0026: ret
} // end of method Using::NoUsing
.method public hidebysig specialname rtspecialname .method public hidebysig specialname rtspecialname
instance void .ctor() cil managed instance void .ctor() cil managed
{ {

65
ICSharpCode.Decompiler.Tests/TestCases/Pretty/Using.opt.il

@ -10,7 +10,7 @@
.publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4.. .publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4..
.ver 4:0:0:0 .ver 4:0:0:0
} }
.assembly vexl0swc .assembly nwychzte
{ {
.custom instance void [mscorlib]System.Runtime.CompilerServices.CompilationRelaxationsAttribute::.ctor(int32) = ( 01 00 08 00 00 00 00 00 ) .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilationRelaxationsAttribute::.ctor(int32) = ( 01 00 08 00 00 00 00 00 )
.custom instance void [mscorlib]System.Runtime.CompilerServices.RuntimeCompatibilityAttribute::.ctor() = ( 01 00 01 00 54 02 16 57 72 61 70 4E 6F 6E 45 78 // ....T..WrapNonEx .custom instance void [mscorlib]System.Runtime.CompilerServices.RuntimeCompatibilityAttribute::.ctor() = ( 01 00 01 00 54 02 16 57 72 61 70 4E 6F 6E 45 78 // ....T..WrapNonEx
@ -20,15 +20,15 @@
.hash algorithm 0x00008004 .hash algorithm 0x00008004
.ver 0:0:0:0 .ver 0:0:0:0
} }
.module vexl0swc.dll .module nwychzte.dll
// MVID: {EB6E7617-FC1E-4784-86CC-81DA71679C35} // MVID: {142BA3BD-C0CA-4005-A426-112E6C543819}
.custom instance void [mscorlib]System.Security.UnverifiableCodeAttribute::.ctor() = ( 01 00 00 00 ) .custom instance void [mscorlib]System.Security.UnverifiableCodeAttribute::.ctor() = ( 01 00 00 00 )
.imagebase 0x10000000 .imagebase 0x10000000
.file alignment 0x00000200 .file alignment 0x00000200
.stackreserve 0x00100000 .stackreserve 0x00100000
.subsystem 0x0003 // WINDOWS_CUI .subsystem 0x0003 // WINDOWS_CUI
.corflags 0x00000001 // ILONLY .corflags 0x00000001 // ILONLY
// Image base: 0x00BE0000 // Image base: 0x025B0000
// =============== CLASS MEMBERS DECLARATION =================== // =============== CLASS MEMBERS DECLARATION ===================
@ -64,37 +64,6 @@
} // end of class UsingStruct } // end of class UsingStruct
.class auto ansi nested private beforefieldinit PrintOnDispose
extends [mscorlib]System.Object
implements [mscorlib]System.IDisposable
{
.field private string v
.method public hidebysig specialname rtspecialname
instance void .ctor(string v) cil managed
{
// Code size 14 (0xe)
.maxstack 8
IL_0000: ldarg.0
IL_0001: call instance void [mscorlib]System.Object::.ctor()
IL_0006: ldarg.0
IL_0007: ldarg.1
IL_0008: stfld string ICSharpCode.Decompiler.Tests.TestCases.Pretty.Using/PrintOnDispose::v
IL_000d: ret
} // end of method PrintOnDispose::.ctor
.method public hidebysig newslot virtual final
instance void Dispose() cil managed
{
// Code size 12 (0xc)
.maxstack 8
IL_0000: ldarg.0
IL_0001: ldfld string ICSharpCode.Decompiler.Tests.TestCases.Pretty.Using/PrintOnDispose::v
IL_0006: call void [mscorlib]System.Console::WriteLine(string)
IL_000b: ret
} // end of method PrintOnDispose::Dispose
} // end of class PrintOnDispose
.method public hidebysig instance void .method public hidebysig instance void
SimpleUsingNullStatement() cil managed SimpleUsingNullStatement() cil managed
{ {
@ -358,32 +327,6 @@
IL_0025: ret IL_0025: ret
} // end of method Using::GenericClassUsing } // end of method Using::GenericClassUsing
.method public hidebysig instance void
NoUsing() cil managed
{
// Code size 32 (0x20)
.maxstack 1
.locals init (class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Using/PrintOnDispose V_0)
IL_0000: ldstr "Wrong"
IL_0005: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.Using/PrintOnDispose::.ctor(string)
IL_000a: stloc.0
.try
{
IL_000b: ldstr "Correct"
IL_0010: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.Using/PrintOnDispose::.ctor(string)
IL_0015: stloc.0
IL_0016: leave.s IL_001f
} // end .try
finally
{
IL_0018: ldloc.0
IL_0019: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.Using/PrintOnDispose::Dispose()
IL_001e: endfinally
} // end handler
IL_001f: ret
} // end of method Using::NoUsing
.method public hidebysig specialname rtspecialname .method public hidebysig specialname rtspecialname
instance void .ctor() cil managed instance void .ctor() cil managed
{ {

61
ICSharpCode.Decompiler.Tests/TestCases/Pretty/Using.opt.roslyn.il

@ -25,14 +25,14 @@
.ver 0:0:0:0 .ver 0:0:0:0
} }
.module Using.dll .module Using.dll
// MVID: {6ACE0D07-2500-4E79-B8A5-908F446B5708} // MVID: {F795B575-6F0C-4E56-817C-B7689ECEE4A6}
.custom instance void [mscorlib]System.Security.UnverifiableCodeAttribute::.ctor() = ( 01 00 00 00 ) .custom instance void [mscorlib]System.Security.UnverifiableCodeAttribute::.ctor() = ( 01 00 00 00 )
.imagebase 0x10000000 .imagebase 0x10000000
.file alignment 0x00000200 .file alignment 0x00000200
.stackreserve 0x00100000 .stackreserve 0x00100000
.subsystem 0x0003 // WINDOWS_CUI .subsystem 0x0003 // WINDOWS_CUI
.corflags 0x00000001 // ILONLY .corflags 0x00000001 // ILONLY
// Image base: 0x01950000 // Image base: 0x003F0000
// =============== CLASS MEMBERS DECLARATION =================== // =============== CLASS MEMBERS DECLARATION ===================
@ -68,37 +68,6 @@
} // end of class UsingStruct } // end of class UsingStruct
.class auto ansi nested private beforefieldinit PrintOnDispose
extends [mscorlib]System.Object
implements [mscorlib]System.IDisposable
{
.field private string v
.method public hidebysig specialname rtspecialname
instance void .ctor(string v) cil managed
{
// Code size 14 (0xe)
.maxstack 8
IL_0000: ldarg.0
IL_0001: call instance void [mscorlib]System.Object::.ctor()
IL_0006: ldarg.0
IL_0007: ldarg.1
IL_0008: stfld string ICSharpCode.Decompiler.Tests.TestCases.Pretty.Using/PrintOnDispose::v
IL_000d: ret
} // end of method PrintOnDispose::.ctor
.method public hidebysig newslot virtual final
instance void Dispose() cil managed
{
// Code size 12 (0xc)
.maxstack 8
IL_0000: ldarg.0
IL_0001: ldfld string ICSharpCode.Decompiler.Tests.TestCases.Pretty.Using/PrintOnDispose::v
IL_0006: call void [mscorlib]System.Console::WriteLine(string)
IL_000b: ret
} // end of method PrintOnDispose::Dispose
} // end of class PrintOnDispose
.method public hidebysig instance void .method public hidebysig instance void
SimpleUsingExpressionStatement() cil managed SimpleUsingExpressionStatement() cil managed
{ {
@ -335,32 +304,6 @@
IL_0023: ret IL_0023: ret
} // end of method Using::GenericClassUsing } // end of method Using::GenericClassUsing
.method public hidebysig instance void
NoUsing() cil managed
{
// Code size 32 (0x20)
.maxstack 1
.locals init (class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Using/PrintOnDispose V_0)
IL_0000: ldstr "Wrong"
IL_0005: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.Using/PrintOnDispose::.ctor(string)
IL_000a: stloc.0
.try
{
IL_000b: ldstr "Correct"
IL_0010: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.Using/PrintOnDispose::.ctor(string)
IL_0015: stloc.0
IL_0016: leave.s IL_001f
} // end .try
finally
{
IL_0018: ldloc.0
IL_0019: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.Using/PrintOnDispose::Dispose()
IL_001e: endfinally
} // end handler
IL_001f: ret
} // end of method Using::NoUsing
.method public hidebysig specialname rtspecialname .method public hidebysig specialname rtspecialname
instance void .ctor() cil managed instance void .ctor() cil managed
{ {

71
ICSharpCode.Decompiler.Tests/TestCases/Pretty/Using.roslyn.il

@ -25,14 +25,14 @@
.ver 0:0:0:0 .ver 0:0:0:0
} }
.module Using.dll .module Using.dll
// MVID: {01A69772-54AF-4C5E-875F-47130AC714FC} // MVID: {297FC1D9-B0EF-4868-95FD-EA7385BE32F8}
.custom instance void [mscorlib]System.Security.UnverifiableCodeAttribute::.ctor() = ( 01 00 00 00 ) .custom instance void [mscorlib]System.Security.UnverifiableCodeAttribute::.ctor() = ( 01 00 00 00 )
.imagebase 0x10000000 .imagebase 0x10000000
.file alignment 0x00000200 .file alignment 0x00000200
.stackreserve 0x00100000 .stackreserve 0x00100000
.subsystem 0x0003 // WINDOWS_CUI .subsystem 0x0003 // WINDOWS_CUI
.corflags 0x00000001 // ILONLY .corflags 0x00000001 // ILONLY
// Image base: 0x02BE0000 // Image base: 0x027F0000
// =============== CLASS MEMBERS DECLARATION =================== // =============== CLASS MEMBERS DECLARATION ===================
@ -71,41 +71,6 @@
} // end of class UsingStruct } // end of class UsingStruct
.class auto ansi nested private beforefieldinit PrintOnDispose
extends [mscorlib]System.Object
implements [mscorlib]System.IDisposable
{
.field private string v
.method public hidebysig specialname rtspecialname
instance void .ctor(string v) cil managed
{
// Code size 16 (0x10)
.maxstack 8
IL_0000: ldarg.0
IL_0001: call instance void [mscorlib]System.Object::.ctor()
IL_0006: nop
IL_0007: nop
IL_0008: ldarg.0
IL_0009: ldarg.1
IL_000a: stfld string ICSharpCode.Decompiler.Tests.TestCases.Pretty.Using/PrintOnDispose::v
IL_000f: ret
} // end of method PrintOnDispose::.ctor
.method public hidebysig newslot virtual final
instance void Dispose() cil managed
{
// Code size 14 (0xe)
.maxstack 8
IL_0000: nop
IL_0001: ldarg.0
IL_0002: ldfld string ICSharpCode.Decompiler.Tests.TestCases.Pretty.Using/PrintOnDispose::v
IL_0007: call void [mscorlib]System.Console::WriteLine(string)
IL_000c: nop
IL_000d: ret
} // end of method PrintOnDispose::Dispose
} // end of class PrintOnDispose
.method public hidebysig instance void .method public hidebysig instance void
SimpleUsingExpressionStatement() cil managed SimpleUsingExpressionStatement() cil managed
{ {
@ -383,38 +348,6 @@
IL_0028: ret IL_0028: ret
} // end of method Using::GenericClassUsing } // end of method Using::GenericClassUsing
.method public hidebysig instance void
NoUsing() cil managed
{
// Code size 38 (0x26)
.maxstack 1
.locals init (class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Using/PrintOnDispose V_0)
IL_0000: nop
IL_0001: ldstr "Wrong"
IL_0006: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.Using/PrintOnDispose::.ctor(string)
IL_000b: stloc.0
.try
{
IL_000c: nop
IL_000d: ldstr "Correct"
IL_0012: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.Using/PrintOnDispose::.ctor(string)
IL_0017: stloc.0
IL_0018: nop
IL_0019: leave.s IL_0025
} // end .try
finally
{
IL_001b: nop
IL_001c: ldloc.0
IL_001d: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.Using/PrintOnDispose::Dispose()
IL_0022: nop
IL_0023: nop
IL_0024: endfinally
} // end handler
IL_0025: ret
} // end of method Using::NoUsing
.method public hidebysig specialname rtspecialname .method public hidebysig specialname rtspecialname
instance void .ctor() cil managed instance void .ctor() cil managed
{ {

Loading…
Cancel
Save