From 1613a737556204e440d60fdf7e7792ab986ce56c Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Sun, 24 Sep 2017 22:00:30 +0200 Subject: [PATCH] Split Patterns.cs in Using.cs and Loops.cs --- .../CorrectnessTestRunner.cs | 8 +- .../ICSharpCode.Decompiler.Tests.csproj | 3 +- .../Correctness/{Patterns.cs => Loops.cs} | 84 +++++-------------- .../TestCases/Correctness/Using.cs | 82 ++++++++++++++++++ 4 files changed, 111 insertions(+), 66 deletions(-) rename ICSharpCode.Decompiler.Tests/TestCases/Correctness/{Patterns.cs => Loops.cs} (50%) create mode 100644 ICSharpCode.Decompiler.Tests/TestCases/Correctness/Using.cs diff --git a/ICSharpCode.Decompiler.Tests/CorrectnessTestRunner.cs b/ICSharpCode.Decompiler.Tests/CorrectnessTestRunner.cs index bc87db9fd..bfeaf5e85 100644 --- a/ICSharpCode.Decompiler.Tests/CorrectnessTestRunner.cs +++ b/ICSharpCode.Decompiler.Tests/CorrectnessTestRunner.cs @@ -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); } diff --git a/ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj b/ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj index 6b9061c08..40842b724 100644 --- a/ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj +++ b/ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj @@ -57,9 +57,10 @@ + - + diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Correctness/Patterns.cs b/ICSharpCode.Decompiler.Tests/TestCases/Correctness/Loops.cs similarity index 50% rename from ICSharpCode.Decompiler.Tests/TestCases/Correctness/Patterns.cs rename to ICSharpCode.Decompiler.Tests/TestCases/Correctness/Loops.cs index fdb281baa..8b279083a 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Correctness/Patterns.cs +++ b/ICSharpCode.Decompiler.Tests/TestCases/Correctness/Loops.cs @@ -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; namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness { - /// - /// This file contains special cases of some patterns that cannot be tested in pretty tests. - /// - 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 - /// - /// Special case: Roslyn eliminates the try-finally altogether. - /// - 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 current = 1; Console.WriteLine(current); } - #endregion } } diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Correctness/Using.cs b/ICSharpCode.Decompiler.Tests/TestCases/Correctness/Using.cs new file mode 100644 index 000000000..7e914ca75 --- /dev/null +++ b/ICSharpCode.Decompiler.Tests/TestCases/Correctness/Using.cs @@ -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(); + } + + /// + /// Special case: Roslyn eliminates the try-finally altogether. + /// + 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(); + } + } + } + } +}