Browse Source

Split Patterns.cs in Using.cs and Loops.cs

pull/877/head
Siegfried Pammer 8 years ago
parent
commit
1613a73755
  1. 8
      ICSharpCode.Decompiler.Tests/CorrectnessTestRunner.cs
  2. 3
      ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj
  3. 84
      ICSharpCode.Decompiler.Tests/TestCases/Correctness/Loops.cs
  4. 82
      ICSharpCode.Decompiler.Tests/TestCases/Correctness/Using.cs

8
ICSharpCode.Decompiler.Tests/CorrectnessTestRunner.cs

@ -96,7 +96,13 @@ namespace ICSharpCode.Decompiler.Tests @@ -96,7 +96,13 @@ namespace ICSharpCode.Decompiler.Tests
}
[Test]
public void Patterns([ValueSource("defaultOptions")] CompilerOptions options)
public void Using([ValueSource("defaultOptions")] CompilerOptions options)
{
RunCS(options: options);
}
[Test]
public void Loops([ValueSource("defaultOptions")] CompilerOptions options)
{
RunCS(options: options);
}

3
ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj

@ -57,9 +57,10 @@ @@ -57,9 +57,10 @@
<Compile Include="Helpers\TypeSystemHelper.cs" />
<Compile Include="ILPrettyTestRunner.cs" />
<Compile Include="Stub.cs" />
<Compile Include="TestCases\Correctness\Loops.cs" />
<Compile Include="TestCases\Correctness\NullableTests.cs" />
<Compile Include="TestCases\Correctness\Patterns.cs" />
<Compile Include="TestCases\Correctness\TrickyTypes.cs" />
<Compile Include="TestCases\Correctness\Using.cs" />
<Compile Include="TestCases\ILPretty\Issue379.cs" />
<Compile Include="TestCases\Pretty\Async.cs" />
<Compile Include="TestCases\Pretty\CheckedUnchecked.cs" />

84
ICSharpCode.Decompiler.Tests/TestCases/Correctness/Patterns.cs → ICSharpCode.Decompiler.Tests/TestCases/Correctness/Loops.cs

@ -1,4 +1,22 @@ @@ -1,4 +1,22 @@
using System;
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
// software and associated documentation files (the "Software"), to deal in the Software
// without restriction, including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
// to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or
// substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
@ -6,76 +24,15 @@ using System.Threading.Tasks; @@ -6,76 +24,15 @@ using System.Threading.Tasks;
namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
{
/// <summary>
/// This file contains special cases of some patterns that cannot be tested in pretty tests.
/// </summary>
static class Patterns
class Loops
{
#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()
{
SimpleUsingNullStatement();
NoUsing();
NoUsing2();
ForWithMultipleVariables();
DoubleForEachWithSameVariable(new[] { "a", "b", "c" });
ForeachExceptForNameCollision(new[] { 42, 43, 44, 45 });
}
#region Using
/// <summary>
/// Special case: Roslyn eliminates the try-finally altogether.
/// </summary>
public static void SimpleUsingNullStatement()
{
Console.WriteLine("before using");
using (null) {
Console.WriteLine("using (null)");
}
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()
{
int x, y;
@ -113,6 +70,5 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -113,6 +70,5 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
current = 1;
Console.WriteLine(current);
}
#endregion
}
}

82
ICSharpCode.Decompiler.Tests/TestCases/Correctness/Using.cs

@ -0,0 +1,82 @@ @@ -0,0 +1,82 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
// software and associated documentation files (the "Software"), to deal in the Software
// without restriction, including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
// to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or
// substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
using System;
namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
{
class Using
{
class PrintOnDispose : IDisposable
{
private string v;
public PrintOnDispose(string v)
{
this.v = v;
}
public void Dispose()
{
Console.WriteLine(this.v);
}
}
static void Main()
{
SimpleUsingNullStatement();
NoUsing();
NoUsing2();
}
/// <summary>
/// Special case: Roslyn eliminates the try-finally altogether.
/// </summary>
public static void SimpleUsingNullStatement()
{
Console.WriteLine("before using");
using (null) {
Console.WriteLine("using (null)");
}
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();
}
}
}
}
}
Loading…
Cancel
Save