Browse Source

#2128: Reformat the whole code base.

pull/2134/head
dotnet format 5 years ago committed by Siegfried Pammer
parent
commit
0d9f871a4f
  1. 34
      ICSharpCode.Decompiler.PdbProvider.Cecil/MonoCecilDebugInfoProvider.cs
  2. 44
      ICSharpCode.Decompiler.Tests/CorrectnessTestRunner.cs
  3. 2
      ICSharpCode.Decompiler.Tests/DataFlowTest.cs
  4. 8
      ICSharpCode.Decompiler.Tests/DisassemblerPrettyTestRunner.cs
  5. 56
      ICSharpCode.Decompiler.Tests/Helpers/CodeAssert.cs
  6. 14
      ICSharpCode.Decompiler.Tests/Helpers/RemoveCompilerAttribute.cs
  7. 100
      ICSharpCode.Decompiler.Tests/Helpers/SdkUtility.cs
  8. 39
      ICSharpCode.Decompiler.Tests/Helpers/Tester.VB.cs
  9. 189
      ICSharpCode.Decompiler.Tests/Helpers/Tester.cs
  10. 11
      ICSharpCode.Decompiler.Tests/ILPrettyTestRunner.cs
  11. 5
      ICSharpCode.Decompiler.Tests/Output/CSharpAmbienceTests.cs
  12. 18
      ICSharpCode.Decompiler.Tests/PdbGenerationTestRunner.cs
  13. 18
      ICSharpCode.Decompiler.Tests/PrettyTestRunner.cs
  14. 2
      ICSharpCode.Decompiler.Tests/ProjectDecompiler/TargetFrameworkTests.cs
  15. 74
      ICSharpCode.Decompiler.Tests/RoundtripAssembly.cs
  16. 8
      ICSharpCode.Decompiler.Tests/Semantics/ConversionTests.cs
  17. 4
      ICSharpCode.Decompiler.Tests/Semantics/ExplicitConversionTest.cs
  18. 8
      ICSharpCode.Decompiler.Tests/Semantics/OverloadResolutionTests.cs
  19. 4
      ICSharpCode.Decompiler.Tests/TestAssemblyResolver.cs
  20. 129
      ICSharpCode.Decompiler.Tests/TestCases/Correctness/Async.cs
  21. 60
      ICSharpCode.Decompiler.Tests/TestCases/Correctness/Capturing.cs
  22. 6
      ICSharpCode.Decompiler.Tests/TestCases/Correctness/Comparisons.cs
  23. 20
      ICSharpCode.Decompiler.Tests/TestCases/Correctness/CompoundAssignment.cs
  24. 56
      ICSharpCode.Decompiler.Tests/TestCases/Correctness/ControlFlow.cs
  25. 39
      ICSharpCode.Decompiler.Tests/TestCases/Correctness/Conversions.cs
  26. 24
      ICSharpCode.Decompiler.Tests/TestCases/Correctness/DeconstructionTests.cs
  27. 3
      ICSharpCode.Decompiler.Tests/TestCases/Correctness/FloatingPointArithmetic.cs
  28. 60
      ICSharpCode.Decompiler.Tests/TestCases/Correctness/InitializerTests.cs
  29. 15
      ICSharpCode.Decompiler.Tests/TestCases/Correctness/LINQRaytracer.cs
  30. 99
      ICSharpCode.Decompiler.Tests/TestCases/Correctness/Loops.cs
  31. 202
      ICSharpCode.Decompiler.Tests/TestCases/Correctness/MiniJSON.cs
  32. 49
      ICSharpCode.Decompiler.Tests/TestCases/Correctness/NullableTests.cs
  33. 3
      ICSharpCode.Decompiler.Tests/TestCases/Correctness/OverloadResolution.cs
  34. 8
      ICSharpCode.Decompiler.Tests/TestCases/Correctness/PropertiesAndEvents.cs
  35. 69
      ICSharpCode.Decompiler.Tests/TestCases/Correctness/Switch.cs
  36. 10
      ICSharpCode.Decompiler.Tests/TestCases/Correctness/UndocumentedExpressions.cs
  37. 6
      ICSharpCode.Decompiler.Tests/TestCases/Correctness/UnsafeCode.cs
  38. 70
      ICSharpCode.Decompiler.Tests/TestCases/Correctness/Using.cs
  39. 19
      ICSharpCode.Decompiler.Tests/TestCases/Correctness/ValueTypeCall.cs
  40. 228
      ICSharpCode.Decompiler.Tests/TestCases/Correctness/YieldReturn.cs
  41. 55
      ICSharpCode.Decompiler.Tests/TestCases/ILPretty/CS1xSwitch_Debug.cs
  42. 55
      ICSharpCode.Decompiler.Tests/TestCases/ILPretty/CS1xSwitch_Release.cs
  43. 21
      ICSharpCode.Decompiler.Tests/TestCases/ILPretty/FSharpLoops_Debug.cs
  44. 21
      ICSharpCode.Decompiler.Tests/TestCases/ILPretty/FSharpLoops_Release.cs
  45. 18
      ICSharpCode.Decompiler.Tests/TestCases/ILPretty/FSharpUsing_Debug.cs
  46. 18
      ICSharpCode.Decompiler.Tests/TestCases/ILPretty/FSharpUsing_Release.cs
  47. 3
      ICSharpCode.Decompiler.Tests/TestCases/ILPretty/Issue1047.cs
  48. 3
      ICSharpCode.Decompiler.Tests/TestCases/ILPretty/Issue1454.cs
  49. 13
      ICSharpCode.Decompiler.Tests/TestCases/ILPretty/Issue1918.cs
  50. 3
      ICSharpCode.Decompiler.Tests/TestCases/ILPretty/Issue646.cs
  51. 25
      ICSharpCode.Decompiler.Tests/TestCases/ILPretty/Issue684.cs
  52. 3
      ICSharpCode.Decompiler.Tests/TestCases/ILPretty/Issue959.cs
  53. 21
      ICSharpCode.Decompiler.Tests/TestCases/ILPretty/SequenceOfNestedIfs.cs
  54. 25
      ICSharpCode.Decompiler.Tests/TestCases/ILPretty/Unsafe.cs
  55. 43
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/Async.cs
  56. 12
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/AsyncForeach.cs
  57. 16
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/AsyncStreams.cs
  58. 12
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/AsyncUsing.cs
  59. 18
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/CheckedUnchecked.cs
  60. 10
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/CompoundAssignmentTest.cs
  61. 5
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/CustomAttributeConflicts.cs
  62. 41
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/CustomShortCircuitOperators.cs
  63. 37
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/CustomTaskType.cs
  64. 6
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/DeconstructionTests.cs
  65. 67
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/DelegateConstruction.cs
  66. 32
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/DynamicTests.cs
  67. 232
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/ExceptionHandling.cs
  68. 15
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/ExpressionTrees.cs
  69. 10
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/FixProxyCalls.cs
  70. 3
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/Generics.cs
  71. 15
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.cs
  72. 3
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/InlineAssignmentTest.cs
  73. 3
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/Issue1080.cs
  74. 171
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/LiftedOperators.cs
  75. 47
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/LocalFunctions.cs
  76. 6
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/Lock.cs
  77. 295
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/Loops.cs
  78. 9
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/NativeInts.cs
  79. 12
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/NullPropagation.cs
  80. 6
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/OutVariables.cs
  81. 2
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/PInvoke.cs
  82. 3
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/QualifierTests.cs
  83. 6
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/QueryExpressions.cs
  84. 288
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/ReduceNesting.cs
  85. 21
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/RefLocalsAndReturns.cs
  86. 140
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/ShortCircuit.cs
  87. 368
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.cs
  88. 21
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/SwitchExpressions.cs
  89. 3
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/ThrowExpressions.cs
  90. 12
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/TupleTests.cs
  91. 3
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/TypeAnalysisTests.cs
  92. 2
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/TypeMemberTests.cs
  93. 61
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/UnsafeCode.cs
  94. 36
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/Using.cs
  95. 6
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/UsingVariables.cs
  96. 9
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/ValueTypes.cs
  97. 181
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/YieldReturn.cs
  98. 26
      ICSharpCode.Decompiler.Tests/TestCases/Ugly/AggressiveScalarReplacementOfAggregates.Expected.cs
  99. 46
      ICSharpCode.Decompiler.Tests/TestCases/Ugly/AggressiveScalarReplacementOfAggregates.cs
  100. 2
      ICSharpCode.Decompiler.Tests/TestCases/Ugly/NoDecimalConstants.Expected.cs
  101. Some files were not shown because too many files have changed in this diff Show More

34
ICSharpCode.Decompiler.PdbProvider.Cecil/MonoCecilDebugInfoProvider.cs

@ -28,6 +28,7 @@ using ICSharpCode.Decompiler.Util; @@ -28,6 +28,7 @@ using ICSharpCode.Decompiler.Util;
using Mono.Cecil;
using Mono.Cecil.Pdb;
using SRM = System.Reflection.Metadata;
namespace ICSharpCode.Decompiler.PdbProvider
@ -38,11 +39,13 @@ namespace ICSharpCode.Decompiler.PdbProvider @@ -38,11 +39,13 @@ namespace ICSharpCode.Decompiler.PdbProvider
public unsafe MonoCecilDebugInfoProvider(PEFile module, string pdbFileName, string description = null)
{
if (module == null) {
if (module == null)
{
throw new ArgumentNullException(nameof(module));
}
if (!module.Reader.IsEntireImageAvailable) {
if (!module.Reader.IsEntireImageAvailable)
{
throw new ArgumentException("This provider needs access to the full image!");
}
@ -51,18 +54,22 @@ namespace ICSharpCode.Decompiler.PdbProvider @@ -51,18 +54,22 @@ namespace ICSharpCode.Decompiler.PdbProvider
var image = module.Reader.GetEntireImage();
this.debugInfo = new Dictionary<SRM.MethodDefinitionHandle, (IList<SequencePoint> SequencePoints, IList<Variable> Variables)>();
using (UnmanagedMemoryStream stream = new UnmanagedMemoryStream(image.Pointer, image.Length))
using (var moduleDef = ModuleDefinition.ReadModule(stream)) {
using (var moduleDef = ModuleDefinition.ReadModule(stream))
{
moduleDef.ReadSymbols(new PdbReaderProvider().GetSymbolReader(moduleDef, pdbFileName));
foreach (var method in module.Metadata.MethodDefinitions) {
foreach (var method in module.Metadata.MethodDefinitions)
{
var cecilMethod = moduleDef.LookupToken(MetadataTokens.GetToken(method)) as MethodDefinition;
var debugInfo = cecilMethod?.DebugInformation;
if (debugInfo == null)
continue;
IList<SequencePoint> sequencePoints = EmptyList<SequencePoint>.Instance;
if (debugInfo.HasSequencePoints) {
if (debugInfo.HasSequencePoints)
{
sequencePoints = new List<SequencePoint>(debugInfo.SequencePoints.Count);
foreach (var point in debugInfo.SequencePoints) {
foreach (var point in debugInfo.SequencePoints)
{
sequencePoints.Add(new SequencePoint {
Offset = point.Offset,
StartLine = point.StartLine,
@ -74,10 +81,12 @@ namespace ICSharpCode.Decompiler.PdbProvider @@ -74,10 +81,12 @@ namespace ICSharpCode.Decompiler.PdbProvider
}
}
var variables = new List<Variable>();
foreach (var scope in debugInfo.GetScopes()) {
foreach (var scope in debugInfo.GetScopes())
{
if (!scope.HasVariables)
continue;
foreach (var v in scope.Variables) {
foreach (var v in scope.Variables)
{
variables.Add(new Variable(v.Index, v.Name));
}
}
@ -90,7 +99,8 @@ namespace ICSharpCode.Decompiler.PdbProvider @@ -90,7 +99,8 @@ namespace ICSharpCode.Decompiler.PdbProvider
public IList<SequencePoint> GetSequencePoints(SRM.MethodDefinitionHandle handle)
{
if (!debugInfo.TryGetValue(handle, out var info)) {
if (!debugInfo.TryGetValue(handle, out var info))
{
return EmptyList<SequencePoint>.Instance;
}
@ -99,7 +109,8 @@ namespace ICSharpCode.Decompiler.PdbProvider @@ -99,7 +109,8 @@ namespace ICSharpCode.Decompiler.PdbProvider
public IList<Variable> GetVariables(SRM.MethodDefinitionHandle handle)
{
if (!debugInfo.TryGetValue(handle, out var info)) {
if (!debugInfo.TryGetValue(handle, out var info))
{
return EmptyList<Variable>.Instance;
}
@ -109,7 +120,8 @@ namespace ICSharpCode.Decompiler.PdbProvider @@ -109,7 +120,8 @@ namespace ICSharpCode.Decompiler.PdbProvider
public bool TryGetName(SRM.MethodDefinitionHandle handle, int index, out string name)
{
name = null;
if (!debugInfo.TryGetValue(handle, out var info)) {
if (!debugInfo.TryGetValue(handle, out var info))
{
return false;
}

44
ICSharpCode.Decompiler.Tests/CorrectnessTestRunner.cs

@ -21,7 +21,9 @@ using System.CodeDom.Compiler; @@ -21,7 +21,9 @@ using System.CodeDom.Compiler;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using ICSharpCode.Decompiler.Tests.Helpers;
using NUnit.Framework;
namespace ICSharpCode.Decompiler.Tests
@ -38,7 +40,8 @@ namespace ICSharpCode.Decompiler.Tests @@ -38,7 +40,8 @@ namespace ICSharpCode.Decompiler.Tests
.Where(m => m.GetCustomAttributes(typeof(TestAttribute), false).Any())
.Select(m => m.Name)
.ToArray();
foreach (var file in new DirectoryInfo(TestCasePath).EnumerateFiles()) {
foreach (var file in new DirectoryInfo(TestCasePath).EnumerateFiles())
{
if (file.Extension == ".txt" || file.Extension == ".exe" || file.Extension == ".config")
continue;
var testName = Path.GetFileNameWithoutExtension(file.Name);
@ -213,7 +216,8 @@ namespace ICSharpCode.Decompiler.Tests @@ -213,7 +216,8 @@ namespace ICSharpCode.Decompiler.Tests
{
CompilerOptions compiler = CompilerOptions.UseDebug;
AssemblerOptions asm = AssemblerOptions.None;
if (force32Bit) {
if (force32Bit)
{
compiler |= CompilerOptions.Force32Bit;
asm |= AssemblerOptions.Force32Bit;
}
@ -237,7 +241,8 @@ namespace ICSharpCode.Decompiler.Tests @@ -237,7 +241,8 @@ namespace ICSharpCode.Decompiler.Tests
{
CompilerOptions compiler = CompilerOptions.UseRoslyn | CompilerOptions.UseDebug;
AssemblerOptions asm = AssemblerOptions.None;
if (force32Bit) {
if (force32Bit)
{
compiler |= CompilerOptions.Force32Bit;
asm |= AssemblerOptions.Force32Bit;
}
@ -247,7 +252,8 @@ namespace ICSharpCode.Decompiler.Tests @@ -247,7 +252,8 @@ namespace ICSharpCode.Decompiler.Tests
[Test]
public void UnsafeCode([ValueSource("defaultOptions")] CompilerOptions options)
{
if (options.HasFlag(CompilerOptions.UseMcs)) {
if (options.HasFlag(CompilerOptions.UseMcs))
{
Assert.Ignore("Decompiler bug with mono!");
}
RunCS(options: options);
@ -274,7 +280,8 @@ namespace ICSharpCode.Decompiler.Tests @@ -274,7 +280,8 @@ namespace ICSharpCode.Decompiler.Tests
[Test]
public void YieldReturn([ValueSource("defaultOptions")] CompilerOptions options)
{
if (options.HasFlag(CompilerOptions.UseMcs)) {
if (options.HasFlag(CompilerOptions.UseMcs))
{
Assert.Ignore("Decompiler bug with mono!");
}
RunCS(options: options);
@ -301,7 +308,8 @@ namespace ICSharpCode.Decompiler.Tests @@ -301,7 +308,8 @@ namespace ICSharpCode.Decompiler.Tests
[Test]
public void MiniJSON([ValueSource("defaultOptions")] CompilerOptions options)
{
if (options.HasFlag(CompilerOptions.UseMcs)) {
if (options.HasFlag(CompilerOptions.UseMcs))
{
Assert.Ignore("Decompiler bug with mono!");
}
RunCS(options: options);
@ -313,11 +321,13 @@ namespace ICSharpCode.Decompiler.Tests @@ -313,11 +321,13 @@ namespace ICSharpCode.Decompiler.Tests
string testOutputFileName = testName + Tester.GetSuffix(options) + ".exe";
CompilerResults outputFile = null, decompiledOutputFile = null;
try {
try
{
outputFile = Tester.CompileCSharp(Path.Combine(TestCasePath, testFileName), options,
outputFileName: Path.Combine(TestCasePath, testOutputFileName));
string decompiledCodeFile = Tester.DecompileCSharp(outputFile.PathToAssembly, Tester.GetSettings(options));
if (forceRoslynRecompile || options.HasFlag(CompilerOptions.UseMcs)) {
if (forceRoslynRecompile || options.HasFlag(CompilerOptions.UseMcs))
{
// For second pass, use roslyn instead of mcs.
// mcs has some compiler bugs that cause it to not accept ILSpy-generated code,
// for example when there's unreachable code due to other compiler bugs in the first mcs run.
@ -337,7 +347,9 @@ namespace ICSharpCode.Decompiler.Tests @@ -337,7 +347,9 @@ namespace ICSharpCode.Decompiler.Tests
Tester.RepeatOnIOError(() => File.Delete(decompiledCodeFile));
Tester.RepeatOnIOError(() => File.Delete(decompiledOutputFile.PathToAssembly));
} finally {
}
finally
{
if (outputFile != null)
outputFile.TempFiles.Delete();
if (decompiledOutputFile != null)
@ -352,7 +364,8 @@ namespace ICSharpCode.Decompiler.Tests @@ -352,7 +364,8 @@ namespace ICSharpCode.Decompiler.Tests
string testOutputFileName = testName + Tester.GetSuffix(options) + ".exe";
CompilerResults outputFile = null, decompiledOutputFile = null;
try {
try
{
outputFile = Tester.CompileVB(Path.Combine(TestCasePath, testFileName), options,
outputFileName: Path.Combine(TestCasePath, testOutputFileName));
string decompiledCodeFile = Tester.DecompileCSharp(outputFile.PathToAssembly, Tester.GetSettings(options));
@ -362,7 +375,9 @@ namespace ICSharpCode.Decompiler.Tests @@ -362,7 +375,9 @@ namespace ICSharpCode.Decompiler.Tests
Tester.RepeatOnIOError(() => File.Delete(decompiledCodeFile));
Tester.RepeatOnIOError(() => File.Delete(decompiledOutputFile.PathToAssembly));
} finally {
}
finally
{
if (outputFile != null)
outputFile.TempFiles.Delete();
if (decompiledOutputFile != null)
@ -375,7 +390,8 @@ namespace ICSharpCode.Decompiler.Tests @@ -375,7 +390,8 @@ namespace ICSharpCode.Decompiler.Tests
string outputFile = null;
CompilerResults decompiledOutputFile = null;
try {
try
{
outputFile = Tester.AssembleIL(Path.Combine(TestCasePath, testFileName), asmOptions);
string decompiledCodeFile = Tester.DecompileCSharp(outputFile, Tester.GetSettings(options));
decompiledOutputFile = Tester.CompileCSharp(decompiledCodeFile, options);
@ -384,7 +400,9 @@ namespace ICSharpCode.Decompiler.Tests @@ -384,7 +400,9 @@ namespace ICSharpCode.Decompiler.Tests
Tester.RepeatOnIOError(() => File.Delete(decompiledCodeFile));
Tester.RepeatOnIOError(() => File.Delete(decompiledOutputFile.PathToAssembly));
} finally {
}
finally
{
if (decompiledOutputFile != null)
decompiledOutputFile.TempFiles.Delete();
}

2
ICSharpCode.Decompiler.Tests/DataFlowTest.cs

@ -22,9 +22,11 @@ using System.Linq; @@ -22,9 +22,11 @@ using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using ICSharpCode.Decompiler.FlowAnalysis;
using ICSharpCode.Decompiler.IL;
using ICSharpCode.Decompiler.TypeSystem;
using NUnit.Framework;
namespace ICSharpCode.Decompiler.Tests

8
ICSharpCode.Decompiler.Tests/DisassemblerPrettyTestRunner.cs

@ -23,7 +23,9 @@ using System.Linq; @@ -23,7 +23,9 @@ using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using ICSharpCode.Decompiler.Tests.Helpers;
using NUnit.Framework;
namespace ICSharpCode.Decompiler.Tests
@ -40,8 +42,10 @@ namespace ICSharpCode.Decompiler.Tests @@ -40,8 +42,10 @@ namespace ICSharpCode.Decompiler.Tests
.Where(m => m.GetCustomAttributes(typeof(TestAttribute), false).Any())
.Select(m => m.Name)
.ToArray();
foreach (var file in new DirectoryInfo(TestCasePath).EnumerateFiles()) {
if (file.Extension.Equals(".il", StringComparison.OrdinalIgnoreCase)) {
foreach (var file in new DirectoryInfo(TestCasePath).EnumerateFiles())
{
if (file.Extension.Equals(".il", StringComparison.OrdinalIgnoreCase))
{
var testName = file.Name.Split('.')[0];
Assert.Contains(testName, testNames);
}

56
ICSharpCode.Decompiler.Tests/Helpers/CodeAssert.cs

@ -2,9 +2,12 @@ @@ -2,9 +2,12 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using DiffLib;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using NUnit.Framework;
namespace ICSharpCode.Decompiler.Tests.Helpers
@ -19,7 +22,8 @@ namespace ICSharpCode.Decompiler.Tests.Helpers @@ -19,7 +22,8 @@ namespace ICSharpCode.Decompiler.Tests.Helpers
public static void AreEqual(string input1, string input2, string[] definedSymbols = null)
{
var diff = new StringWriter();
if (!CodeComparer.Compare(input1, input2, diff, CodeComparer.NormalizeLine, definedSymbols)) {
if (!CodeComparer.Compare(input1, input2, diff, CodeComparer.NormalizeLine, definedSymbols))
{
Assert.Fail(diff.ToString());
}
}
@ -42,25 +46,33 @@ namespace ICSharpCode.Decompiler.Tests.Helpers @@ -42,25 +46,33 @@ namespace ICSharpCode.Decompiler.Tests.Helpers
int consecutiveMatches = contextSize;
var hiddenMatches = new List<string>();
foreach (var change in alignedDiff) {
switch (change.Operation) {
foreach (var change in alignedDiff)
{
switch (change.Operation)
{
case DiffOperation.Match:
AppendMatch($"{++line1,4} {++line2,4} ", change.ElementFromCollection1.Value);
break;
case DiffOperation.Insert:
string pos = $" {++line2,4} ";
if (ShouldIgnoreChange(change.ElementFromCollection2.Value)) {
if (ShouldIgnoreChange(change.ElementFromCollection2.Value))
{
AppendMatch(pos, change.ElementFromCollection2.Value);
} else {
}
else
{
AppendDelta(pos, " + ", change.ElementFromCollection2.Value);
result = false;
}
break;
case DiffOperation.Delete:
pos = $"{++line1,4} ";
if (ShouldIgnoreChange(change.ElementFromCollection1.Value)) {
if (ShouldIgnoreChange(change.ElementFromCollection1.Value))
{
AppendMatch(pos, change.ElementFromCollection1.Value);
} else {
}
else
{
AppendDelta(pos, " - ", change.ElementFromCollection1.Value);
result = false;
}
@ -73,7 +85,8 @@ namespace ICSharpCode.Decompiler.Tests.Helpers @@ -73,7 +85,8 @@ namespace ICSharpCode.Decompiler.Tests.Helpers
break;
}
}
if (hiddenMatches.Count > 0) {
if (hiddenMatches.Count > 0)
{
diff.WriteLine(" ...");
}
@ -82,10 +95,13 @@ namespace ICSharpCode.Decompiler.Tests.Helpers @@ -82,10 +95,13 @@ namespace ICSharpCode.Decompiler.Tests.Helpers
void AppendMatch(string pos, string code)
{
consecutiveMatches++;
if (consecutiveMatches > contextSize) {
if (consecutiveMatches > contextSize)
{
// hide this match
hiddenMatches.Add(pos + " " + code);
} else {
}
else
{
diff.WriteLine(pos + " " + code);
}
}
@ -93,10 +109,12 @@ namespace ICSharpCode.Decompiler.Tests.Helpers @@ -93,10 +109,12 @@ namespace ICSharpCode.Decompiler.Tests.Helpers
void AppendDelta(string pos, string changeType, string code)
{
consecutiveMatches = 0;
if (hiddenMatches.Count > contextSize) {
if (hiddenMatches.Count > contextSize)
{
diff.WriteLine(" ...");
}
for (int i = Math.Max(0, hiddenMatches.Count - contextSize); i < hiddenMatches.Count; i++) {
for (int i = Math.Max(0, hiddenMatches.Count - contextSize); i < hiddenMatches.Count; i++)
{
diff.WriteLine(hiddenMatches[i]);
}
hiddenMatches.Clear();
@ -132,11 +150,16 @@ namespace ICSharpCode.Decompiler.Tests.Helpers @@ -132,11 +150,16 @@ namespace ICSharpCode.Decompiler.Tests.Helpers
{
line = line.Trim();
var index = line.IndexOf("//", StringComparison.Ordinal);
if (index >= 0) {
if (index >= 0)
{
return line.Substring(0, index);
} else if (line.StartsWith("#", StringComparison.Ordinal)) {
}
else if (line.StartsWith("#", StringComparison.Ordinal))
{
return string.Empty;
} else {
}
else
{
return line;
}
}
@ -151,7 +174,8 @@ namespace ICSharpCode.Decompiler.Tests.Helpers @@ -151,7 +174,8 @@ namespace ICSharpCode.Decompiler.Tests.Helpers
{
public override SyntaxTrivia VisitTrivia(SyntaxTrivia trivia)
{
if (trivia.IsKind(SyntaxKind.DisabledTextTrivia)) {
if (trivia.IsKind(SyntaxKind.DisabledTextTrivia))
{
return default(SyntaxTrivia); // delete
}
return base.VisitTrivia(trivia);

14
ICSharpCode.Decompiler.Tests/Helpers/RemoveCompilerAttribute.cs

@ -1,4 +1,5 @@ @@ -1,4 +1,5 @@
using System.Collections.Generic;
using ICSharpCode.Decompiler.CSharp;
using ICSharpCode.Decompiler.CSharp.Syntax;
using ICSharpCode.Decompiler.CSharp.Transforms;
@ -13,12 +14,14 @@ namespace ICSharpCode.Decompiler.Tests.Helpers @@ -13,12 +14,14 @@ namespace ICSharpCode.Decompiler.Tests.Helpers
var section = (AttributeSection)attribute.Parent;
SimpleType type = attribute.Type as SimpleType;
if (section.AttributeTarget == "assembly" &&
(type.Identifier == "CompilationRelaxations" || type.Identifier == "RuntimeCompatibility" || type.Identifier == "SecurityPermission" || type.Identifier == "PermissionSet" || type.Identifier == "AssemblyVersion" || type.Identifier == "Debuggable" || type.Identifier == "TargetFramework")) {
(type.Identifier == "CompilationRelaxations" || type.Identifier == "RuntimeCompatibility" || type.Identifier == "SecurityPermission" || type.Identifier == "PermissionSet" || type.Identifier == "AssemblyVersion" || type.Identifier == "Debuggable" || type.Identifier == "TargetFramework"))
{
attribute.Remove();
if (section.Attributes.Count == 0)
section.Remove();
}
if (section.AttributeTarget == "module" && type.Identifier == "UnverifiableCode") {
if (section.AttributeTarget == "module" && type.Identifier == "UnverifiableCode")
{
attribute.Remove();
if (section.Attributes.Count == 0)
section.Remove();
@ -64,9 +67,12 @@ namespace ICSharpCode.Decompiler.Tests.Helpers @@ -64,9 +67,12 @@ namespace ICSharpCode.Decompiler.Tests.Helpers
{
public override void VisitNamespaceDeclaration(NamespaceDeclaration namespaceDeclaration)
{
if (namespaceDeclaration.Name == "My") {
if (namespaceDeclaration.Name == "My")
{
namespaceDeclaration.Remove();
} else {
}
else
{
base.VisitNamespaceDeclaration(namespaceDeclaration);
}
}

100
ICSharpCode.Decompiler.Tests/Helpers/SdkUtility.cs

@ -17,6 +17,7 @@ @@ -17,6 +17,7 @@
// DEALINGS IN THE SOFTWARE.
using System.IO;
using Microsoft.Win32;
namespace ICSharpCode.Decompiler.Tests.Helpers
@ -25,10 +26,13 @@ namespace ICSharpCode.Decompiler.Tests.Helpers @@ -25,10 +26,13 @@ namespace ICSharpCode.Decompiler.Tests.Helpers
{
static string GetPathFromRegistry(string key, string valueName)
{
using (RegistryKey installRootKey = Registry.LocalMachine.OpenSubKey(key)) {
if (installRootKey != null) {
using (RegistryKey installRootKey = Registry.LocalMachine.OpenSubKey(key))
{
if (installRootKey != null)
{
object o = installRootKey.GetValue(valueName);
if (o != null) {
if (o != null)
{
string r = o.ToString();
if (!string.IsNullOrEmpty(r))
return r;
@ -40,11 +44,15 @@ namespace ICSharpCode.Decompiler.Tests.Helpers @@ -40,11 +44,15 @@ namespace ICSharpCode.Decompiler.Tests.Helpers
static string GetPathFromRegistryX86(string key, string valueName)
{
using (RegistryKey baseKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32)) {
using (RegistryKey installRootKey = baseKey.OpenSubKey(key)) {
if (installRootKey != null) {
using (RegistryKey baseKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32))
{
using (RegistryKey installRootKey = baseKey.OpenSubKey(key))
{
if (installRootKey != null)
{
object o = installRootKey.GetValue(valueName);
if (o != null) {
if (o != null)
{
string r = o.ToString();
if (!string.IsNullOrEmpty(r))
return r;
@ -63,7 +71,8 @@ namespace ICSharpCode.Decompiler.Tests.Helpers @@ -63,7 +71,8 @@ namespace ICSharpCode.Decompiler.Tests.Helpers
/// </summary>
public static string NetFrameworkInstallRoot {
get {
if (netFrameworkInstallRoot == null) {
if (netFrameworkInstallRoot == null)
{
netFrameworkInstallRoot = GetPathFromRegistry(@"SOFTWARE\Microsoft\.NETFramework", "InstallRoot") ?? string.Empty;
}
return netFrameworkInstallRoot;
@ -76,7 +85,8 @@ namespace ICSharpCode.Decompiler.Tests.Helpers @@ -76,7 +85,8 @@ namespace ICSharpCode.Decompiler.Tests.Helpers
/// </summary>
public static string NetSdk20InstallRoot {
get {
if (netSdk20InstallRoot == null) {
if (netSdk20InstallRoot == null)
{
netSdk20InstallRoot = GetPathFromRegistry(@"SOFTWARE\Microsoft\.NETFramework", "sdkInstallRootv2.0") ?? string.Empty;
}
return netSdk20InstallRoot;
@ -89,7 +99,8 @@ namespace ICSharpCode.Decompiler.Tests.Helpers @@ -89,7 +99,8 @@ namespace ICSharpCode.Decompiler.Tests.Helpers
/// </summary>
public static string WindowsSdk60InstallRoot {
get {
if (windowsSdk60InstallRoot == null) {
if (windowsSdk60InstallRoot == null)
{
windowsSdk60InstallRoot = GetPathFromRegistry(@"SOFTWARE\Microsoft\Microsoft SDKs\Windows\v6.0", "InstallationFolder") ?? string.Empty;
}
return windowsSdk60InstallRoot;
@ -102,7 +113,8 @@ namespace ICSharpCode.Decompiler.Tests.Helpers @@ -102,7 +113,8 @@ namespace ICSharpCode.Decompiler.Tests.Helpers
/// </summary>
public static string WindowsSdk60aInstallRoot {
get {
if (windowsSdk60aInstallRoot == null) {
if (windowsSdk60aInstallRoot == null)
{
windowsSdk60aInstallRoot = GetPathFromRegistry(@"SOFTWARE\Microsoft\Microsoft SDKs\Windows\v6.0a", "InstallationFolder") ?? string.Empty;
}
return windowsSdk60aInstallRoot;
@ -115,7 +127,8 @@ namespace ICSharpCode.Decompiler.Tests.Helpers @@ -115,7 +127,8 @@ namespace ICSharpCode.Decompiler.Tests.Helpers
/// </summary>
public static string WindowsSdk61InstallRoot {
get {
if (windowsSdk61InstallRoot == null) {
if (windowsSdk61InstallRoot == null)
{
windowsSdk61InstallRoot = GetPathFromRegistry(@"SOFTWARE\Microsoft\Microsoft SDKs\Windows\v6.1", "InstallationFolder") ?? string.Empty;
}
return windowsSdk61InstallRoot;
@ -128,7 +141,8 @@ namespace ICSharpCode.Decompiler.Tests.Helpers @@ -128,7 +141,8 @@ namespace ICSharpCode.Decompiler.Tests.Helpers
/// </summary>
public static string WindowsSdk70InstallRoot {
get {
if (windowsSdk70InstallRoot == null) {
if (windowsSdk70InstallRoot == null)
{
windowsSdk70InstallRoot = GetPathFromRegistry(@"SOFTWARE\Microsoft\Microsoft SDKs\Windows\v7.0", "InstallationFolder") ?? string.Empty;
}
return windowsSdk70InstallRoot;
@ -141,7 +155,8 @@ namespace ICSharpCode.Decompiler.Tests.Helpers @@ -141,7 +155,8 @@ namespace ICSharpCode.Decompiler.Tests.Helpers
/// </summary>
public static string WindowsSdk71InstallRoot {
get {
if (windowsSdk71InstallRoot == null) {
if (windowsSdk71InstallRoot == null)
{
windowsSdk71InstallRoot = GetPathFromRegistry(@"SOFTWARE\Microsoft\Microsoft SDKs\Windows\v7.1", "InstallationFolder") ?? string.Empty;
}
return windowsSdk71InstallRoot;
@ -154,7 +169,8 @@ namespace ICSharpCode.Decompiler.Tests.Helpers @@ -154,7 +169,8 @@ namespace ICSharpCode.Decompiler.Tests.Helpers
/// </summary>
public static string WindowsSdk80NetFxTools {
get {
if (windowsSdk80InstallRoot == null) {
if (windowsSdk80InstallRoot == null)
{
windowsSdk80InstallRoot = GetPathFromRegistryX86(@"SOFTWARE\Microsoft\Microsoft SDKs\Windows\v8.0A\WinSDK-NetFx40Tools", "InstallationFolder") ?? string.Empty;
}
return windowsSdk80InstallRoot;
@ -167,7 +183,8 @@ namespace ICSharpCode.Decompiler.Tests.Helpers @@ -167,7 +183,8 @@ namespace ICSharpCode.Decompiler.Tests.Helpers
/// </summary>
public static string WindowsSdk461NetFxTools {
get {
if (WindowsSdk461InstallRoot == null) {
if (WindowsSdk461InstallRoot == null)
{
WindowsSdk461InstallRoot = GetPathFromRegistryX86(@"SOFTWARE\Wow6432Node\Microsoft\Microsoft SDKs\NETFXSDK\4.6.1\WinSDK-NetFx40Tools", "InstallationFolder") ?? string.Empty;
}
return WindowsSdk461InstallRoot;
@ -181,39 +198,56 @@ namespace ICSharpCode.Decompiler.Tests.Helpers @@ -181,39 +198,56 @@ namespace ICSharpCode.Decompiler.Tests.Helpers
/// </summary>
/// <param name="exeName">The EXE to search for.</param>
/// <returns>The path of the executable, or null if the exe is not found.</returns>
public static string GetSdkPath(string exeName) {
public static string GetSdkPath(string exeName)
{
string execPath;
if (!string.IsNullOrEmpty(WindowsSdk461NetFxTools)) {
if (!string.IsNullOrEmpty(WindowsSdk461NetFxTools))
{
execPath = Path.Combine(WindowsSdk461NetFxTools, exeName);
if (File.Exists(execPath)) { return execPath; }
if (File.Exists(execPath))
{ return execPath; }
}
if (!string.IsNullOrEmpty(WindowsSdk80NetFxTools)) {
if (!string.IsNullOrEmpty(WindowsSdk80NetFxTools))
{
execPath = Path.Combine(WindowsSdk80NetFxTools, exeName);
if (File.Exists(execPath)) { return execPath; }
if (File.Exists(execPath))
{ return execPath; }
}
if (!string.IsNullOrEmpty(WindowsSdk71InstallRoot)) {
if (!string.IsNullOrEmpty(WindowsSdk71InstallRoot))
{
execPath = Path.Combine(WindowsSdk71InstallRoot, "bin\\" + exeName);
if (File.Exists(execPath)) { return execPath; }
if (File.Exists(execPath))
{ return execPath; }
}
if (!string.IsNullOrEmpty(WindowsSdk70InstallRoot)) {
if (!string.IsNullOrEmpty(WindowsSdk70InstallRoot))
{
execPath = Path.Combine(WindowsSdk70InstallRoot, "bin\\" + exeName);
if (File.Exists(execPath)) { return execPath; }
if (File.Exists(execPath))
{ return execPath; }
}
if (!string.IsNullOrEmpty(WindowsSdk61InstallRoot)) {
if (!string.IsNullOrEmpty(WindowsSdk61InstallRoot))
{
execPath = Path.Combine(WindowsSdk61InstallRoot, "bin\\" + exeName);
if (File.Exists(execPath)) { return execPath; }
if (File.Exists(execPath))
{ return execPath; }
}
if (!string.IsNullOrEmpty(WindowsSdk60aInstallRoot)) {
if (!string.IsNullOrEmpty(WindowsSdk60aInstallRoot))
{
execPath = Path.Combine(WindowsSdk60aInstallRoot, "bin\\" + exeName);
if (File.Exists(execPath)) { return execPath; }
if (File.Exists(execPath))
{ return execPath; }
}
if (!string.IsNullOrEmpty(WindowsSdk60InstallRoot)) {
if (!string.IsNullOrEmpty(WindowsSdk60InstallRoot))
{
execPath = Path.Combine(WindowsSdk60InstallRoot, "bin\\" + exeName);
if (File.Exists(execPath)) { return execPath; }
if (File.Exists(execPath))
{ return execPath; }
}
if (!string.IsNullOrEmpty(NetSdk20InstallRoot)) {
if (!string.IsNullOrEmpty(NetSdk20InstallRoot))
{
execPath = Path.Combine(NetSdk20InstallRoot, "bin\\" + exeName);
if (File.Exists(execPath)) { return execPath; }
if (File.Exists(execPath))
{ return execPath; }
}
return null;
}

39
ICSharpCode.Decompiler.Tests/Helpers/Tester.VB.cs

@ -7,6 +7,7 @@ using System.Text; @@ -7,6 +7,7 @@ using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.VisualBasic;
using Microsoft.VisualBasic;
@ -18,17 +19,20 @@ namespace ICSharpCode.Decompiler.Tests.Helpers @@ -18,17 +19,20 @@ namespace ICSharpCode.Decompiler.Tests.Helpers
public static CompilerResults CompileVB(string sourceFileName, CompilerOptions flags = CompilerOptions.UseDebug, string outputFileName = null)
{
List<string> sourceFileNames = new List<string> { sourceFileName };
foreach (Match match in Regex.Matches(File.ReadAllText(sourceFileName), @"#include ""([\w\d./]+)""")) {
foreach (Match match in Regex.Matches(File.ReadAllText(sourceFileName), @"#include ""([\w\d./]+)"""))
{
sourceFileNames.Add(Path.GetFullPath(Path.Combine(Path.GetDirectoryName(sourceFileName), match.Groups[1].Value)));
}
var preprocessorSymbols = GetPreprocessorSymbols(flags).Select(symbol => new KeyValuePair<string, object>(symbol, 1)).ToList();
if (flags.HasFlag(CompilerOptions.UseRoslyn)) {
if (flags.HasFlag(CompilerOptions.UseRoslyn))
{
var parseOptions = new VisualBasicParseOptions(preprocessorSymbols: preprocessorSymbols, languageVersion: LanguageVersion.Latest);
var syntaxTrees = sourceFileNames.Select(f => SyntaxFactory.ParseSyntaxTree(File.ReadAllText(f), parseOptions, path: f));
var references = defaultReferences.Value;
if (flags.HasFlag(CompilerOptions.ReferenceVisualBasic)) {
if (flags.HasFlag(CompilerOptions.ReferenceVisualBasic))
{
references = references.Concat(visualBasic.Value);
}
var compilation = VisualBasicCompilation.Create(Path.GetFileNameWithoutExtension(sourceFileName),
@ -42,17 +46,23 @@ namespace ICSharpCode.Decompiler.Tests.Helpers @@ -42,17 +46,23 @@ namespace ICSharpCode.Decompiler.Tests.Helpers
CompilerResults results = new CompilerResults(new TempFileCollection());
results.PathToAssembly = outputFileName ?? Path.GetTempFileName();
var emitResult = compilation.Emit(results.PathToAssembly);
if (!emitResult.Success) {
if (!emitResult.Success)
{
StringBuilder b = new StringBuilder("Compiler error:");
foreach (var diag in emitResult.Diagnostics) {
foreach (var diag in emitResult.Diagnostics)
{
b.AppendLine(diag.ToString());
}
throw new Exception(b.ToString());
}
return results;
} else if (flags.HasFlag(CompilerOptions.UseMcs)) {
}
else if (flags.HasFlag(CompilerOptions.UseMcs))
{
throw new NotSupportedException("Cannot use mcs for VB");
} else {
}
else
{
var provider = new VBCodeProvider(new Dictionary<string, string> { { "CompilerVersion", "v4.0" } });
CompilerParameters options = new CompilerParameters();
options.GenerateExecutable = !flags.HasFlag(CompilerOptions.Library);
@ -60,23 +70,28 @@ namespace ICSharpCode.Decompiler.Tests.Helpers @@ -60,23 +70,28 @@ namespace ICSharpCode.Decompiler.Tests.Helpers
options.CompilerOptions += (flags.HasFlag(CompilerOptions.UseDebug) ? " /debug" : "");
options.CompilerOptions += (flags.HasFlag(CompilerOptions.Force32Bit) ? " /platform:anycpu32bitpreferred" : "");
options.CompilerOptions += " /optioninfer+ /optionexplicit+";
if (preprocessorSymbols.Count > 0) {
if (preprocessorSymbols.Count > 0)
{
options.CompilerOptions += " /d:" + string.Join(",", preprocessorSymbols.Select(p => $"{p.Key}={p.Value}"));
}
if (outputFileName != null) {
if (outputFileName != null)
{
options.OutputAssembly = outputFileName;
}
options.ReferencedAssemblies.Add("System.dll");
options.ReferencedAssemblies.Add("System.Core.dll");
options.ReferencedAssemblies.Add("System.Xml.dll");
if (flags.HasFlag(CompilerOptions.ReferenceVisualBasic)) {
if (flags.HasFlag(CompilerOptions.ReferenceVisualBasic))
{
options.ReferencedAssemblies.Add("Microsoft.VisualBasic.dll");
}
CompilerResults results = provider.CompileAssemblyFromFile(options, sourceFileNames.ToArray());
if (results.Errors.Cast<CompilerError>().Any(e => !e.IsWarning)) {
if (results.Errors.Cast<CompilerError>().Any(e => !e.IsWarning))
{
StringBuilder b = new StringBuilder("Compiler error:");
foreach (var error in results.Errors) {
foreach (var error in results.Errors)
{
b.AppendLine(error.ToString());
}
throw new Exception(b.ToString());

189
ICSharpCode.Decompiler.Tests/Helpers/Tester.cs

@ -28,18 +28,21 @@ using System.Text; @@ -28,18 +28,21 @@ using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using ICSharpCode.Decompiler.CSharp;
using ICSharpCode.Decompiler.CSharp.OutputVisitor;
using ICSharpCode.Decompiler.CSharp.Transforms;
using ICSharpCode.Decompiler.Disassembler;
using ICSharpCode.Decompiler.Metadata;
using ICSharpCode.Decompiler.TypeSystem;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.Emit;
using Microsoft.CodeAnalysis.Text;
using Microsoft.CSharp;
using Microsoft.DiaSymReader.Tools;
using NUnit.Framework;
namespace ICSharpCode.Decompiler.Tests.Helpers
@ -81,20 +84,25 @@ namespace ICSharpCode.Decompiler.Tests.Helpers @@ -81,20 +84,25 @@ namespace ICSharpCode.Decompiler.Tests.Helpers
string ilasmPath = Path.Combine(Environment.GetEnvironmentVariable("windir"), @"Microsoft.NET\Framework\v4.0.30319\ilasm.exe");
string outputFile = Path.Combine(Path.GetDirectoryName(sourceFileName), Path.GetFileNameWithoutExtension(sourceFileName));
string otherOptions = " ";
if (options.HasFlag(AssemblerOptions.Force32Bit)) {
if (options.HasFlag(AssemblerOptions.Force32Bit))
{
outputFile += ".32";
otherOptions += "/32BitPreferred ";
}
if (options.HasFlag(AssemblerOptions.Library)) {
if (options.HasFlag(AssemblerOptions.Library))
{
outputFile += ".dll";
otherOptions += "/dll ";
} else {
}
else
{
outputFile += ".exe";
otherOptions += "/exe ";
}
if (options.HasFlag(AssemblerOptions.UseDebug)) {
if (options.HasFlag(AssemblerOptions.UseDebug))
{
otherOptions += "/debug ";
}
@ -121,10 +129,12 @@ namespace ICSharpCode.Decompiler.Tests.Helpers @@ -121,10 +129,12 @@ namespace ICSharpCode.Decompiler.Tests.Helpers
public static string Disassemble(string sourceFileName, string outputFile, AssemblerOptions asmOptions)
{
if (asmOptions.HasFlag(AssemblerOptions.UseOwnDisassembler)) {
if (asmOptions.HasFlag(AssemblerOptions.UseOwnDisassembler))
{
using (var peFileStream = new FileStream(sourceFileName, FileMode.Open, FileAccess.Read))
using (var peFile = new PEFile(sourceFileName, peFileStream))
using (var writer = new StringWriter()) {
using (var writer = new StringWriter())
{
var metadata = peFile.Metadata;
var output = new PlainTextOutput(writer);
ReflectionDisassembler rd = new ReflectionDisassembler(output, CancellationToken.None);
@ -217,7 +227,8 @@ namespace ICSharpCode.Decompiler.Tests.Helpers @@ -217,7 +227,8 @@ namespace ICSharpCode.Decompiler.Tests.Helpers
static IEnumerable<MetadataReference> GetDefaultReferences()
{
foreach (var reference in Directory.EnumerateFiles(coreRefAsmPath, "*.dll")) {
foreach (var reference in Directory.EnumerateFiles(coreRefAsmPath, "*.dll"))
{
yield return MetadataReference.CreateFromFile(reference);
}
}
@ -231,16 +242,20 @@ namespace ICSharpCode.Decompiler.Tests.Helpers @@ -231,16 +242,20 @@ namespace ICSharpCode.Decompiler.Tests.Helpers
public static List<string> GetPreprocessorSymbols(CompilerOptions flags)
{
var preprocessorSymbols = new List<string>();
if (flags.HasFlag(CompilerOptions.UseDebug)) {
if (flags.HasFlag(CompilerOptions.UseDebug))
{
preprocessorSymbols.Add("DEBUG");
}
if (flags.HasFlag(CompilerOptions.Optimize)) {
if (flags.HasFlag(CompilerOptions.Optimize))
{
preprocessorSymbols.Add("OPT");
}
if (flags.HasFlag(CompilerOptions.ReferenceCore)) {
if (flags.HasFlag(CompilerOptions.ReferenceCore))
{
preprocessorSymbols.Add("NETCORE");
}
if (flags.HasFlag(CompilerOptions.UseRoslyn)) {
if (flags.HasFlag(CompilerOptions.UseRoslyn))
{
preprocessorSymbols.Add("ROSLYN");
preprocessorSymbols.Add("CS60");
preprocessorSymbols.Add("CS70");
@ -252,12 +267,17 @@ namespace ICSharpCode.Decompiler.Tests.Helpers @@ -252,12 +267,17 @@ namespace ICSharpCode.Decompiler.Tests.Helpers
preprocessorSymbols.Add("VB14");
preprocessorSymbols.Add("VB15");
if (flags.HasFlag(CompilerOptions.Preview)) {
if (flags.HasFlag(CompilerOptions.Preview))
{
preprocessorSymbols.Add("CS90");
}
} else if (flags.HasFlag(CompilerOptions.UseMcs)) {
}
else if (flags.HasFlag(CompilerOptions.UseMcs))
{
preprocessorSymbols.Add("MCS");
} else {
}
else
{
preprocessorSymbols.Add("LEGACY_CSC");
preprocessorSymbols.Add("LEGACY_VBC");
}
@ -267,28 +287,35 @@ namespace ICSharpCode.Decompiler.Tests.Helpers @@ -267,28 +287,35 @@ namespace ICSharpCode.Decompiler.Tests.Helpers
public static CompilerResults CompileCSharp(string sourceFileName, CompilerOptions flags = CompilerOptions.UseDebug, string outputFileName = null)
{
List<string> sourceFileNames = new List<string> { sourceFileName };
foreach (Match match in Regex.Matches(File.ReadAllText(sourceFileName), @"#include ""([\w\d./]+)""")) {
foreach (Match match in Regex.Matches(File.ReadAllText(sourceFileName), @"#include ""([\w\d./]+)"""))
{
sourceFileNames.Add(Path.GetFullPath(Path.Combine(Path.GetDirectoryName(sourceFileName), match.Groups[1].Value)));
}
var preprocessorSymbols = GetPreprocessorSymbols(flags);
if (flags.HasFlag(CompilerOptions.UseRoslyn)) {
if (flags.HasFlag(CompilerOptions.UseRoslyn))
{
var parseOptions = new CSharpParseOptions(
preprocessorSymbols: preprocessorSymbols.ToArray(),
languageVersion: flags.HasFlag(CompilerOptions.Preview) ? Microsoft.CodeAnalysis.CSharp.LanguageVersion.Preview : Microsoft.CodeAnalysis.CSharp.LanguageVersion.CSharp8
);
var syntaxTrees = sourceFileNames.Select(f => SyntaxFactory.ParseSyntaxTree(File.ReadAllText(f), parseOptions, path: f, encoding: Encoding.UTF8));
if (flags.HasFlag(CompilerOptions.ReferenceCore)) {
if (flags.HasFlag(CompilerOptions.ReferenceCore))
{
syntaxTrees = syntaxTrees.Concat(new[] { SyntaxFactory.ParseSyntaxTree(targetFrameworkAttributeSnippet) });
}
IEnumerable<MetadataReference> references;
if (flags.HasFlag(CompilerOptions.ReferenceCore)) {
if (flags.HasFlag(CompilerOptions.ReferenceCore))
{
references = coreDefaultReferences.Value;
} else {
}
else
{
references = defaultReferences.Value;
}
if (flags.HasFlag(CompilerOptions.ReferenceVisualBasic)) {
if (flags.HasFlag(CompilerOptions.ReferenceVisualBasic))
{
references = references.Concat(visualBasic.Value);
}
var compilation = CSharpCompilation.Create(Path.GetFileNameWithoutExtension(sourceFileName),
@ -306,41 +333,54 @@ namespace ICSharpCode.Decompiler.Tests.Helpers @@ -306,41 +333,54 @@ namespace ICSharpCode.Decompiler.Tests.Helpers
if (flags.HasFlag(CompilerOptions.GeneratePdb))
pdbName = Path.ChangeExtension(outputFileName, ".pdb");
var emitResult = compilation.Emit(results.PathToAssembly, pdbName);
if (!emitResult.Success) {
if (!emitResult.Success)
{
StringBuilder b = new StringBuilder("Compiler error:");
foreach (var diag in emitResult.Diagnostics) {
foreach (var diag in emitResult.Diagnostics)
{
b.AppendLine(diag.ToString());
}
throw new Exception(b.ToString());
}
return results;
} else if (flags.HasFlag(CompilerOptions.UseMcs)) {
}
else if (flags.HasFlag(CompilerOptions.UseMcs))
{
CompilerResults results = new CompilerResults(new TempFileCollection());
results.PathToAssembly = outputFileName ?? Path.GetTempFileName();
string testBasePath = RoundtripAssembly.TestDir;
if (!Directory.Exists(testBasePath)) {
if (!Directory.Exists(testBasePath))
{
Assert.Ignore($"Compilation with mcs ignored: test directory '{testBasePath}' needs to be checked out separately." + Environment.NewLine +
$"git clone https://github.com/icsharpcode/ILSpy-tests \"{testBasePath}\"");
}
string mcsPath = Path.Combine(testBasePath, @"mcs\2.6.4\bin\gmcs.bat");
string otherOptions = " -unsafe -o" + (flags.HasFlag(CompilerOptions.Optimize) ? "+ " : "- ");
if (flags.HasFlag(CompilerOptions.Library)) {
if (flags.HasFlag(CompilerOptions.Library))
{
otherOptions += "-t:library ";
} else {
}
else
{
otherOptions += "-t:exe ";
}
if (flags.HasFlag(CompilerOptions.UseDebug)) {
if (flags.HasFlag(CompilerOptions.UseDebug))
{
otherOptions += "-g ";
}
if (flags.HasFlag(CompilerOptions.Force32Bit)) {
if (flags.HasFlag(CompilerOptions.Force32Bit))
{
otherOptions += "-platform:x86 ";
} else {
}
else
{
otherOptions += "-platform:anycpu ";
}
if (preprocessorSymbols.Count > 0) {
if (preprocessorSymbols.Count > 0)
{
otherOptions += " \"-d:" + string.Join(";", preprocessorSymbols) + "\" ";
}
@ -364,35 +404,43 @@ namespace ICSharpCode.Decompiler.Tests.Helpers @@ -364,35 +404,43 @@ namespace ICSharpCode.Decompiler.Tests.Helpers
Console.WriteLine("errors: " + errorTask.Result);
Assert.AreEqual(0, process.ExitCode, "mcs failed");
return results;
} else {
}
else
{
var provider = new CSharpCodeProvider(new Dictionary<string, string> { { "CompilerVersion", "v4.0" } });
CompilerParameters options = new CompilerParameters();
options.GenerateExecutable = !flags.HasFlag(CompilerOptions.Library);
options.CompilerOptions = "/unsafe /o" + (flags.HasFlag(CompilerOptions.Optimize) ? "+" : "-");
string debugOption = " /debug";
if (flags.HasFlag(CompilerOptions.GeneratePdb)) {
if (flags.HasFlag(CompilerOptions.GeneratePdb))
{
debugOption += ":full";
options.IncludeDebugInformation = true;
}
options.CompilerOptions += (flags.HasFlag(CompilerOptions.UseDebug) ? debugOption : "");
options.CompilerOptions += (flags.HasFlag(CompilerOptions.Force32Bit) ? " /platform:anycpu32bitpreferred" : "");
if (preprocessorSymbols.Count > 0) {
if (preprocessorSymbols.Count > 0)
{
options.CompilerOptions += " /d:" + string.Join(";", preprocessorSymbols);
}
if (outputFileName != null) {
if (outputFileName != null)
{
options.OutputAssembly = outputFileName;
}
options.ReferencedAssemblies.Add("System.dll");
options.ReferencedAssemblies.Add("System.Core.dll");
options.ReferencedAssemblies.Add("System.Xml.dll");
options.ReferencedAssemblies.Add("Microsoft.CSharp.dll");
if (flags.HasFlag(CompilerOptions.ReferenceVisualBasic)) {
if (flags.HasFlag(CompilerOptions.ReferenceVisualBasic))
{
options.ReferencedAssemblies.Add("Microsoft.VisualBasic.dll");
}
CompilerResults results = provider.CompileAssemblyFromFile(options, sourceFileNames.ToArray());
if (results.Errors.Cast<CompilerError>().Any(e => !e.IsWarning)) {
if (results.Errors.Cast<CompilerError>().Any(e => !e.IsWarning))
{
StringBuilder b = new StringBuilder("Compiler error:");
foreach (var error in results.Errors) {
foreach (var error in results.Errors)
{
b.AppendLine(error.ToString());
}
throw new Exception(b.ToString());
@ -403,13 +451,19 @@ namespace ICSharpCode.Decompiler.Tests.Helpers @@ -403,13 +451,19 @@ namespace ICSharpCode.Decompiler.Tests.Helpers
internal static DecompilerSettings GetSettings(CompilerOptions cscOptions)
{
if (cscOptions.HasFlag(CompilerOptions.UseRoslyn)) {
if (cscOptions.HasFlag(CompilerOptions.Preview)) {
if (cscOptions.HasFlag(CompilerOptions.UseRoslyn))
{
if (cscOptions.HasFlag(CompilerOptions.Preview))
{
return new DecompilerSettings(CSharp.LanguageVersion.Latest);
} else {
}
else
{
return new DecompilerSettings(CSharp.LanguageVersion.CSharp8_0);
}
} else {
}
else
{
return new DecompilerSettings(CSharp.LanguageVersion.CSharp5);
}
}
@ -421,7 +475,8 @@ namespace ICSharpCode.Decompiler.Tests.Helpers @@ -421,7 +475,8 @@ namespace ICSharpCode.Decompiler.Tests.Helpers
List<EmbeddedText> embeddedTexts = new List<EmbeddedText>();
List<SyntaxTree> syntaxTrees = new List<SyntaxTree>();
foreach (KeyValuePair<string, string> file in sourceFiles) {
foreach (KeyValuePair<string, string> file in sourceFiles)
{
var sourceText = SourceText.From(file.Value, new UTF8Encoding(false), SourceHashAlgorithm.Sha256);
syntaxTrees.Add(SyntaxFactory.ParseSyntaxTree(sourceText, parseOptions, file.Key));
embeddedTexts.Add(EmbeddedText.FromSource(file.Key, sourceText));
@ -437,11 +492,14 @@ namespace ICSharpCode.Decompiler.Tests.Helpers @@ -437,11 +492,14 @@ namespace ICSharpCode.Decompiler.Tests.Helpers
deterministic: true
));
using (FileStream peStream = File.Open(assemblyName + ".dll", FileMode.OpenOrCreate, FileAccess.ReadWrite))
using (FileStream pdbStream = File.Open(assemblyName + ".pdb", FileMode.OpenOrCreate, FileAccess.ReadWrite)) {
using (FileStream pdbStream = File.Open(assemblyName + ".pdb", FileMode.OpenOrCreate, FileAccess.ReadWrite))
{
var emitResult = compilation.Emit(peStream, pdbStream, options: new EmitOptions(debugInformationFormat: DebugInformationFormat.PortablePdb, pdbFilePath: assemblyName + ".pdb"), embeddedTexts: embeddedTexts);
if (!emitResult.Success) {
if (!emitResult.Success)
{
StringBuilder b = new StringBuilder("Compiler error:");
foreach (var diag in emitResult.Diagnostics) {
foreach (var diag in emitResult.Diagnostics)
{
b.AppendLine(diag.ToString());
}
throw new Exception(b.ToString());
@ -490,7 +548,8 @@ namespace ICSharpCode.Decompiler.Tests.Helpers @@ -490,7 +548,8 @@ namespace ICSharpCode.Decompiler.Tests.Helpers
{
if (settings == null)
settings = new DecompilerSettings();
using (var file = new FileStream(assemblyFileName, FileMode.Open, FileAccess.Read)) {
using (var file = new FileStream(assemblyFileName, FileMode.Open, FileAccess.Read))
{
var module = new PEFile(assemblyFileName, file, PEStreamOptions.PrefetchEntireImage);
var resolver = new UniversalAssemblyResolver(assemblyFileName, false,
module.Reader.DetectTargetFrameworkId(), PEStreamOptions.PrefetchMetadata);
@ -526,13 +585,16 @@ namespace ICSharpCode.Decompiler.Tests.Helpers @@ -526,13 +585,16 @@ namespace ICSharpCode.Decompiler.Tests.Helpers
Assert.AreEqual(0, result1, "Exit code != 0; did the test case crash?" + Environment.NewLine + error1);
Assert.AreEqual(0, result2, "Exit code != 0; did the decompiled code crash?" + Environment.NewLine + error2);
if (output1 != output2 || error1 != error2) {
if (output1 != output2 || error1 != error2)
{
StringBuilder b = new StringBuilder();
b.AppendLine($"Test {testFileName} failed: output does not match.");
if (decompiledCodeFile != null) {
if (decompiledCodeFile != null)
{
b.AppendLine($"Decompiled code in {decompiledCodeFile}:line 1");
}
if (error1 != error2) {
if (error1 != error2)
{
b.AppendLine("Got different error output.");
b.AppendLine("Original error:");
b.AppendLine(error1);
@ -541,25 +603,30 @@ namespace ICSharpCode.Decompiler.Tests.Helpers @@ -541,25 +603,30 @@ namespace ICSharpCode.Decompiler.Tests.Helpers
b.AppendLine(error2);
b.AppendLine();
}
if (output1 != output2) {
if (output1 != output2)
{
string outputFileName = Path.Combine(Path.GetTempPath(), Path.GetFileNameWithoutExtension(testFileName));
File.WriteAllText(outputFileName + ".original.out", output1);
File.WriteAllText(outputFileName + ".decompiled.out", output2);
int diffLine = 0;
string lastHeader = null;
Tuple<string, string> errorItem = null;
foreach (var pair in output1.Replace("\r", "").Split('\n').Zip(output2.Replace("\r", "").Split('\n'), Tuple.Create)) {
foreach (var pair in output1.Replace("\r", "").Split('\n').Zip(output2.Replace("\r", "").Split('\n'), Tuple.Create))
{
diffLine++;
if (pair.Item1 != pair.Item2) {
if (pair.Item1 != pair.Item2)
{
errorItem = pair;
break;
}
if (pair.Item1.EndsWith(":", StringComparison.Ordinal)) {
if (pair.Item1.EndsWith(":", StringComparison.Ordinal))
{
lastHeader = pair.Item1;
}
}
b.AppendLine($"Output differs; first difference in line {diffLine}");
if (lastHeader != null) {
if (lastHeader != null)
{
b.AppendLine(lastHeader);
}
b.AppendLine($"{outputFileName}.original.out:line {diffLine}");
@ -573,12 +640,18 @@ namespace ICSharpCode.Decompiler.Tests.Helpers @@ -573,12 +640,18 @@ namespace ICSharpCode.Decompiler.Tests.Helpers
internal static void RepeatOnIOError(Action action, int numTries = 5)
{
for (int i = 0; i < numTries - 1; i++) {
try {
for (int i = 0; i < numTries - 1; i++)
{
try
{
action();
return;
} catch (IOException) {
} catch (UnauthorizedAccessException) {
}
catch (IOException)
{
}
catch (UnauthorizedAccessException)
{
// potential virus scanner problem
}
Thread.Sleep(10);

11
ICSharpCode.Decompiler.Tests/ILPrettyTestRunner.cs

@ -20,7 +20,9 @@ using System; @@ -20,7 +20,9 @@ using System;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using ICSharpCode.Decompiler.Tests.Helpers;
using NUnit.Framework;
namespace ICSharpCode.Decompiler.Tests
@ -37,8 +39,10 @@ namespace ICSharpCode.Decompiler.Tests @@ -37,8 +39,10 @@ namespace ICSharpCode.Decompiler.Tests
.Where(m => m.GetCustomAttributes(typeof(TestAttribute), false).Any())
.Select(m => m.Name)
.ToArray();
foreach (var file in new DirectoryInfo(TestCasePath).EnumerateFiles()) {
if (file.Extension.Equals(".il", StringComparison.OrdinalIgnoreCase)) {
foreach (var file in new DirectoryInfo(TestCasePath).EnumerateFiles())
{
if (file.Extension.Equals(".il", StringComparison.OrdinalIgnoreCase))
{
var testName = file.Name.Split('.')[0];
Assert.Contains(testName, testNames);
Assert.IsTrue(File.Exists(Path.Combine(TestCasePath, testName + ".cs")));
@ -243,7 +247,8 @@ namespace ICSharpCode.Decompiler.Tests @@ -243,7 +247,8 @@ namespace ICSharpCode.Decompiler.Tests
static void CopyFSharpCoreDll()
{
lock (copyLock) {
lock (copyLock)
{
if (File.Exists(Path.Combine(TestCasePath, "FSharp.Core.dll")))
return;
string fsharpCoreDll = Path.Combine(TestCasePath, "..\\..\\..\\ILSpy-tests\\FSharp\\FSharp.Core.dll");

5
ICSharpCode.Decompiler.Tests/Output/CSharpAmbienceTests.cs

@ -19,11 +19,13 @@ @@ -19,11 +19,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using ICSharpCode.Decompiler.CSharp.OutputVisitor;
using ICSharpCode.Decompiler.Output;
using ICSharpCode.Decompiler.Tests.TypeSystem;
using ICSharpCode.Decompiler.TypeSystem;
using ICSharpCode.Decompiler.TypeSystem.Implementation;
using NUnit.Framework;
using static ICSharpCode.Decompiler.Output.ConversionFlags;
@ -47,7 +49,8 @@ namespace ICSharpCode.Decompiler.Tests.Output @@ -47,7 +49,8 @@ namespace ICSharpCode.Decompiler.Tests.Output
ITypeDefinition GetDefinition(Type type)
{
if (type == null) {
if (type == null)
{
throw new ArgumentNullException(nameof(type));
}

18
ICSharpCode.Decompiler.Tests/PdbGenerationTestRunner.cs

@ -6,14 +6,17 @@ using System.Reflection.PortableExecutable; @@ -6,14 +6,17 @@ using System.Reflection.PortableExecutable;
using System.Runtime.CompilerServices;
using System.Text;
using System.Xml.Linq;
using ICSharpCode.Decompiler.CSharp;
using ICSharpCode.Decompiler.CSharp.OutputVisitor;
using ICSharpCode.Decompiler.DebugInfo;
using ICSharpCode.Decompiler.Metadata;
using ICSharpCode.Decompiler.Tests.Helpers;
using ICSharpCode.Decompiler.TypeSystem;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.DiaSymReader.Tools;
using NUnit.Framework;
namespace ICSharpCode.Decompiler.Tests
@ -58,17 +61,21 @@ namespace ICSharpCode.Decompiler.Tests @@ -58,17 +61,21 @@ namespace ICSharpCode.Decompiler.Tests
var moduleDefinition = new PEFile(peFileName);
var resolver = new UniversalAssemblyResolver(peFileName, false, moduleDefinition.Reader.DetectTargetFrameworkId(), PEStreamOptions.PrefetchEntireImage);
var decompiler = new CSharpDecompiler(moduleDefinition, resolver, new DecompilerSettings());
using (FileStream pdbStream = File.Open(Path.Combine(TestCasePath, testName + ".pdb"), FileMode.OpenOrCreate, FileAccess.ReadWrite)) {
using (FileStream pdbStream = File.Open(Path.Combine(TestCasePath, testName + ".pdb"), FileMode.OpenOrCreate, FileAccess.ReadWrite))
{
pdbStream.SetLength(0);
PortablePdbWriter.WritePdb(moduleDefinition, decompiler, new DecompilerSettings(), pdbStream, noLogo: true);
pdbStream.Position = 0;
using (Stream peStream = File.OpenRead(peFileName))
using (Stream expectedPdbStream = File.OpenRead(pdbFileName)) {
using (StreamWriter writer = new StreamWriter(Path.ChangeExtension(pdbFileName, ".xml"), false, Encoding.UTF8)) {
using (Stream expectedPdbStream = File.OpenRead(pdbFileName))
{
using (StreamWriter writer = new StreamWriter(Path.ChangeExtension(pdbFileName, ".xml"), false, Encoding.UTF8))
{
PdbToXmlConverter.ToXml(writer, expectedPdbStream, peStream, options);
}
peStream.Position = 0;
using (StreamWriter writer = new StreamWriter(Path.ChangeExtension(xmlFile, ".generated.xml"), false, Encoding.UTF8)) {
using (StreamWriter writer = new StreamWriter(Path.ChangeExtension(xmlFile, ".generated.xml"), false, Encoding.UTF8))
{
PdbToXmlConverter.ToXml(writer, pdbStream, peStream, options);
}
}
@ -83,7 +90,8 @@ namespace ICSharpCode.Decompiler.Tests @@ -83,7 +90,8 @@ namespace ICSharpCode.Decompiler.Tests
private void ProcessXmlFile(string fileName)
{
var document = XDocument.Load(fileName);
foreach (var file in document.Descendants("file")) {
foreach (var file in document.Descendants("file"))
{
file.Attribute("checksum").Remove();
file.Attribute("embeddedSourceLength").Remove();
file.ReplaceNodes(new XCData(file.Value.Replace("\uFEFF", "")));

18
ICSharpCode.Decompiler.Tests/PrettyTestRunner.cs

@ -21,7 +21,9 @@ using System.CodeDom.Compiler; @@ -21,7 +21,9 @@ using System.CodeDom.Compiler;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using ICSharpCode.Decompiler.Tests.Helpers;
using NUnit.Framework;
namespace ICSharpCode.Decompiler.Tests
@ -38,9 +40,11 @@ namespace ICSharpCode.Decompiler.Tests @@ -38,9 +40,11 @@ namespace ICSharpCode.Decompiler.Tests
.Where(m => m.GetCustomAttributes(typeof(TestAttribute), false).Any())
.Select(m => m.Name)
.ToArray();
foreach (var file in new DirectoryInfo(TestCasePath).EnumerateFiles()) {
foreach (var file in new DirectoryInfo(TestCasePath).EnumerateFiles())
{
if (file.Extension.Equals(".il", StringComparison.OrdinalIgnoreCase)
|| file.Extension.Equals(".cs", StringComparison.OrdinalIgnoreCase)) {
|| file.Extension.Equals(".cs", StringComparison.OrdinalIgnoreCase))
{
var testName = file.Name.Split('.')[0];
Assert.Contains(testName, testNames);
}
@ -533,15 +537,19 @@ namespace ICSharpCode.Decompiler.Tests @@ -533,15 +537,19 @@ namespace ICSharpCode.Decompiler.Tests
{
var csFile = Path.Combine(TestCasePath, testName + ".cs");
var exeFile = Path.Combine(TestCasePath, testName) + Tester.GetSuffix(cscOptions) + ".exe";
if (cscOptions.HasFlag(CompilerOptions.Library)) {
if (cscOptions.HasFlag(CompilerOptions.Library))
{
exeFile = Path.ChangeExtension(exeFile, ".dll");
}
// 1. Compile
CompilerResults output = null;
try {
try
{
output = Tester.CompileCSharp(csFile, cscOptions, exeFile);
} finally {
}
finally
{
if (output != null)
output.TempFiles.Delete();
}

2
ICSharpCode.Decompiler.Tests/ProjectDecompiler/TargetFrameworkTests.cs

@ -17,7 +17,9 @@ @@ -17,7 +17,9 @@
// DEALINGS IN THE SOFTWARE.
using System;
using ICSharpCode.Decompiler.CSharp.ProjectDecompiler;
using NUnit.Framework;
namespace ICSharpCode.Decompiler.Tests

74
ICSharpCode.Decompiler.Tests/RoundtripAssembly.cs

@ -23,12 +23,15 @@ using System.Linq; @@ -23,12 +23,15 @@ using System.Linq;
using System.Reflection.PortableExecutable;
using System.Text.RegularExpressions;
using System.Threading;
using ICSharpCode.Decompiler.CSharp;
using ICSharpCode.Decompiler.CSharp.ProjectDecompiler;
using ICSharpCode.Decompiler.Metadata;
using ICSharpCode.Decompiler.Tests.Helpers;
using Microsoft.Build.Locator;
using Microsoft.Win32;
using NUnit.Framework;
namespace ICSharpCode.Decompiler.Tests
@ -54,9 +57,12 @@ namespace ICSharpCode.Decompiler.Tests @@ -54,9 +57,12 @@ namespace ICSharpCode.Decompiler.Tests
[Test]
public void NewtonsoftJson_pcl_debug()
{
try {
try
{
RunWithTest("Newtonsoft.Json-pcl-debug", "Newtonsoft.Json.dll", "Newtonsoft.Json.Tests.dll", useOldProjectFormat: true);
} catch (CompilationFailedException) {
}
catch (CompilationFailedException)
{
Assert.Ignore("Cannot yet re-compile PCL projects.");
}
}
@ -148,14 +154,16 @@ namespace ICSharpCode.Decompiler.Tests @@ -148,14 +154,16 @@ namespace ICSharpCode.Decompiler.Tests
void RunInternal(string dir, string fileToRoundtrip, Action<string> testAction, LanguageVersion languageVersion, string snkFilePath = null, bool useOldProjectFormat = false)
{
if (!Directory.Exists(TestDir)) {
if (!Directory.Exists(TestDir))
{
Assert.Ignore($"Assembly-roundtrip test ignored: test directory '{TestDir}' needs to be checked out separately." + Environment.NewLine +
$"git clone https://github.com/icsharpcode/ILSpy-tests \"{TestDir}\"");
$"git clone https://github.com/icsharpcode/ILSpy-tests \"{TestDir}\"");
}
string inputDir = Path.Combine(TestDir, dir);
string decompiledDir = inputDir + "-decompiled";
string outputDir = inputDir + "-output";
if (inputDir.EndsWith("TestCases")) {
if (inputDir.EndsWith("TestCases"))
{
// make sure output dir names are unique so that we don't get trouble due to parallel test execution
decompiledDir += Path.GetFileNameWithoutExtension(fileToRoundtrip) + "_" + languageVersion.ToString();
outputDir += Path.GetFileNameWithoutExtension(fileToRoundtrip) + "_" + languageVersion.ToString();
@ -163,16 +171,20 @@ namespace ICSharpCode.Decompiler.Tests @@ -163,16 +171,20 @@ namespace ICSharpCode.Decompiler.Tests
ClearDirectory(decompiledDir);
ClearDirectory(outputDir);
string projectFile = null;
foreach (string file in Directory.EnumerateFiles(inputDir, "*", SearchOption.AllDirectories)) {
if (!file.StartsWith(inputDir + Path.DirectorySeparatorChar, StringComparison.OrdinalIgnoreCase)) {
foreach (string file in Directory.EnumerateFiles(inputDir, "*", SearchOption.AllDirectories))
{
if (!file.StartsWith(inputDir + Path.DirectorySeparatorChar, StringComparison.OrdinalIgnoreCase))
{
Assert.Fail($"Unexpected file name: {file}");
}
string relFile = file.Substring(inputDir.Length + 1);
Directory.CreateDirectory(Path.Combine(outputDir, Path.GetDirectoryName(relFile)));
if (relFile.Equals(fileToRoundtrip, StringComparison.OrdinalIgnoreCase)) {
if (relFile.Equals(fileToRoundtrip, StringComparison.OrdinalIgnoreCase))
{
Console.WriteLine($"Decompiling {fileToRoundtrip}...");
Stopwatch w = Stopwatch.StartNew();
using (var fileStream = new FileStream(file, FileMode.Open, FileAccess.Read)) {
using (var fileStream = new FileStream(file, FileMode.Open, FileAccess.Read))
{
PEFile module = new PEFile(file, fileStream, PEStreamOptions.PrefetchEntireImage);
var resolver = new TestAssemblyResolver(file, inputDir, module.Reader.DetectTargetFrameworkId());
resolver.AddSearchDirectory(inputDir);
@ -182,20 +194,24 @@ namespace ICSharpCode.Decompiler.Tests @@ -182,20 +194,24 @@ namespace ICSharpCode.Decompiler.Tests
var projectGuid = Guid.Parse("{127C83E4-4587-4CF9-ADCA-799875F3DFE6}");
var settings = new DecompilerSettings(languageVersion);
if (useOldProjectFormat) {
if (useOldProjectFormat)
{
settings.UseSdkStyleProjectFormat = false;
}
var decompiler = new TestProjectDecompiler(projectGuid, resolver, settings);
if (snkFilePath != null) {
if (snkFilePath != null)
{
decompiler.StrongNameKeyFile = Path.Combine(inputDir, snkFilePath);
}
decompiler.DecompileProject(module, decompiledDir);
Console.WriteLine($"Decompiled {fileToRoundtrip} in {w.Elapsed.TotalSeconds:f2}");
projectFile = Path.Combine(decompiledDir, module.Name + ".csproj");
}
} else {
}
else
{
File.Copy(file, Path.Combine(outputDir, relFile));
}
}
@ -208,19 +224,25 @@ namespace ICSharpCode.Decompiler.Tests @@ -208,19 +224,25 @@ namespace ICSharpCode.Decompiler.Tests
static void ClearDirectory(string dir)
{
Directory.CreateDirectory(dir);
foreach (string subdir in Directory.EnumerateDirectories(dir)) {
for (int attempt = 0; ; attempt++) {
try {
foreach (string subdir in Directory.EnumerateDirectories(dir))
{
for (int attempt = 0; ; attempt++)
{
try
{
Directory.Delete(subdir, true);
break;
} catch (IOException) {
}
catch (IOException)
{
if (attempt >= 10)
throw;
Thread.Sleep(100);
}
}
}
foreach (string file in Directory.EnumerateFiles(dir)) {
foreach (string file in Directory.EnumerateFiles(dir))
{
File.Delete(file);
}
}
@ -247,16 +269,20 @@ namespace ICSharpCode.Decompiler.Tests @@ -247,16 +269,20 @@ namespace ICSharpCode.Decompiler.Tests
info.EnvironmentVariables.Remove("Configuration");
info.EnvironmentVariables.Remove("Platform");
Console.WriteLine($"\"{info.FileName}\" {info.Arguments}");
using (var p = Process.Start(info)) {
using (var p = Process.Start(info))
{
Regex errorRegex = new Regex(@"^[\w\d.\\-]+\(\d+,\d+\):");
string suffix = $" [{projectFile}]";
string line;
while ((line = p.StandardOutput.ReadLine()) != null) {
if (line.EndsWith(suffix, StringComparison.OrdinalIgnoreCase)) {
while ((line = p.StandardOutput.ReadLine()) != null)
{
if (line.EndsWith(suffix, StringComparison.OrdinalIgnoreCase))
{
line = line.Substring(0, line.Length - suffix.Length);
}
Match m = errorRegex.Match(line);
if (m.Success) {
if (m.Success)
{
// Make path absolute so that it gets hyperlinked
line = Path.GetDirectoryName(projectFile) + Path.DirectorySeparatorChar + line;
}
@ -277,9 +303,11 @@ namespace ICSharpCode.Decompiler.Tests @@ -277,9 +303,11 @@ namespace ICSharpCode.Decompiler.Tests
info.UseShellExecute = false;
info.RedirectStandardOutput = true;
Console.WriteLine($"\"{info.FileName}\" {info.Arguments}");
using (var p = Process.Start(info)) {
using (var p = Process.Start(info))
{
string line;
while ((line = p.StandardOutput.ReadLine()) != null) {
while ((line = p.StandardOutput.ReadLine()) != null)
{
Console.WriteLine(line);
}
p.WaitForExit();

8
ICSharpCode.Decompiler.Tests/Semantics/ConversionTests.cs

@ -20,21 +20,23 @@ using System; @@ -20,21 +20,23 @@ using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Immutable;
using ICSharpCode.Decompiler.CSharp.Resolver;
using ICSharpCode.Decompiler.Semantics;
using ICSharpCode.Decompiler.Tests.TypeSystem;
using ICSharpCode.Decompiler.TypeSystem;
using ICSharpCode.Decompiler.TypeSystem.Implementation;
using NUnit.Framework;
namespace ICSharpCode.Decompiler.Tests.Semantics
{
// assign short names to the fake reflection types
using Null = ICSharpCode.Decompiler.TypeSystem.ReflectionHelper.Null;
using C = Conversion;
using dynamic = ICSharpCode.Decompiler.TypeSystem.ReflectionHelper.Dynamic;
using nuint = ICSharpCode.Decompiler.TypeSystem.ReflectionHelper.NUInt;
using nint = ICSharpCode.Decompiler.TypeSystem.ReflectionHelper.NInt;
using C = Conversion;
using nuint = ICSharpCode.Decompiler.TypeSystem.ReflectionHelper.NUInt;
using Null = ICSharpCode.Decompiler.TypeSystem.ReflectionHelper.Null;
[TestFixture, Parallelizable(ParallelScope.All)]
public unsafe class ConversionTest

4
ICSharpCode.Decompiler.Tests/Semantics/ExplicitConversionTest.cs

@ -19,17 +19,19 @@ @@ -19,17 +19,19 @@
using System;
using System.Collections.Generic;
using System.Linq;
using ICSharpCode.Decompiler.CSharp.Resolver;
using ICSharpCode.Decompiler.Semantics;
using ICSharpCode.Decompiler.Tests.TypeSystem;
using ICSharpCode.Decompiler.TypeSystem;
using ICSharpCode.Decompiler.TypeSystem.Implementation;
using NUnit.Framework;
namespace ICSharpCode.Decompiler.Tests.Semantics
{
using dynamic = ICSharpCode.Decompiler.TypeSystem.ReflectionHelper.Dynamic;
using C = Conversion;
using dynamic = ICSharpCode.Decompiler.TypeSystem.ReflectionHelper.Dynamic;
[TestFixture, Parallelizable(ParallelScope.All)]
public class ExplicitConversionsTest

8
ICSharpCode.Decompiler.Tests/Semantics/OverloadResolutionTests.cs

@ -20,11 +20,13 @@ using System; @@ -20,11 +20,13 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using ICSharpCode.Decompiler.CSharp.Resolver;
using ICSharpCode.Decompiler.Semantics;
using ICSharpCode.Decompiler.Tests.TypeSystem;
using ICSharpCode.Decompiler.TypeSystem;
using ICSharpCode.Decompiler.TypeSystem.Implementation;
using NUnit.Framework;
namespace ICSharpCode.Decompiler.Tests.Semantics
@ -53,7 +55,8 @@ namespace ICSharpCode.Decompiler.Tests.Semantics @@ -53,7 +55,8 @@ namespace ICSharpCode.Decompiler.Tests.Semantics
var m = new FakeMethod(compilation, SymbolKind.Method);
m.Name = "Method";
var parameters = new List<IParameter>();
foreach (var typeOrDefaultValue in parameterTypesOrDefaultValues) {
foreach (var typeOrDefaultValue in parameterTypesOrDefaultValues)
{
Type type = typeOrDefaultValue as Type;
if (type != null)
parameters.Add(new DefaultParameter(compilation.FindType(type), string.Empty, owner: m));
@ -324,7 +327,8 @@ namespace ICSharpCode.Decompiler.Tests.Semantics @@ -324,7 +327,8 @@ namespace ICSharpCode.Decompiler.Tests.Semantics
};
OverloadResolution r = new OverloadResolution(compilation, args);
foreach (var method in container.GetMethods(m => m.Name == "Method")) {
foreach (var method in container.GetMethods(m => m.Name == "Method"))
{
Assert.AreEqual(OverloadResolutionErrors.None, r.AddCandidate(method));
}

4
ICSharpCode.Decompiler.Tests/TestAssemblyResolver.cs

@ -3,6 +3,7 @@ using System.IO; @@ -3,6 +3,7 @@ using System.IO;
using System.Linq;
using System.Reflection.Metadata;
using System.Reflection.PortableExecutable;
using ICSharpCode.Decompiler.Metadata;
namespace ICSharpCode.Decompiler.Tests
@ -15,7 +16,8 @@ namespace ICSharpCode.Decompiler.Tests @@ -15,7 +16,8 @@ namespace ICSharpCode.Decompiler.Tests
: base(mainAssemblyFileName, false, targetFramework, PEStreamOptions.PrefetchMetadata, MetadataReaderOptions.ApplyWindowsRuntimeProjections)
{
var assemblyNames = new DirectoryInfo(baseDir).EnumerateFiles("*.dll").Select(f => Path.GetFileNameWithoutExtension(f.Name));
foreach (var name in assemblyNames) {
foreach (var name in assemblyNames)
{
localAssemblies.Add(name);
}
}

129
ICSharpCode.Decompiler.Tests/TestCases/Correctness/Async.cs

@ -44,9 +44,12 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -44,9 +44,12 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
await AwaitMultipleCatchBlocks(Task.FromResult(1));
await AwaitMultipleCatchBlocks2(Task.FromResult(1));
Console.WriteLine(await AwaitInComplexFinally());
try {
try
{
await AwaitFinally(Task.FromResult(2));
} catch (Exception ex) {
}
catch (Exception ex)
{
Console.WriteLine(ex + " caught!");
}
#endif
@ -75,7 +78,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -75,7 +78,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
byte[] array = new byte[bufferSize];
int count;
Console.WriteLine("BeforeLoop");
while ((count = await destination.ReadAsync(array, 0, array.Length)) != 0) {
while ((count = await destination.ReadAsync(array, 0, array.Length)) != 0)
{
Console.WriteLine("In Loop after condition!");
await destination.WriteAsync(array, 0, count);
Console.WriteLine("In Loop after inner await");
@ -89,7 +93,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -89,7 +93,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
byte[] array = new byte[bufferSize];
int count;
Console.WriteLine("Before Loop");
while ((count = await destination.ReadAsync(array, 0, array.Length).ConfigureAwait(false)) != 0) {
while ((count = await destination.ReadAsync(array, 0, array.Length).ConfigureAwait(false)) != 0)
{
Console.WriteLine("Before Inner Await");
await destination.WriteAsync(array, 0, count).ConfigureAwait(false);
Console.WriteLine("After Inner Await");
@ -101,7 +106,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -101,7 +106,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
{
int num = 0;
Console.WriteLine("Before Loop");
foreach (Task<int> current in elements) {
foreach (Task<int> current in elements)
{
Console.WriteLine("Before Inner Await");
num += await current;
Console.WriteLine("After Inner Await");
@ -112,11 +118,15 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -112,11 +118,15 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
public async Task TaskMethodWithoutAwaitButWithExceptionHandling()
{
try {
using (new StringWriter()) {
try
{
using (new StringWriter())
{
Console.WriteLine("No Await");
}
} catch (Exception) {
}
catch (Exception)
{
Console.WriteLine("Crash");
}
}
@ -124,23 +134,31 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -124,23 +134,31 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
#if CS60
public async Task AwaitCatch(Task<int> task)
{
try {
try
{
Console.WriteLine("Before throw");
throw new Exception();
} catch {
}
catch
{
Console.WriteLine(await task);
}
}
public async Task AwaitMultipleCatchBlocks(Task<int> task)
{
try {
try
{
Console.WriteLine("Before throw");
throw new Exception();
} catch (OutOfMemoryException ex) {
}
catch (OutOfMemoryException ex)
{
Console.WriteLine(ex.ToString());
Console.WriteLine(await task);
} catch {
}
catch
{
Console.WriteLine(await task);
}
}
@ -148,25 +166,35 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -148,25 +166,35 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
public async Task AwaitMultipleCatchBlocks2(Task<int> task)
{
try {
try
{
Console.WriteLine("Before throw");
throw new Exception();
} catch (OutOfMemoryException ex) {
}
catch (OutOfMemoryException ex)
{
Console.WriteLine(ex.ToString());
Console.WriteLine(await task);
} catch (InternalBufferOverflowException ex) {
}
catch (InternalBufferOverflowException ex)
{
Console.WriteLine(ex.ToString());
} catch {
}
catch
{
Console.WriteLine(await task);
}
}
public async Task AwaitFinally(Task<int> task)
{
try {
try
{
Console.WriteLine("Before throw");
throw new Exception();
} finally {
}
finally
{
Console.WriteLine(await task);
}
}
@ -184,9 +212,12 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -184,9 +212,12 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
public async Task AwaitWithStack2(Task<int> task)
{
if (await this.SimpleBoolTaskMethod()) {
if (await this.SimpleBoolTaskMethod())
{
Console.WriteLine("A", 1, await task);
} else {
}
else
{
int num = 1;
Console.WriteLine("A", 1, num);
}
@ -195,11 +226,14 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -195,11 +226,14 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
#if CS60
public async Task AwaitInCatch(Task<int> task1, Task<int> task2)
{
try {
try
{
Console.WriteLine("Start try");
await task1;
Console.WriteLine("End try");
} catch (Exception) {
}
catch (Exception)
{
Console.WriteLine("Start catch");
await task2;
Console.WriteLine("End catch");
@ -209,11 +243,14 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -209,11 +243,14 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
public async Task AwaitInFinally(Task<int> task1, Task<int> task2)
{
try {
try
{
Console.WriteLine("Start try");
await task1;
Console.WriteLine("End try");
} finally {
}
finally
{
Console.WriteLine("Start finally");
await task2;
Console.WriteLine("End finally");
@ -224,20 +261,29 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -224,20 +261,29 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
public static async Task<int> AwaitInComplexFinally()
{
Console.WriteLine("a");
try {
try
{
Console.WriteLine("b");
await Task.Delay(1);
Console.WriteLine("c");
} catch (Exception ex) {
}
catch (Exception ex)
{
await Task.Delay(ex.HResult);
} finally {
}
finally
{
Console.WriteLine("d");
int i = 0;
if (Console.CapsLock) {
if (Console.CapsLock)
{
i++;
await Task.Delay(i);
} else {
while (i < 5) {
}
else
{
while (i < 5)
{
Console.WriteLine("i: " + i);
i++;
}
@ -250,15 +296,20 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -250,15 +296,20 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
public async Task AwaitInCatchAndFinally(Task<int> task1, Task<int> task2, Task<int> task3)
{
try {
try
{
Console.WriteLine("Start try");
await task1;
Console.WriteLine("End try");
} catch (Exception ex) {
}
catch (Exception ex)
{
Console.WriteLine("Start catch");
await task2;
Console.WriteLine("End catch");
} finally {
}
finally
{
Console.WriteLine("Start finally");
await task3;
Console.WriteLine("End finally");
@ -268,12 +319,16 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -268,12 +319,16 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
public async Task<int> AwaitInFinallyInUsing(Task<IDisposable> task1, Task<int> task2, Task<int> task3)
{
using (await task1) {
using (await task1)
{
Console.WriteLine("Start using");
try {
try
{
Console.WriteLine("Before return");
return await task2;
} finally {
}
finally
{
Console.WriteLine("Start finally");
await task3;
Console.WriteLine("End finally");

60
ICSharpCode.Decompiler.Tests/TestCases/Correctness/Capturing.cs

@ -31,7 +31,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -31,7 +31,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
List<Action> actions = new List<Action>();
int max = 5;
string line;
while (ReadLine(out line, ref max)) {
while (ReadLine(out line, ref max))
{
actions.Add(() => Console.WriteLine(line));
}
// line still declared
@ -47,7 +48,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -47,7 +48,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
List<Action> actions = new List<Action>();
int max = 5;
string line;
while (ReadLine(out line, ref max)) {
while (ReadLine(out line, ref max))
{
string capture = line;
actions.Add(() => Console.WriteLine(capture));
}
@ -64,7 +66,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -64,7 +66,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
List<Action> actions = new List<Action>();
int max = 5;
string line, capture;
while (ReadLine(out line, ref max)) {
while (ReadLine(out line, ref max))
{
capture = line;
actions.Add(() => Console.WriteLine(capture));
}
@ -96,16 +99,19 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -96,16 +99,19 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
Console.WriteLine("OutsideLoop");
var list = new List<int> { 1, 2, 3 };
var functions = new List<Func<int>>();
using (var e = list.GetEnumerator()) {
using (var e = list.GetEnumerator())
{
int val; // declared outside loop
// The decompiler cannot convert this to a foreach-loop without
// changing the lambda capture semantics.
while (e.MoveNext()) {
while (e.MoveNext())
{
val = e.Current;
functions.Add(() => val);
}
}
foreach (var func in functions) {
foreach (var func in functions)
{
Console.WriteLine(func());
}
}
@ -115,13 +121,16 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -115,13 +121,16 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
Console.WriteLine("InsideLoop");
var list = new List<int> { 1, 2, 3 };
var functions = new List<Func<int>>();
using (var e = list.GetEnumerator()) {
while (e.MoveNext()) {
using (var e = list.GetEnumerator())
{
while (e.MoveNext())
{
int val = e.Current;
functions.Add(() => val);
}
}
foreach (var func in functions) {
foreach (var func in functions)
{
Console.WriteLine(func());
}
}
@ -134,11 +143,13 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -134,11 +143,13 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
int val; // declared outside loop
// The decompiler cannot convert this to a foreach-loop without
// changing the lambda capture semantics.
for (int i = 0; i < array.Length; ++i) {
for (int i = 0; i < array.Length; ++i)
{
val = array[i];
functions.Add(() => val);
}
foreach (var func in functions) {
foreach (var func in functions)
{
Console.WriteLine(func());
}
}
@ -151,12 +162,14 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -151,12 +162,14 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
int val; // declared outside loop
// The decompiler can convert this to a foreach-loop, but the 'val'
// variable must be declared outside.
for (int i = 0; i < array.Length; ++i) {
for (int i = 0; i < array.Length; ++i)
{
int element = array[i];
val = element * 2;
functions.Add(() => val);
}
foreach (var func in functions) {
foreach (var func in functions)
{
Console.WriteLine(func());
}
}
@ -166,12 +179,14 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -166,12 +179,14 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
Console.WriteLine("InsideLoopOverArray2:");
var functions = new List<Func<int>>();
var array = new int[] { 1, 2, 3 };
for (int i = 0; i < array.Length; ++i) {
for (int i = 0; i < array.Length; ++i)
{
int element = array[i];
int val = element * 2;
functions.Add(() => val);
}
foreach (var func in functions) {
foreach (var func in functions)
{
Console.WriteLine(func());
}
}
@ -187,13 +202,15 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -187,13 +202,15 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
{
Console.WriteLine("NotWhileDueToVariableInsideLoop:");
var functions = new List<Func<int>>();
while (true) {
while (true)
{
int v;
if ((v = GetVal()) == 0)
break;
functions.Add(() => v);
}
foreach (var f in functions) {
foreach (var f in functions)
{
Console.WriteLine(f());
}
}
@ -202,13 +219,15 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -202,13 +219,15 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
{
Console.WriteLine("NotDoWhileDueToVariableInsideLoop:");
var functions = new List<Func<int>>();
while (true) {
while (true)
{
int v = GetVal();
functions.Add(() => v);
if (v == 0)
break;
}
foreach (var f in functions) {
foreach (var f in functions)
{
Console.WriteLine(f());
}
}
@ -216,7 +235,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -216,7 +235,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
public static void Issue1936()
{
IEnumerable<object> outerCapture = null;
for (int i = 0; i < 10; i++) {
for (int i = 0; i < 10; i++)
{
int innerCapture = 0;
Action a = (delegate {
List<object> list = new List<object>();

6
ICSharpCode.Decompiler.Tests/TestCases/Correctness/Comparisons.cs

@ -54,8 +54,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -54,8 +54,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
static void TestFloatOp(string name, Func<float, float, bool> f)
{
float[] vals = { -1, 0, 3, float.PositiveInfinity, float.NaN };
for (int i = 0; i < vals.Length; i++) {
for (int j = 0; j < vals.Length; j++) {
for (int i = 0; i < vals.Length; i++)
{
for (int j = 0; j < vals.Length; j++)
{
Console.WriteLine("Float: {0} {1} {2:r} = {3}",
vals[i].ToString("r", CultureInfo.InvariantCulture),
name,

20
ICSharpCode.Decompiler.Tests/TestCases/Correctness/CompoundAssignment.cs

@ -53,8 +53,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -53,8 +53,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
int instanceField;
public int InstanceProperty
{
public int InstanceProperty {
get {
Console.WriteLine("In {0}.get_InstanceProperty", instanceNumber);
return instanceField;
@ -67,8 +66,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -67,8 +66,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
static int staticField;
public static int StaticProperty
{
public static int StaticProperty {
get {
Console.WriteLine("In get_StaticProperty");
return staticField;
@ -203,18 +201,24 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -203,18 +201,24 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
Console.WriteLine("Overflow:");
ByteProperty = 0;
ByteProperty = (byte)checked(ByteProperty + 300);
try {
try
{
ByteProperty = checked((byte)(ByteProperty + 300));
} catch (OverflowException) {
}
catch (OverflowException)
{
Console.WriteLine("Overflow OK");
}
ByteProperty = 200;
ByteProperty = (byte)checked(ByteProperty + 100);
ByteProperty = 201;
try {
try
{
ByteProperty = checked((byte)(ByteProperty + 100));
} catch (OverflowException) {
}
catch (OverflowException)
{
Console.WriteLine("Overflow OK");
}
}

56
ICSharpCode.Decompiler.Tests/TestCases/Correctness/ControlFlow.cs

@ -47,7 +47,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -47,7 +47,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
static void EmptyIf(string input, ref int result)
{
if (input.Contains("test")) {
if (input.Contains("test"))
{
}
result = result + 1;
Console.WriteLine("EmptyIf");
@ -55,9 +56,12 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -55,9 +56,12 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
static void NormalIf(string input, ref int result)
{
if (input.Contains("test")) {
if (input.Contains("test"))
{
Console.WriteLine("result");
} else {
}
else
{
Console.WriteLine("else");
}
result = result + 1;
@ -66,7 +70,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -66,7 +70,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
static void NormalIf2(string input, ref int result)
{
if (input.Contains("test")) {
if (input.Contains("test"))
{
Console.WriteLine("result");
}
result = result + 1;
@ -75,9 +80,12 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -75,9 +80,12 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
static void NormalIf3(string input, ref int result)
{
if (input.Contains("test")) {
if (input.Contains("test"))
{
Console.WriteLine("result");
} else {
}
else
{
Console.WriteLine("else");
}
result = result + 1;
@ -85,13 +93,17 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -85,13 +93,17 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
static void Test(string input, ref int result)
{
foreach (char c in input) {
foreach (char c in input)
{
Console.Write(c);
result = result + 1;
}
if (input.Contains("test")) {
if (input.Contains("test"))
{
Console.WriteLine("result");
} else {
}
else
{
Console.WriteLine("else");
}
}
@ -101,8 +113,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -101,8 +113,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
var tens = new[] { 10, 20, 30 };
var ones = new[] { 1, 2, 3 };
for (int i = 0; i < tens.Length; i++) {
for (int j = 0; j < ones.Length; j++) {
for (int i = 0; i < tens.Length; i++)
{
for (int j = 0; j < ones.Length; j++)
{
if (tens[i] + ones[j] == arg)
return i;
}
@ -114,7 +128,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -114,7 +128,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
static void ForeachWithAssignment(IEnumerable<int> inputs)
{
Console.WriteLine("ForeachWithAssignment");
foreach (int input in inputs) {
foreach (int input in inputs)
{
int i = input;
if (i < 10)
i *= 2;
@ -125,11 +140,13 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -125,11 +140,13 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
static void BreakUnlessContinue(bool b)
{
Console.WriteLine("BreakUnlessContinue({0})", b);
for (int i = 0; i < 5; i++) {
for (int i = 0; i < 5; i++)
{
if ((i % 3) == 0)
continue;
Console.WriteLine(i);
if (b) {
if (b)
{
Console.WriteLine("continuing");
continue;
}
@ -154,11 +171,16 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -154,11 +171,16 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
static string Issue1946()
{
string obj = "1";
try {
try
{
obj = "2";
} catch {
}
catch
{
obj = "3";
} finally {
}
finally
{
obj = "4";
}
return obj;

39
ICSharpCode.Decompiler.Tests/TestCases/Correctness/Conversions.cs

@ -19,6 +19,7 @@ @@ -19,6 +19,7 @@
// #include "../../../ICSharpCode.Decompiler/Util/CSharpPrimitiveCast.cs"
using System;
using ICSharpCode.Decompiler.Util;
namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
@ -115,16 +116,21 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -115,16 +116,21 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
static void RunTest(bool checkForOverflow)
{
string mode = checkForOverflow ? "checked" : "unchecked";
foreach (object input in inputValues) {
foreach (object input in inputValues)
{
string inputType = input.GetType().Name;
foreach (var targetType in targetTypes) {
try {
foreach (var targetType in targetTypes)
{
try
{
object result = CSharpPrimitiveCast.Cast(targetType, input, checkForOverflow);
Console.WriteLine("{0} ({1})({2}){3} = ({4}){5}", mode, targetType, inputType, input,
result.GetType().Name, result);
} catch (Exception ex) {
result.GetType().Name, result);
}
catch (Exception ex)
{
Console.WriteLine("{0} ({1})({2}){3} = {4}", mode, targetType, inputType, input,
ex.GetType().Name);
ex.GetType().Name);
}
}
}
@ -132,28 +138,31 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -132,28 +138,31 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
static object MM(sbyte c)
{
checked {
checked
{
return (UInt64)c;
}
}
static string ReadZeroTerminatedString (int length)
static string ReadZeroTerminatedString(int length)
{
int read = 0;
var buffer = new char [length];
var bytes = ReadBytes (length);
while (read < length) {
var current = bytes [read];
var buffer = new char[length];
var bytes = ReadBytes(length);
while (read < length)
{
var current = bytes[read];
if (current == 0)
break;
buffer [read++] = (char) current;
buffer[read++] = (char)current;
}
return new string (buffer, 0, read);
return new string(buffer, 0, read);
}
static byte[] ReadBytes(int length) {
static byte[] ReadBytes(int length)
{
return System.Text.Encoding.ASCII.GetBytes("Hello World!");
}
}

24
ICSharpCode.Decompiler.Tests/TestCases/Correctness/DeconstructionTests.cs

@ -194,10 +194,13 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -194,10 +194,13 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
public void NullReferenceException_Field_Deconstruction(out int a)
{
try {
try
{
AssignmentTargets t0 = null;
(t0.IntField, a) = GetSource<int, int>();
} catch (Exception ex) {
}
catch (Exception ex)
{
a = 0;
Console.WriteLine(ex.GetType().FullName);
}
@ -205,11 +208,14 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -205,11 +208,14 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
public void NullReferenceException_RefLocalReferencesField_Deconstruction(out int a)
{
try {
try
{
AssignmentTargets t0 = null;
ref int i = ref t0.IntField;
(i, a) = GetSource<int, int>();
} catch (Exception ex) {
}
catch (Exception ex)
{
a = 0;
Console.WriteLine(ex.GetType().FullName);
}
@ -217,10 +223,13 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -217,10 +223,13 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
public void NullReferenceException_RefLocalReferencesArrayElement_Deconstruction(out int a, int[] arr)
{
try {
try
{
ref int i = ref arr[0];
(i, a) = GetSource<int, int>();
} catch (Exception ex) {
}
catch (Exception ex)
{
a = 0;
Console.WriteLine(ex.GetType().FullName);
}
@ -238,7 +247,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -238,7 +247,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
public void DeconstructTupleListForEachSameVar(List<(string, string)> tuples)
{
Console.WriteLine("DeconstructTupleListForEachSameVar:");
foreach (var tuple in tuples) {
foreach (var tuple in tuples)
{
string a;
a = tuple.Item1;
a = tuple.Item2;

3
ICSharpCode.Decompiler.Tests/TestCases/Correctness/FloatingPointArithmetic.cs

@ -91,7 +91,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -91,7 +91,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
static void CxAssert(bool v)
{
if (!v) {
if (!v)
{
throw new InvalidOperationException();
}
}

60
ICSharpCode.Decompiler.Tests/TestCases/Correctness/InitializerTests.cs

@ -52,36 +52,30 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -52,36 +52,30 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
private class Data
{
public List<InitializerTests.MyEnum2> FieldList = new List<InitializerTests.MyEnum2>();
public InitializerTests.MyEnum a
{
public InitializerTests.MyEnum a {
get;
set;
}
public InitializerTests.MyEnum b
{
public InitializerTests.MyEnum b {
get;
set;
}
public List<InitializerTests.MyEnum2> PropertyList
{
public List<InitializerTests.MyEnum2> PropertyList {
get;
set;
}
public InitializerTests.Data MoreData
{
public InitializerTests.Data MoreData {
get;
set;
}
public InitializerTests.StructData NestedStruct
{
public InitializerTests.StructData NestedStruct {
get;
set;
}
public InitializerTests.Data this[int i]
{
public InitializerTests.Data this[int i] {
get {
return null;
}
@ -99,14 +93,12 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -99,14 +93,12 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
private struct StructData
{
public int Field;
public int Property
{
public int Property {
get;
set;
}
public InitializerTests.Data MoreData
{
public InitializerTests.Data MoreData {
get;
set;
}
@ -191,8 +183,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -191,8 +183,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
public static void ObjectInitializer()
{
InitializerTests.X(InitializerTests.Y(), new InitializerTests.Data
{
InitializerTests.X(InitializerTests.Y(), new InitializerTests.Data {
a = InitializerTests.MyEnum.a
});
}
@ -206,8 +197,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -206,8 +197,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
public static void ObjectInitializerAssignCollectionToField()
{
InitializerTests.X(InitializerTests.Y(), new InitializerTests.Data
{
InitializerTests.X(InitializerTests.Y(), new InitializerTests.Data {
a = InitializerTests.MyEnum.a,
FieldList = new List<InitializerTests.MyEnum2>
{
@ -219,8 +209,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -219,8 +209,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
public static void ObjectInitializerAddToCollectionInField()
{
InitializerTests.X(InitializerTests.Y(), new InitializerTests.Data
{
InitializerTests.X(InitializerTests.Y(), new InitializerTests.Data {
a = InitializerTests.MyEnum.a,
FieldList =
{
@ -232,8 +221,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -232,8 +221,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
public static void ObjectInitializerAssignCollectionToProperty()
{
InitializerTests.X(InitializerTests.Y(), new InitializerTests.Data
{
InitializerTests.X(InitializerTests.Y(), new InitializerTests.Data {
a = InitializerTests.MyEnum.a,
PropertyList = new List<InitializerTests.MyEnum2>
{
@ -245,8 +233,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -245,8 +233,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
public static void ObjectInitializerAddToCollectionInProperty()
{
InitializerTests.X(InitializerTests.Y(), new InitializerTests.Data
{
InitializerTests.X(InitializerTests.Y(), new InitializerTests.Data {
a = InitializerTests.MyEnum.a,
PropertyList =
{
@ -258,8 +245,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -258,8 +245,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
public static void ObjectInitializerWithInitializationOfNestedObjects()
{
InitializerTests.X(InitializerTests.Y(), new InitializerTests.Data
{
InitializerTests.X(InitializerTests.Y(), new InitializerTests.Data {
MoreData =
{
a = InitializerTests.MyEnum.a,
@ -342,8 +328,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -342,8 +328,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
public static void StructInitializer_DefaultConstructor()
{
InitializerTests.X(InitializerTests.Y(), new InitializerTests.StructData
{
InitializerTests.X(InitializerTests.Y(), new InitializerTests.StructData {
Field = 1,
Property = 2
});
@ -359,8 +344,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -359,8 +344,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
public static void StructInitializer_ExplicitConstructor()
{
InitializerTests.X(InitializerTests.Y(), new InitializerTests.StructData(0)
{
InitializerTests.X(InitializerTests.Y(), new InitializerTests.StructData(0) {
Field = 1,
Property = 2
});
@ -368,8 +352,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -368,8 +352,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
public static void StructInitializerWithInitializationOfNestedObjects()
{
InitializerTests.X(InitializerTests.Y(), new InitializerTests.StructData
{
InitializerTests.X(InitializerTests.Y(), new InitializerTests.StructData {
MoreData =
{
a = InitializerTests.MyEnum.a,
@ -384,10 +367,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -384,10 +367,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
public static void StructInitializerWithinObjectInitializer()
{
InitializerTests.X(InitializerTests.Y(), new InitializerTests.Data
{
NestedStruct = new InitializerTests.StructData(2)
{
InitializerTests.X(InitializerTests.Y(), new InitializerTests.Data {
NestedStruct = new InitializerTests.StructData(2) {
Field = 1,
Property = 2
}
@ -435,7 +416,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -435,7 +416,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
int num = 0;
for (int i = 0; i < 2; i++) {
for (int i = 0; i < 2; i++)
{
if (num < 10)
items.SetItem(num, Item(string.Empty, new Data { Obj = null }));
}

15
ICSharpCode.Decompiler.Tests/TestCases/Correctness/LINQRaytracer.cs

@ -1,8 +1,8 @@ @@ -1,8 +1,8 @@
// This test case is taken from https://blogs.msdn.microsoft.com/lukeh/2007/10/01/taking-linq-to-objects-to-extremes-a-fully-linqified-raytracer/
using System.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
namespace RayTracer
{
@ -333,13 +333,17 @@ namespace RayTracer @@ -333,13 +333,17 @@ namespace RayTracer
Vector eo = Vector.Minus(Center, ray.Start);
double v = Vector.Dot(eo, ray.Dir);
double dist;
if (v < 0) {
if (v < 0)
{
dist = 0;
} else {
}
else
{
double disc = Math.Pow(Radius, 2) - (Vector.Dot(eo, eo) - Math.Pow(v, 2));
dist = disc < 0 ? 0 : v - Math.Sqrt(disc);
}
if (dist == 0) return null;
if (dist == 0)
return null;
return new ISect() {
Thing = this,
Ray = ray,
@ -361,7 +365,8 @@ namespace RayTracer @@ -361,7 +365,8 @@ namespace RayTracer
public override ISect Intersect(Ray ray)
{
double denom = Vector.Dot(Norm, ray.Dir);
if (denom > 0) return null;
if (denom > 0)
return null;
return new ISect() {
Thing = this,
Ray = ray,

99
ICSharpCode.Decompiler.Tests/TestCases/Correctness/Loops.cs

@ -41,7 +41,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -41,7 +41,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
public bool MoveNext()
{
if (next) {
if (next)
{
next = false;
return true;
}
@ -87,7 +88,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -87,7 +88,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
{
int x, y;
Console.WriteLine("before for");
for (x = y = 0; x < 10; x++) {
for (x = y = 0; x < 10; x++)
{
y++;
Console.WriteLine("x = " + x + ", y = " + y);
}
@ -97,11 +99,13 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -97,11 +99,13 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
public static void DoubleForEachWithSameVariable(IEnumerable<string> enumerable)
{
Console.WriteLine("DoubleForEachWithSameVariable:");
foreach (string current in enumerable) {
foreach (string current in enumerable)
{
Console.WriteLine(current.ToLower());
}
Console.WriteLine("after first loop");
foreach (string current in enumerable) {
foreach (string current in enumerable)
{
Console.WriteLine(current.ToUpper());
}
Console.WriteLine("after second loop");
@ -111,8 +115,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -111,8 +115,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
{
Console.WriteLine("ForeachWithNameCollision:");
int current;
using (IEnumerator<int> enumerator = inputs.GetEnumerator()) {
while (enumerator.MoveNext()) {
using (IEnumerator<int> enumerator = inputs.GetEnumerator())
{
while (enumerator.MoveNext())
{
current = enumerator.Current;
Console.WriteLine(current);
}
@ -125,8 +131,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -125,8 +131,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
{
Console.WriteLine("ForeachExceptForContinuedUse");
int num = 0;
using (IEnumerator<int> enumerator = inputs.GetEnumerator()) {
while (enumerator.MoveNext()) {
using (IEnumerator<int> enumerator = inputs.GetEnumerator())
{
while (enumerator.MoveNext())
{
num = enumerator.Current;
Console.WriteLine(num);
}
@ -138,15 +146,20 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -138,15 +146,20 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
{
Console.WriteLine("NonGenericForeachWithReturnFallback:");
IEnumerator enumerator = e.GetEnumerator();
try {
try
{
Console.WriteLine("MoveNext");
if (enumerator.MoveNext()) {
if (enumerator.MoveNext())
{
object current = enumerator.Current;
Console.WriteLine("current: " + current);
}
} finally {
}
finally
{
IDisposable disposable = enumerator as IDisposable;
if (disposable != null) {
if (disposable != null)
{
disposable.Dispose();
}
}
@ -156,7 +169,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -156,7 +169,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
public static object NonGenericForeachWithReturn(IEnumerable enumerable)
{
Console.WriteLine("NonGenericForeachWithReturn:");
foreach (var obj in enumerable) {
foreach (var obj in enumerable)
{
Console.WriteLine("return: " + obj);
return obj;
}
@ -168,7 +182,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -168,7 +182,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
public static int? ForeachWithReturn(IEnumerable<int> enumerable)
{
Console.WriteLine("ForeachWithReturn:");
foreach (var obj in enumerable) {
foreach (var obj in enumerable)
{
Console.WriteLine("return: " + obj);
return obj;
}
@ -180,7 +195,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -180,7 +195,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
public static void ForeachWithRefUsage(List<int> items)
{
Console.WriteLine("ForeachWithRefUsage:");
foreach (var item in items) {
foreach (var item in items)
{
var itemToChange = item;
Console.WriteLine("item: " + item);
Operation(ref itemToChange);
@ -191,7 +207,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -191,7 +207,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
public static T FirstOrDefault<T>(IEnumerable<T> items)
{
T result = default(T);
foreach (T item in items) {
foreach (T item in items)
{
result = item;
break;
}
@ -202,8 +219,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -202,8 +219,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
{
Console.WriteLine("NoForeachDueToMultipleCurrentAccess:");
T result = default(T);
using (IEnumerator<T> enumerator = items.GetEnumerator()) {
while (enumerator.MoveNext()) {
using (IEnumerator<T> enumerator = items.GetEnumerator())
{
while (enumerator.MoveNext())
{
result = enumerator.Current;
Console.WriteLine("result: " + result);
}
@ -214,8 +233,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -214,8 +233,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
public static T NoForeachCallWithSideEffect<T>(CustomClassEnumeratorWithIDisposable<T> items)
{
Console.WriteLine("NoForeachCallWithSideEffect:");
using (CustomClassEnumeratorWithIDisposable<T> enumerator = items.GetEnumerator()) {
while (enumerator.MoveNext()) {
using (CustomClassEnumeratorWithIDisposable<T> enumerator = items.GetEnumerator())
{
while (enumerator.MoveNext())
{
T result = enumerator.Current;
}
return CallWithSideEffect<T>();
@ -231,19 +252,25 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -231,19 +252,25 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
static void LoopWithGotoRepeat()
{
Console.WriteLine("LoopWithGotoRepeat:");
try {
try
{
REPEAT:
Console.WriteLine("after repeat label");
while (GetBool("Loop condition")) {
if (GetBool("if1")) {
if (GetBool("if3")) {
while (GetBool("Loop condition"))
{
if (GetBool("if1"))
{
if (GetBool("if3"))
{
goto REPEAT;
}
break;
}
}
Console.WriteLine("after loop");
} finally {
}
finally
{
Console.WriteLine("finally");
}
Console.WriteLine("after finally");
@ -252,10 +279,12 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -252,10 +279,12 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
private static int LoopFollowedByIf()
{
int num = 0;
while (num == 0) {
while (num == 0)
{
num++;
}
if (num == 0) {
if (num == 0)
{
return -1;
}
return num;
@ -263,9 +292,11 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -263,9 +292,11 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
static void Issue1392ForWithNestedSwitchPlusGoto()
{
for (int i = 0; i < 100; i++) {
for (int i = 0; i < 100; i++)
{
again:
switch (i) {
switch (i)
{
case 10:
Console.WriteLine("10");
break;
@ -281,13 +312,17 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -281,13 +312,17 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
private static void NoForeachDueToVariableAssignment()
{
try {
try
{
int[] array = new int[] { 1, 2, 3 };
for (int i = 0; i < array.Length; i++) {
for (int i = 0; i < array.Length; i++)
{
Console.WriteLine(array[i]);
array = null;
}
} catch (Exception ex) {
}
catch (Exception ex)
{
Console.WriteLine(ex.GetType() + ": " + ex.Message);
}
}

202
ICSharpCode.Decompiler.Tests/TestCases/Correctness/MiniJSON.cs

@ -9,30 +9,32 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -9,30 +9,32 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
// taken from https://github.com/Jackyjjc/MiniJSON.cs
// Copyright (c) 2013 Calvin Rien.
// Licensed under the MIT LICENSE.
public class MiniJSONTest {
public static void Main(string[] args) {
var jsonString = "{ \"array\": [1.44,2,3], " +
"\"object\": {\"key1\":\"value1\", \"key2\":256}, " +
"\"string\": \"The quick brown fox \\\"jumps\\\" over the lazy dog \", " +
"\"unicode\": \"\\u3041 Men\u00fa sesi\u00f3n\", " +
"\"int\": 65536, " +
"\"float\": 3.1415926, " +
"\"bool\": true, " +
"\"null\": null }";
var dict = Json.Deserialize(jsonString) as Dictionary<string,object>;
Console.WriteLine("deserialized: " + dict.GetType());
Console.WriteLine("dict['array'][0]: " + ((List<object>) dict["array"])[0]);
Console.WriteLine("dict['string']: " + (string) dict["string"]);
Console.WriteLine("dict['float']: " + (double) dict["float"]); // floats come out as doubles
Console.WriteLine("dict['int']: " + (long) dict["int"]); // ints come out as longs
Console.WriteLine("dict['unicode']: " + (string) dict["unicode"]);
var str = Json.Serialize(dict);
Console.WriteLine("serialized: " + str);
}
public class MiniJSONTest
{
public static void Main(string[] args)
{
var jsonString = "{ \"array\": [1.44,2,3], " +
"\"object\": {\"key1\":\"value1\", \"key2\":256}, " +
"\"string\": \"The quick brown fox \\\"jumps\\\" over the lazy dog \", " +
"\"unicode\": \"\\u3041 Men\u00fa sesi\u00f3n\", " +
"\"int\": 65536, " +
"\"float\": 3.1415926, " +
"\"bool\": true, " +
"\"null\": null }";
var dict = Json.Deserialize(jsonString) as Dictionary<string, object>;
Console.WriteLine("deserialized: " + dict.GetType());
Console.WriteLine("dict['array'][0]: " + ((List<object>)dict["array"])[0]);
Console.WriteLine("dict['string']: " + (string)dict["string"]);
Console.WriteLine("dict['float']: " + (double)dict["float"]); // floats come out as doubles
Console.WriteLine("dict['int']: " + (long)dict["int"]); // ints come out as longs
Console.WriteLine("dict['unicode']: " + (string)dict["unicode"]);
var str = Json.Serialize(dict);
Console.WriteLine("serialized: " + str);
}
}
public static class Json
@ -45,7 +47,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -45,7 +47,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
public static object Deserialize(string json)
{
// save the string for debug information
if (json == null) {
if (json == null)
{
return null;
}
@ -93,7 +96,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -93,7 +96,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
public static object Parse(string jsonString)
{
using (var instance = new Parser(jsonString)) {
using (var instance = new Parser(jsonString))
{
return instance.ParseValue();
}
}
@ -112,8 +116,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -112,8 +116,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
json.Read();
// {
while (true) {
switch (NextToken) {
while (true)
{
switch (NextToken)
{
case TOKEN.NONE:
return null;
case TOKEN.COMMA:
@ -123,12 +129,14 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -123,12 +129,14 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
case TOKEN.STRING:
// name
string name = ParseString();
if (name == null) {
if (name == null)
{
return null;
}
// :
if (NextToken != TOKEN.COLON) {
if (NextToken != TOKEN.COLON)
{
return null;
}
// ditch the colon
@ -156,10 +164,12 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -156,10 +164,12 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
// [
var parsing = true;
while (parsing) {
while (parsing)
{
TOKEN nextToken = NextToken;
switch (nextToken) {
switch (nextToken)
{
case TOKEN.NONE:
return null;
case TOKEN.COMMA:
@ -187,7 +197,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -187,7 +197,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
object ParseByToken(TOKEN token)
{
switch (token) {
switch (token)
{
case TOKEN.STRING:
return ParseString();
case TOKEN.NUMBER:
@ -216,26 +227,31 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -216,26 +227,31 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
json.Read();
bool parsing = true;
while (parsing) {
while (parsing)
{
if (json.Peek() == -1) {
if (json.Peek() == -1)
{
parsing = false;
break;
}
c = NextChar;
switch (c) {
switch (c)
{
case '"':
parsing = false;
break;
case '\\':
if (json.Peek() == -1) {
if (json.Peek() == -1)
{
parsing = false;
break;
}
c = NextChar;
switch (c) {
switch (c)
{
case '"':
case '\\':
case '/':
@ -259,7 +275,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -259,7 +275,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
case 'u':
var hex = new char[4];
for (int i = 0; i < 4; i++) {
for (int i = 0; i < 4; i++)
{
hex[i] = NextChar;
if (!IsHexDigit(hex[i]))
return null;
@ -282,7 +299,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -282,7 +299,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
{
string number = NextWord;
if (number.IndexOf('.') == -1 && number.IndexOf('E') == -1 && number.IndexOf('e') == -1) {
if (number.IndexOf('.') == -1 && number.IndexOf('E') == -1 && number.IndexOf('e') == -1)
{
long parsedInt;
Int64.TryParse(number, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out parsedInt);
return parsedInt;
@ -295,10 +313,12 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -295,10 +313,12 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
void EatWhitespace()
{
while (Char.IsWhiteSpace(PeekChar)) {
while (Char.IsWhiteSpace(PeekChar))
{
json.Read();
if (json.Peek() == -1) {
if (json.Peek() == -1)
{
break;
}
}
@ -320,10 +340,12 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -320,10 +340,12 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
get {
StringBuilder word = new StringBuilder();
while (!IsWordBreak(PeekChar)) {
while (!IsWordBreak(PeekChar))
{
word.Append(NextChar);
if (json.Peek() == -1) {
if (json.Peek() == -1)
{
break;
}
}
@ -336,11 +358,13 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -336,11 +358,13 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
get {
EatWhitespace();
if (json.Peek() == -1) {
if (json.Peek() == -1)
{
return TOKEN.NONE;
}
switch (PeekChar) {
switch (PeekChar)
{
case '{':
return TOKEN.CURLY_OPEN;
case '}':
@ -372,7 +396,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -372,7 +396,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
return TOKEN.NUMBER;
}
switch (NextWord) {
switch (NextWord)
{
case "false":
return TOKEN.FALSE;
case "true":
@ -420,19 +445,32 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -420,19 +445,32 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
IDictionary asDict;
string asStr;
if (value == null) {
if (value == null)
{
builder.Append("null");
} else if ((asStr = value as string) != null) {
}
else if ((asStr = value as string) != null)
{
SerializeString(asStr);
} else if (value is bool) {
}
else if (value is bool)
{
builder.Append((bool)value ? "true" : "false");
} else if ((asList = value as IList) != null) {
}
else if ((asList = value as IList) != null)
{
SerializeArray(asList);
} else if ((asDict = value as IDictionary) != null) {
}
else if ((asDict = value as IDictionary) != null)
{
SerializeObject(asDict);
} else if (value is char) {
}
else if (value is char)
{
SerializeString(new string((char)value, 1));
} else {
}
else
{
SerializeOther(value);
}
}
@ -443,8 +481,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -443,8 +481,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
builder.Append('{');
foreach (object e in obj.Keys) {
if (!first) {
foreach (object e in obj.Keys)
{
if (!first)
{
builder.Append(',');
}
@ -465,9 +505,11 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -465,9 +505,11 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
bool first = true;
for (int i = 0; i < anArray.Count; i++) {
for (int i = 0; i < anArray.Count; i++)
{
object obj = anArray[i];
if (!first) {
if (!first)
{
builder.Append(',');
}
@ -484,9 +526,11 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -484,9 +526,11 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
builder.Append('\"');
char[] charArray = str.ToCharArray();
for (int i = 0; i < charArray.Length; i++) {
for (int i = 0; i < charArray.Length; i++)
{
char c = charArray[i];
switch (c) {
switch (c)
{
case '"':
builder.Append("\\\"");
break;
@ -510,9 +554,12 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -510,9 +554,12 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
break;
default:
int codepoint = Convert.ToInt32(c);
if ((codepoint >= 32) && (codepoint <= 126)) {
if ((codepoint >= 32) && (codepoint <= 126))
{
builder.Append(c);
} else {
}
else
{
builder.Append("\\u");
builder.Append(codepoint.ToString("x4"));
}
@ -528,21 +575,28 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -528,21 +575,28 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
// NOTE: decimals lose precision during serialization.
// They always have, I'm just letting you know.
// Previously floats and doubles lost precision too.
if (value is float) {
if (value is float)
{
builder.Append(((float)value).ToString("R", System.Globalization.CultureInfo.InvariantCulture));
} else if (value is int
|| value is uint
|| value is long
|| value is sbyte
|| value is byte
|| value is short
|| value is ushort
|| value is ulong) {
}
else if (value is int
|| value is uint
|| value is long
|| value is sbyte
|| value is byte
|| value is short
|| value is ushort
|| value is ulong)
{
builder.Append(value);
} else if (value is double
|| value is decimal) {
}
else if (value is double
|| value is decimal)
{
builder.Append(Convert.ToDouble(value).ToString("R", System.Globalization.CultureInfo.InvariantCulture));
} else {
}
else
{
SerializeString(value.ToString());
}
}

49
ICSharpCode.Decompiler.Tests/TestCases/Correctness/NullableTests.cs

@ -103,18 +103,24 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -103,18 +103,24 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
static void FieldAccessOrderOfEvaluation(NullableTests c)
{
Console.WriteLine("GetInt, then NRE:");
try {
try
{
c.intField = GetValue<int>();
} catch (Exception ex) {
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
Console.WriteLine("NRE before GetInt:");
try {
try
{
#if CS60
ref int i = ref c.intField;
i = GetValue<int>();
#endif
} catch (Exception ex) {
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
@ -124,18 +130,24 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -124,18 +130,24 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
static void FieldAccessOrderOfEvaluationWithStruct(NullableTests c)
{
Console.WriteLine("GetInt, then NRE (with struct):");
try {
try
{
c.structField.IntField = GetValue<int>();
} catch (Exception ex) {
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
Console.WriteLine("NRE before GetInt (with struct):");
try {
try
{
#if CS60
ref SomeStruct s = ref c.structField;
s.IntField = GetValue<int>();
#endif
} catch (Exception ex) {
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
@ -155,27 +167,36 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -155,27 +167,36 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
static void ArrayAccessOrderOfEvaluation()
{
Console.WriteLine("GetArray direct:");
try {
try
{
GetArray<int>()[GetIndex()] = GetValue<int>();
} catch (Exception ex) {
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
Console.WriteLine("GetArray with ref:");
try {
try
{
#if CS60
ref int elem = ref GetArray<int>()[GetIndex()];
elem = GetValue<int>();
#endif
} catch (Exception ex) {
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
Console.WriteLine("GetArray direct with value-type:");
try {
try
{
// This line is mis-compiled by legacy csc:
// with the legacy compiler the NRE is thrown before the GetValue call;
// with Roslyn the NRE is thrown after the GetValue call.
GetArray<TimeSpan>()[GetIndex()] = GetValue<TimeSpan>();
} catch (Exception ex) {
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}

3
ICSharpCode.Decompiler.Tests/TestCases/Correctness/OverloadResolution.cs

@ -100,7 +100,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -100,7 +100,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
static void TestCallIssue1281(params object[] args)
{
Console.Write("TestCallIssue1281: count = " + args.Length + ": ");
foreach (var arg in args) {
foreach (var arg in args)
{
Console.Write(arg);
Console.Write(", ");
}

8
ICSharpCode.Decompiler.Tests/TestCases/Correctness/PropertiesAndEvents.cs

@ -21,16 +21,14 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -21,16 +21,14 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
{
int thisValue;
public int this[int i]
{
public int this[int i] {
get { Console.WriteLine("get_this({0})", i); return i * i; }
set { Console.WriteLine("set_this({0}, {1})", i, value); thisValue = value; }
set { Console.WriteLine("set_this({0}, {1})", i, value); thisValue = value; }
}
public string AutoProp { get; set; }
public double PISquare
{
public double PISquare {
get { Console.WriteLine("get_PISquare"); return Math.Pow(Math.PI, 2); }
}
}

69
ICSharpCode.Decompiler.Tests/TestCases/Correctness/Switch.cs

@ -41,7 +41,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -41,7 +41,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
static void TestCase<T>(Func<T, string> target, params T[] args)
{
foreach (var arg in args) {
foreach (var arg in args)
{
Console.WriteLine(target(arg));
}
}
@ -49,26 +50,40 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -49,26 +50,40 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
public static string SparseIntegerSwitch(int i)
{
Console.WriteLine("SparseIntegerSwitch: " + i);
switch (i) {
case -10000000: return "-10 mln";
case -100: return "-hundred";
case -1: return "-1";
case 0: return "0";
case 1: return "1";
case 2: return "2";
case 4: return "4";
case 100: return "hundred";
case 10000: return "ten thousand";
case 10001: return "ten thousand and one";
case int.MaxValue: return "int.MaxValue";
default: return "something else";
switch (i)
{
case -10000000:
return "-10 mln";
case -100:
return "-hundred";
case -1:
return "-1";
case 0:
return "0";
case 1:
return "1";
case 2:
return "2";
case 4:
return "4";
case 100:
return "hundred";
case 10000:
return "ten thousand";
case 10001:
return "ten thousand and one";
case int.MaxValue:
return "int.MaxValue";
default:
return "something else";
}
}
public static string ShortSwitchOverString(string text)
{
Console.WriteLine("ShortSwitchOverString: " + text);
switch (text) {
switch (text)
{
case "First case":
return "Text";
default:
@ -79,7 +94,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -79,7 +94,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
public static string ShortSwitchOverString2(string text)
{
Console.WriteLine("ShortSwitchOverString2: " + text);
switch (text) {
switch (text)
{
case "First case":
return "Text1";
case "Second case":
@ -94,7 +110,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -94,7 +110,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
public static string ShortSwitchOverStringNoExplicitDefault(string text)
{
Console.WriteLine("ShortSwitchOverStringNoExplicitDefault: " + text);
switch (text) {
switch (text)
{
case "First case":
return "Text1";
case "Second case":
@ -108,7 +125,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -108,7 +125,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
public static string SwitchOverString1(string text)
{
Console.WriteLine("SwitchOverString1: " + text);
switch (text) {
switch (text)
{
case "First case":
return "Text1";
case "Second case":
@ -132,7 +150,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -132,7 +150,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
public static string SwitchOverString2()
{
Console.WriteLine("SwitchOverString2:");
switch (Environment.UserName) {
switch (Environment.UserName)
{
case "First case":
return "Text1";
case "Second case":
@ -163,7 +182,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -163,7 +182,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
public static string SwitchOverBool(bool b)
{
Console.WriteLine("SwitchOverBool: " + b);
switch (b) {
switch (b)
{
case true:
return bool.TrueString;
case false:
@ -178,8 +198,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -178,8 +198,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
public static void SwitchInLoop(int i)
{
Console.WriteLine("SwitchInLoop: " + i);
while (true) {
switch (i) {
while (true)
{
switch (i)
{
case 1:
Console.WriteLine("one");
break;
@ -204,7 +226,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -204,7 +226,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
public static void SwitchWithGoto(int i)
{
Console.WriteLine("SwitchWithGoto: " + i);
switch (i) {
switch (i)
{
case 1:
Console.WriteLine("one");
goto default;

10
ICSharpCode.Decompiler.Tests/TestCases/Correctness/UndocumentedExpressions.cs

@ -38,12 +38,16 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -38,12 +38,16 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
ArgIterator argIterator = new ArgIterator(__arglist);
Console.WriteLine("Called with {0} arguments", argIterator.GetRemainingCount());
int pos = 0;
while (argIterator.GetRemainingCount() > 0) {
while (argIterator.GetRemainingCount() > 0)
{
TypedReference tr = argIterator.GetNextArg();
object val;
try {
try
{
val = __refvalue(tr, object);
} catch (Exception ex) {
}
catch (Exception ex)
{
val = ex.GetType().Name;
}
Console.WriteLine("{0} : {1} = {2}", pos++, __reftype(tr).Name, val);

6
ICSharpCode.Decompiler.Tests/TestCases/Correctness/UnsafeCode.cs

@ -36,7 +36,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -36,7 +36,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
public unsafe int MultipleExitsOutOfFixedBlock(int[] arr)
{
fixed (int* ptr = &arr[0]) {
fixed (int* ptr = &arr[0])
{
if (*ptr < 0)
return *ptr;
if (*ptr == 21)
@ -52,7 +53,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -52,7 +53,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
public unsafe void FixMultipleStrings(string text)
{
fixed (char* ptr = text, userName = Environment.UserName, ptr2 = text) {
fixed (char* ptr = text, userName = Environment.UserName, ptr2 = text)
{
*ptr = 'c';
*userName = 'd';
*ptr2 = 'e';

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

@ -57,7 +57,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -57,7 +57,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
Console.WriteLine("before using");
// Mono has a compiler bug and introduces an assembly reference to [gmcs] here...
#if !MCS
using (null) {
using (null)
{
Console.WriteLine("using (null)");
}
#endif
@ -67,9 +68,12 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -67,9 +68,12 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
public static void NoUsingDueToAssignment()
{
PrintOnDispose printOnDispose = new PrintOnDispose("Wrong");
try {
try
{
printOnDispose = new PrintOnDispose("Correct");
} finally {
}
finally
{
printOnDispose.Dispose();
}
}
@ -77,11 +81,15 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -77,11 +81,15 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
public static void NoUsingDueToAssignment2()
{
PrintOnDispose printOnDispose = new PrintOnDispose("NoUsing(): Wrong");
try {
try
{
printOnDispose = new PrintOnDispose("NoUsing(): Correct");
} finally {
}
finally
{
IDisposable disposable = (object)printOnDispose as IDisposable;
if (disposable != null) {
if (disposable != null)
{
disposable.Dispose();
}
}
@ -95,12 +103,16 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -95,12 +103,16 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
public static void NoUsingDueToByRefCall()
{
PrintOnDispose printOnDispose = new PrintOnDispose("NoUsingDueToByRefCall(): Wrong");
try {
try
{
Console.WriteLine("NoUsingDueToByRefCall");
Clear(ref printOnDispose);
} finally {
}
finally
{
IDisposable disposable = (object)printOnDispose as IDisposable;
if (disposable != null) {
if (disposable != null)
{
disposable.Dispose();
}
}
@ -110,11 +122,15 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -110,11 +122,15 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
{
var obj = new System.IO.StringWriter();
IDisposable disposable;
try {
try
{
obj.WriteLine("NoUsingDueToContinuedDisposableUse");
} finally {
}
finally
{
disposable = (object)obj as IDisposable;
if (disposable != null) {
if (disposable != null)
{
disposable.Dispose();
}
}
@ -124,11 +140,15 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -124,11 +140,15 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
public static void ContinuedObjectUse()
{
var obj = new System.IO.StringWriter();
try {
try
{
obj.WriteLine("ContinuedObjectUse");
} finally {
}
finally
{
IDisposable disposable = (object)obj as IDisposable;
if (disposable != null) {
if (disposable != null)
{
disposable.Dispose();
}
}
@ -141,11 +161,15 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -141,11 +161,15 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
obj.Write("VariableAlreadyUsedBefore - 1");
Console.WriteLine(obj);
obj = new System.IO.StringWriter();
try {
try
{
obj.WriteLine("VariableAlreadyUsedBefore - 2");
} finally {
}
finally
{
IDisposable disposable = (object)obj as IDisposable;
if (disposable != null) {
if (disposable != null)
{
disposable.Dispose();
}
}
@ -154,11 +178,15 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -154,11 +178,15 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
public static void UsingObject()
{
object obj = new object();
try {
try
{
Console.WriteLine("UsingObject: {0}", obj);
} finally {
}
finally
{
IDisposable disposable = obj as IDisposable;
if (disposable != null) {
if (disposable != null)
{
disposable.Dispose();
}
}

19
ICSharpCode.Decompiler.Tests/TestCases/Correctness/ValueTypeCall.cs

@ -145,7 +145,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -145,7 +145,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
static void Using1()
{
Console.WriteLine("Using:");
using (var x = new MutValueType()) {
using (var x = new MutValueType())
{
x.Increment();
}
}
@ -154,9 +155,12 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -154,9 +155,12 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
{
Console.WriteLine("Not using:");
var y = new MutValueType();
try {
try
{
y.Increment();
} finally {
}
finally
{
MutValueType x = y;
x.Dispose();
}
@ -166,7 +170,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -166,7 +170,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
{
Console.WriteLine("Using with variable declared outside:");
MutValueType z;
using (z = new MutValueType()) {
using (z = new MutValueType())
{
z.Increment();
}
}
@ -190,7 +195,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -190,7 +195,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
static void ForEach1(List<MutValueType> list)
{
Console.WriteLine("ForEach1:");
foreach (var val in list) {
foreach (var val in list)
{
val.Increment();
val.Increment();
}
@ -200,7 +206,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -200,7 +206,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
static void ForEachArray1(MutValueType[] list)
{
Console.WriteLine("ForEachArray1:");
foreach (var val in list) {
foreach (var val in list)
{
val.Increment();
val.Increment();
}

228
ICSharpCode.Decompiler.Tests/TestCases/Correctness/YieldReturn.cs

@ -47,9 +47,12 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -47,9 +47,12 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
Print("YieldBreakInTryCatchInTryFinally", YieldBreakInTryCatchInTryFinally().GetEnumerator());
Print("YieldBreakInTryFinallyInTryFinally(false)", YieldBreakInTryFinallyInTryFinally(false).GetEnumerator());
Print("YieldBreakInTryFinallyInTryFinally(true)", YieldBreakInTryFinallyInTryFinally(true).GetEnumerator());
try {
try
{
Print("UnconditionalThrowInTryFinally()", UnconditionalThrowInTryFinally().GetEnumerator());
} catch (Exception ex) {
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
Print("NestedTryFinallyStartingOnSamePosition", NestedTryFinallyStartingOnSamePosition().GetEnumerator());
@ -69,7 +72,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -69,7 +72,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
internal static void Print<T>(string name, IEnumerator<T> enumerator)
{
Console.WriteLine(name + ": Test start");
while (enumerator.MoveNext()) {
while (enumerator.MoveNext())
{
Console.WriteLine(name + ": " + enumerator.Current);
}
}
@ -112,7 +116,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -112,7 +116,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
public static IEnumerable<int> YieldReturnInLoop()
{
for (int i = 0; i < 100; i++) {
for (int i = 0; i < 100; i++)
{
yield return i;
}
}
@ -120,9 +125,12 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -120,9 +125,12 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
public static IEnumerable<int> YieldReturnWithTryFinally()
{
yield return 0;
try {
try
{
yield return 1;
} finally {
}
finally
{
Console.WriteLine("Finally!");
}
yield return 2;
@ -130,14 +138,16 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -130,14 +138,16 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
public static IEnumerable<int> YieldReturnInLock1(object o)
{
lock (o) {
lock (o)
{
yield return 1;
}
}
public static IEnumerable<int> YieldReturnInLock2(object o)
{
lock (o) {
lock (o)
{
yield return 1;
o = null;
yield return 2;
@ -149,28 +159,35 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -149,28 +159,35 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
Console.WriteLine("Start of method - 1");
yield return "Start of method";
Console.WriteLine("Start of method - 2");
try {
try
{
Console.WriteLine("Within outer try - 1");
yield return "Within outer try";
Console.WriteLine("Within outer try - 2");
try {
try
{
Console.WriteLine("Within inner try - 1");
yield return "Within inner try";
Console.WriteLine("Within inner try - 2");
if (breakInMiddle) {
if (breakInMiddle)
{
Console.WriteLine("Breaking...");
yield break;
}
Console.WriteLine("End of inner try - 1");
yield return "End of inner try";
Console.WriteLine("End of inner try - 2");
} finally {
}
finally
{
Console.WriteLine("Inner Finally");
}
Console.WriteLine("End of outer try - 1");
yield return "End of outer try";
Console.WriteLine("End of outer try - 2");
} finally {
}
finally
{
Console.WriteLine("Outer Finally");
}
Console.WriteLine("End of method - 1");
@ -181,11 +198,15 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -181,11 +198,15 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
public static IEnumerable<string> YieldReturnWithTwoNonNestedFinallyBlocks(IEnumerable<string> input)
{
// outer try-finally block
foreach (string line in input) {
foreach (string line in input)
{
// nested try-finally block
try {
try
{
yield return line;
} finally {
}
finally
{
Console.WriteLine("Processed " + line);
}
}
@ -196,21 +217,24 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -196,21 +217,24 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
yield return "E";
yield return "F";
// outer try-finally block
foreach (string line in input) {
foreach (string line in input)
{
yield return line.ToUpper();
}
}
public static IEnumerable<Func<string>> YieldReturnWithAnonymousMethods1(IEnumerable<string> input)
{
foreach (string line in input) {
foreach (string line in input)
{
yield return () => line;
}
}
public static IEnumerable<Func<string>> YieldReturnWithAnonymousMethods2(IEnumerable<string> input)
{
foreach (string line in input) {
foreach (string line in input)
{
string copy = line;
yield return () => copy;
}
@ -218,8 +242,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -218,8 +242,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
public static IEnumerable<int> GetEvenNumbers(int n)
{
for (int i = 0; i < n; i++) {
if (i % 2 == 0) {
for (int i = 0; i < n; i++)
{
if (i % 2 == 0)
{
yield return i;
}
}
@ -229,20 +255,29 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -229,20 +255,29 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
public static IEnumerable<char> ExceptionHandling()
{
yield return 'a';
try {
try
{
Console.WriteLine("1 - try");
} catch (Exception) {
}
catch (Exception)
{
Console.WriteLine("1 - catch");
}
yield return 'b';
try {
try {
try
{
try
{
Console.WriteLine("2 - try");
} finally {
}
finally
{
Console.WriteLine("2 - finally");
}
yield return 'c';
} finally {
}
finally
{
Console.WriteLine("outer finally");
}
}
@ -250,9 +285,12 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -250,9 +285,12 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
public static IEnumerable<int> YieldBreakInCatch()
{
yield return 0;
try {
try
{
Console.WriteLine("In Try");
} catch {
}
catch
{
// yield return is not allowed in catch, but yield break is
yield break;
}
@ -261,11 +299,15 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -261,11 +299,15 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
public static IEnumerable<int> YieldBreakInCatchInTryFinally()
{
try {
try
{
yield return 0;
try {
try
{
Console.WriteLine("In Try");
} catch {
}
catch
{
// yield return is not allowed in catch, but yield break is
// Note that pre-roslyn, this code triggers a compiler bug:
// If the finally block throws an exception, it ends up getting
@ -273,43 +315,58 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -273,43 +315,58 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
yield break;
}
yield return 1;
} finally {
}
finally
{
Console.WriteLine("Finally");
}
}
public static IEnumerable<int> YieldBreakInTryCatchInTryFinally()
{
try {
try
{
yield return 0;
try {
try
{
Console.WriteLine("In Try");
// same compiler bug as in YieldBreakInCatchInTryFinally
yield break;
} catch {
}
catch
{
Console.WriteLine("Catch");
}
yield return 1;
} finally {
}
finally
{
Console.WriteLine("Finally");
}
}
public static IEnumerable<int> YieldBreakInTryFinallyInTryFinally(bool b)
{
try {
try
{
yield return 0;
try {
try
{
Console.WriteLine("In Try");
if (b) {
if (b)
{
// same compiler bug as in YieldBreakInCatchInTryFinally
yield break;
}
} finally {
}
finally
{
Console.WriteLine("Inner Finally");
}
yield return 1;
} finally {
}
finally
{
Console.WriteLine("Finally");
}
}
@ -323,10 +380,13 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -323,10 +380,13 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
{
// Here, MoveNext() doesn't call the finally methods at all
// (only indirectly via Dispose())
try {
try
{
yield return 0;
throw new NotImplementedException();
} finally {
}
finally
{
Console.WriteLine("Finally");
}
}
@ -334,13 +394,19 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -334,13 +394,19 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
public static IEnumerable<int> NestedTryFinallyStartingOnSamePosition()
{
// The first user IL instruction is already in 2 nested try blocks.
try {
try {
try
{
try
{
yield return 0;
} finally {
}
finally
{
Console.WriteLine("Inner Finally");
}
} finally {
}
finally
{
Console.WriteLine("Outer Finally");
}
}
@ -349,15 +415,21 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -349,15 +415,21 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
public static IEnumerable<int> TryFinallyWithTwoExitPoints(bool b)
{
// Uses goto for multiple non-exceptional exits out of try-finally.
try {
if (b) {
try
{
if (b)
{
yield return 1;
goto exit1;
} else {
}
else
{
yield return 2;
goto exit2;
}
} finally {
}
finally
{
Console.WriteLine("Finally");
}
exit1:
@ -370,15 +442,21 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -370,15 +442,21 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
#if !LEGACY_CSC
public static IEnumerable<int> YieldBreakInNestedTryFinally()
{
try {
try
{
yield return 1;
try {
try
{
// Compiler bug: pre-Roslyn, the finally blocks will execute in the wrong order
yield break;
} finally {
}
finally
{
Console.WriteLine("Inner Finally");
}
} finally {
}
finally
{
Console.WriteLine("Outer Finally");
}
}
@ -388,17 +466,23 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -388,17 +466,23 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
// that exception gets caught by the catch block.
public static IEnumerable<int> TryFinallyWithTwoExitPointsInNestedTry(bool b)
{
try {
try
{
yield return 1;
try {
try
{
if (b)
goto exit1;
else
goto exit2;
} catch {
}
catch
{
Console.WriteLine("Catch");
}
} finally {
}
finally
{
Console.WriteLine("Finally");
}
exit1:
@ -410,17 +494,23 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -410,17 +494,23 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
public static IEnumerable<int> TryFinallyWithTwoExitPointsInNestedCatch(bool b)
{
try {
try
{
yield return 1;
try {
try
{
Console.WriteLine("Nested Try");
} catch {
}
catch
{
if (b)
goto exit1;
else
goto exit2;
}
} finally {
}
finally
{
Console.WriteLine("Finally");
}
exit1:
@ -434,9 +524,12 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -434,9 +524,12 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
public static IEnumerable<int> LocalInFinally<T>(T a) where T : IDisposable
{
yield return 1;
try {
try
{
yield return 2;
} finally {
}
finally
{
T val = a;
val.Dispose();
val.Dispose();
@ -447,7 +540,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -447,7 +540,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
public static IEnumerable<T> GenericYield<T>() where T : new()
{
T val = new T();
for (int i = 0; i < 3; i++) {
for (int i = 0; i < 3; i++)
{
yield return val;
}
}

55
ICSharpCode.Decompiler.Tests/TestCases/ILPretty/CS1xSwitch_Debug.cs

@ -55,7 +55,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -55,7 +55,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public static string SparseIntegerSwitch(int i)
{
Console.WriteLine("SparseIntegerSwitch: " + i);
switch (i) {
switch (i)
{
case -10000000:
return "-10 mln";
case -100:
@ -85,7 +86,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -85,7 +86,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public static void SwitchOverInt(int i)
{
switch (i) {
switch (i)
{
case 0:
Console.WriteLine("zero");
break;
@ -113,7 +115,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -113,7 +115,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public static string ShortSwitchOverString(string text)
{
Console.WriteLine("ShortSwitchOverString: " + text);
switch (text) {
switch (text)
{
case "First case":
return "Text1";
case "Second case":
@ -128,7 +131,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -128,7 +131,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public static string ShortSwitchOverStringWithNullCase(string text)
{
Console.WriteLine("ShortSwitchOverStringWithNullCase: " + text);
switch (text) {
switch (text)
{
case "First case":
return "Text1";
case "Second case":
@ -143,7 +147,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -143,7 +147,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public static string SwitchOverString1(string text)
{
Console.WriteLine("SwitchOverString1: " + text);
switch (text) {
switch (text)
{
case "First case":
return "Text1";
case "Second case":
@ -167,7 +172,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -167,7 +172,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public static string SwitchOverString2()
{
Console.WriteLine("SwitchOverString2:");
switch (Environment.UserName) {
switch (Environment.UserName)
{
case "First case":
return "Text1";
case "Second case":
@ -197,9 +203,11 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -197,9 +203,11 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public static string TwoDifferentSwitchBlocksInTryFinally()
{
try {
try
{
Console.WriteLine("TwoDifferentSwitchBlocks:");
switch (Environment.UserName) {
switch (Environment.UserName)
{
case "First case":
return "Text1";
case "Second case":
@ -225,9 +233,12 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -225,9 +233,12 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
default:
return "Default";
}
} finally {
}
finally
{
Console.WriteLine("Second switch:");
switch (Console.ReadLine()) {
switch (Console.ReadLine())
{
case "12":
Console.WriteLine("Te43234xt1");
break;
@ -271,7 +282,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -271,7 +282,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public static string SwitchOverBool(bool b)
{
Console.WriteLine("SwitchOverBool: " + b);
switch (b) {
switch (b)
{
case true:
return bool.TrueString;
case false:
@ -284,8 +296,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -284,8 +296,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public static void SwitchInLoop(int i)
{
Console.WriteLine("SwitchInLoop: " + i);
while (true) {
switch (i) {
while (true)
{
switch (i)
{
case 1:
Console.WriteLine("one");
break;
@ -310,7 +324,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -310,7 +324,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public static void SwitchWithGoto(int i)
{
Console.WriteLine("SwitchWithGoto: " + i);
switch (i) {
switch (i)
{
case 1:
Console.WriteLine("one");
goto default;
@ -340,10 +355,12 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -340,10 +355,12 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
ArrayList arrayList = new ArrayList();
ArrayList arrayList2 = new ArrayList();
SetProperty[] properties = GetProperties();
for (int i = 0; i < properties.Length; i++) {
for (int i = 0; i < properties.Length; i++)
{
Console.WriteLine("In for-loop");
SetProperty setProperty = properties[i];
switch (setProperty.Property.Name) {
switch (setProperty.Property.Name)
{
case "Name1":
setProperty.Set = 1;
arrayList.Add(setProperty);
@ -373,7 +390,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -373,7 +390,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public static void SwitchWithComplexCondition(string[] args)
{
switch ((args.Length == 0) ? "dummy" : args[0]) {
switch ((args.Length == 0) ? "dummy" : args[0])
{
case "a":
Console.WriteLine("a");
break;
@ -392,7 +410,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -392,7 +410,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public static void SwitchWithArray(string[] args)
{
switch (args[0]) {
switch (args[0])
{
case "a":
Console.WriteLine("a");
break;

55
ICSharpCode.Decompiler.Tests/TestCases/ILPretty/CS1xSwitch_Release.cs

@ -55,7 +55,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -55,7 +55,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public static string SparseIntegerSwitch(int i)
{
Console.WriteLine("SparseIntegerSwitch: " + i);
switch (i) {
switch (i)
{
case -10000000:
return "-10 mln";
case -100:
@ -85,7 +86,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -85,7 +86,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public static void SwitchOverInt(int i)
{
switch (i) {
switch (i)
{
case 0:
Console.WriteLine("zero");
break;
@ -113,7 +115,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -113,7 +115,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public static string ShortSwitchOverString(string text)
{
Console.WriteLine("ShortSwitchOverString: " + text);
switch (text) {
switch (text)
{
case "First case":
return "Text1";
case "Second case":
@ -128,7 +131,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -128,7 +131,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public static string ShortSwitchOverStringWithNullCase(string text)
{
Console.WriteLine("ShortSwitchOverStringWithNullCase: " + text);
switch (text) {
switch (text)
{
case "First case":
return "Text1";
case "Second case":
@ -143,7 +147,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -143,7 +147,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public static string SwitchOverString1(string text)
{
Console.WriteLine("SwitchOverString1: " + text);
switch (text) {
switch (text)
{
case "First case":
return "Text1";
case "Second case":
@ -167,7 +172,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -167,7 +172,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public static string SwitchOverString2()
{
Console.WriteLine("SwitchOverString2:");
switch (Environment.UserName) {
switch (Environment.UserName)
{
case "First case":
return "Text1";
case "Second case":
@ -197,9 +203,11 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -197,9 +203,11 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public static string TwoDifferentSwitchBlocksInTryFinally()
{
try {
try
{
Console.WriteLine("TwoDifferentSwitchBlocks:");
switch (Environment.UserName) {
switch (Environment.UserName)
{
case "First case":
return "Text1";
case "Second case":
@ -225,9 +233,12 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -225,9 +233,12 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
default:
return "Default";
}
} finally {
}
finally
{
Console.WriteLine("Second switch:");
switch (Console.ReadLine()) {
switch (Console.ReadLine())
{
case "12":
Console.WriteLine("Te43234xt1");
break;
@ -271,7 +282,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -271,7 +282,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public static string SwitchOverBool(bool b)
{
Console.WriteLine("SwitchOverBool: " + b);
switch (b) {
switch (b)
{
case true:
return bool.TrueString;
case false:
@ -284,8 +296,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -284,8 +296,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public static void SwitchInLoop(int i)
{
Console.WriteLine("SwitchInLoop: " + i);
while (true) {
switch (i) {
while (true)
{
switch (i)
{
case 1:
Console.WriteLine("one");
break;
@ -310,7 +324,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -310,7 +324,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public static void SwitchWithGoto(int i)
{
Console.WriteLine("SwitchWithGoto: " + i);
switch (i) {
switch (i)
{
case 1:
Console.WriteLine("one");
goto default;
@ -340,10 +355,12 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -340,10 +355,12 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
ArrayList arrayList = new ArrayList();
ArrayList arrayList2 = new ArrayList();
SetProperty[] properties = GetProperties();
for (int i = 0; i < properties.Length; i++) {
for (int i = 0; i < properties.Length; i++)
{
Console.WriteLine("In for-loop");
SetProperty setProperty = properties[i];
switch (setProperty.Property.Name) {
switch (setProperty.Property.Name)
{
case "Name1":
setProperty.Set = 1;
arrayList.Add(setProperty);
@ -373,7 +390,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -373,7 +390,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public static void SwitchWithComplexCondition(string[] args)
{
switch ((args.Length == 0) ? "dummy" : args[0]) {
switch ((args.Length == 0) ? "dummy" : args[0])
{
case "a":
Console.WriteLine("a");
break;
@ -392,7 +410,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -392,7 +410,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public static void SwitchWithArray(string[] args)
{
switch (args[0]) {
switch (args[0])
{
case "a":
Console.WriteLine("a");
break;

21
ICSharpCode.Decompiler.Tests/TestCases/ILPretty/FSharpLoops_Debug.cs

@ -65,7 +65,8 @@ public static class Program @@ -65,7 +65,8 @@ public static class Program
public override int GenerateNext(ref IEnumerable<int> next)
{
switch (pc) {
switch (pc)
{
default:
pc = 1;
current = 1;
@ -87,7 +88,8 @@ public static class Program @@ -87,7 +88,8 @@ public static class Program
public override bool get_CheckClose()
{
switch (pc) {
switch (pc)
{
default:
return false;
case 0:
@ -137,23 +139,28 @@ public static class Program @@ -137,23 +139,28 @@ public static class Program
public static int main(string[] argv)
{
IDisposable disposable;
using (Program.disposable()) {
using (Program.disposable())
{
Console.WriteLine("Hello 1");
disposable = Program.disposable();
}
using (disposable) {
using (disposable)
{
IEnumerable<int> seq = getSeq();
foreach (int item in seq) {
foreach (int item in seq)
{
Console.WriteLine(item);
}
FSharpList<int> fSharpList = getList();
for (FSharpList<int> tailOrNull = fSharpList.TailOrNull; tailOrNull != null; tailOrNull = fSharpList.TailOrNull) {
for (FSharpList<int> tailOrNull = fSharpList.TailOrNull; tailOrNull != null; tailOrNull = fSharpList.TailOrNull)
{
int headOrDefault = fSharpList.HeadOrDefault;
Console.WriteLine(headOrDefault);
fSharpList = tailOrNull;
}
int[] array = getArray();
foreach (int value in array) {
foreach (int value in array)
{
Console.WriteLine(value);
}
return 0;

21
ICSharpCode.Decompiler.Tests/TestCases/ILPretty/FSharpLoops_Release.cs

@ -66,7 +66,8 @@ public static class Program @@ -66,7 +66,8 @@ public static class Program
public override int GenerateNext(ref IEnumerable<int> next)
{
switch (pc) {
switch (pc)
{
default:
pc = 1;
current = 1;
@ -88,7 +89,8 @@ public static class Program @@ -88,7 +89,8 @@ public static class Program
public override bool get_CheckClose()
{
switch (pc) {
switch (pc)
{
default:
return false;
case 0:
@ -138,17 +140,21 @@ public static class Program @@ -138,17 +140,21 @@ public static class Program
public static int main(string[] argv)
{
IDisposable disposable;
using (Program.disposable()) {
using (Program.disposable())
{
Console.WriteLine("Hello 1");
disposable = Program.disposable();
}
using (disposable) {
using (disposable)
{
IEnumerable<int> seq = getSeq();
foreach (int item in seq) {
foreach (int item in seq)
{
Console.WriteLine(item);
}
FSharpList<int> fSharpList = FSharpList<int>.Cons(1, FSharpList<int>.Empty);
for (FSharpList<int> tailOrNull = fSharpList.TailOrNull; tailOrNull != null; tailOrNull = fSharpList.TailOrNull) {
for (FSharpList<int> tailOrNull = fSharpList.TailOrNull; tailOrNull != null; tailOrNull = fSharpList.TailOrNull)
{
int headOrDefault = fSharpList.HeadOrDefault;
Console.WriteLine(headOrDefault);
fSharpList = tailOrNull;
@ -156,7 +162,8 @@ public static class Program @@ -156,7 +162,8 @@ public static class Program
int[] array = new int[1] {
1
};
for (int headOrDefault = 0; headOrDefault < array.Length; headOrDefault++) {
for (int headOrDefault = 0; headOrDefault < array.Length; headOrDefault++)
{
Console.WriteLine(array[headOrDefault]);
}
return 0;

18
ICSharpCode.Decompiler.Tests/TestCases/ILPretty/FSharpUsing_Debug.cs

@ -5,7 +5,8 @@ public static class FSharpUsingPatterns @@ -5,7 +5,8 @@ public static class FSharpUsingPatterns
{
public static void sample1()
{
using (FileStream fileStream = File.Create("x.txt")) {
using (FileStream fileStream = File.Create("x.txt"))
{
fileStream.WriteByte((byte)1);
}
}
@ -13,7 +14,8 @@ public static class FSharpUsingPatterns @@ -13,7 +14,8 @@ public static class FSharpUsingPatterns
public static void sample2()
{
Console.WriteLine("some text");
using (FileStream fileStream = File.Create("x.txt")) {
using (FileStream fileStream = File.Create("x.txt"))
{
fileStream.WriteByte((byte)2);
Console.WriteLine("some text");
}
@ -22,7 +24,8 @@ public static class FSharpUsingPatterns @@ -22,7 +24,8 @@ public static class FSharpUsingPatterns
public static void sample3()
{
Console.WriteLine("some text");
using (FileStream fileStream = File.Create("x.txt")) {
using (FileStream fileStream = File.Create("x.txt"))
{
fileStream.WriteByte((byte)3);
}
Console.WriteLine("some text");
@ -32,7 +35,8 @@ public static class FSharpUsingPatterns @@ -32,7 +35,8 @@ public static class FSharpUsingPatterns
{
Console.WriteLine("some text");
int num;
using (FileStream fileStream = File.OpenRead("x.txt")) {
using (FileStream fileStream = File.OpenRead("x.txt"))
{
num = fileStream.ReadByte();
}
int num2 = num;
@ -43,12 +47,14 @@ public static class FSharpUsingPatterns @@ -43,12 +47,14 @@ public static class FSharpUsingPatterns
{
Console.WriteLine("some text");
int num;
using (FileStream fileStream = File.OpenRead("x.txt")) {
using (FileStream fileStream = File.OpenRead("x.txt"))
{
num = fileStream.ReadByte();
}
int num2 = num;
int num3;
using (FileStream fileStream = File.OpenRead("x.txt")) {
using (FileStream fileStream = File.OpenRead("x.txt"))
{
fileStream.ReadByte();
num3 = fileStream.ReadByte();
}

18
ICSharpCode.Decompiler.Tests/TestCases/ILPretty/FSharpUsing_Release.cs

@ -5,7 +5,8 @@ public static class FSharpUsingPatterns @@ -5,7 +5,8 @@ public static class FSharpUsingPatterns
{
public static void sample1()
{
using (FileStream fileStream = File.Create("x.txt")) {
using (FileStream fileStream = File.Create("x.txt"))
{
fileStream.WriteByte(1);
}
}
@ -13,7 +14,8 @@ public static class FSharpUsingPatterns @@ -13,7 +14,8 @@ public static class FSharpUsingPatterns
public static void sample2()
{
Console.WriteLine("some text");
using (FileStream fileStream = File.Create("x.txt")) {
using (FileStream fileStream = File.Create("x.txt"))
{
fileStream.WriteByte(2);
Console.WriteLine("some text");
}
@ -22,7 +24,8 @@ public static class FSharpUsingPatterns @@ -22,7 +24,8 @@ public static class FSharpUsingPatterns
public static void sample3()
{
Console.WriteLine("some text");
using (FileStream fileStream = File.Create("x.txt")) {
using (FileStream fileStream = File.Create("x.txt"))
{
fileStream.WriteByte(3);
}
Console.WriteLine("some text");
@ -32,7 +35,8 @@ public static class FSharpUsingPatterns @@ -32,7 +35,8 @@ public static class FSharpUsingPatterns
{
Console.WriteLine("some text");
int num;
using (FileStream fileStream = File.OpenRead("x.txt")) {
using (FileStream fileStream = File.OpenRead("x.txt"))
{
num = fileStream.ReadByte();
}
int num2 = num;
@ -43,12 +47,14 @@ public static class FSharpUsingPatterns @@ -43,12 +47,14 @@ public static class FSharpUsingPatterns
{
Console.WriteLine("some text");
int num;
using (FileStream fileStream = File.OpenRead("x.txt")) {
using (FileStream fileStream = File.OpenRead("x.txt"))
{
num = fileStream.ReadByte();
}
int num2 = num;
int num3;
using (FileStream fileStream = File.OpenRead("x.txt")) {
using (FileStream fileStream = File.OpenRead("x.txt"))
{
fileStream.ReadByte();
num3 = fileStream.ReadByte();
}

3
ICSharpCode.Decompiler.Tests/TestCases/ILPretty/Issue1047.cs

@ -6,7 +6,8 @@ @@ -6,7 +6,8 @@
private void ProblemMethod()
{
while (!dummy) {
while (!dummy)
{
}
}
}

3
ICSharpCode.Decompiler.Tests/TestCases/ILPretty/Issue1454.cs

@ -10,7 +10,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.ILPretty @@ -10,7 +10,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.ILPretty
bitArray.CopyTo(array, 0);
int num = 0;
array[array.Length - 1] &= ~(-1 << bitArray.Count % 32);
for (int i = 0; i < array.Length; i++) {
for (int i = 0; i < array.Length; i++)
{
int num2 = array[i];
num2 -= ((num2 >> 1) & 0x55555555);
num2 = (num2 & 0x33333333) + ((num2 >> 2) & 0x33333333);

13
ICSharpCode.Decompiler.Tests/TestCases/ILPretty/Issue1918.cs

@ -8,17 +8,22 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.ILPretty @@ -8,17 +8,22 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.ILPretty
public unsafe void ProblemFunction(Guid[] A_0, int A_1)
{
fixed (Guid* ptr = A_0) {
fixed (Guid* ptr = A_0)
{
void* ptr2 = ptr;
UIntPtr* ptr3 = (UIntPtr*)((byte*)ptr2 - sizeof(UIntPtr));
UIntPtr uIntPtr = *ptr3;
try {
try
{
*ptr3 = (UIntPtr)(ulong)A_1;
} finally {
}
finally
{
*ptr3 = uIntPtr;
}
}
fixed (Guid[] ptr = NullVal) {
fixed (Guid[] ptr = NullVal)
{
}
}
}

3
ICSharpCode.Decompiler.Tests/TestCases/ILPretty/Issue646.cs

@ -12,7 +12,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.ILPretty @@ -12,7 +12,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.ILPretty
public static void Main()
{
List<string> list = new List<string>();
foreach (string item in list) {
foreach (string item in list)
{
Debug.WriteLine(item);
}
}

25
ICSharpCode.Decompiler.Tests/TestCases/ILPretty/Issue684.cs

@ -9,25 +9,34 @@ public static class Issue684 @@ -9,25 +9,34 @@ public static class Issue684
// Point of this test was to ensure the stack slot here uses an appropriate type,
// (bool instead of int). Unfortunately our type fixup runs too late to affect variable names.
bool num2 = num >= 1000;
if (!num2) {
if (!num2)
{
num2 = (num < 2);
}
if (num2) {
if (num2)
{
Console.WriteLine(-1);
} else {
}
else
{
int i = 2;
for (int num3 = 2; num3 <= num; num3 = i) {
for (int num3 = 2; num3 <= num; num3 = i)
{
Console.WriteLine(num3);
for (; i <= num; i += num3) {
for (; i <= num; i += num3)
{
int num4 = array[i] = 1;
}
i = num3;
while (true) {
while (true)
{
bool num5 = i <= num;
if (num5) {
if (num5)
{
num5 = (array[i] != 0);
}
if (!num5) {
if (!num5)
{
break;
}
i++;

3
ICSharpCode.Decompiler.Tests/TestCases/ILPretty/Issue959.cs

@ -4,7 +4,8 @@ @@ -4,7 +4,8 @@
{
public void Test(bool arg)
{
if (!arg && arg) {
if (!arg && arg)
{
}
}

21
ICSharpCode.Decompiler.Tests/TestCases/ILPretty/SequenceOfNestedIfs.cs

@ -18,25 +18,32 @@ public class SequenceOfNestedIfs @@ -18,25 +18,32 @@ public class SequenceOfNestedIfs
}
public override void CreateMaterials()
{
if (!_clear) {
if (!CheckShader()) {
if (!_clear)
{
if (!CheckShader())
{
return;
}
_material = new Material();
}
if (!_material) {
if (!CheckShader()) {
if (!_material)
{
if (!CheckShader())
{
return;
}
_material = new Material();
}
if (!_material) {
if (!CheckShader()) {
if (!_material)
{
if (!CheckShader())
{
return;
}
_material = new Material();
}
if (!_material && CheckShader()) {
if (!_material && CheckShader())
{
_material = new Material();
}
}

25
ICSharpCode.Decompiler.Tests/TestCases/ILPretty/Unsafe.cs

@ -17,7 +17,8 @@ internal sealed class ExtraUnsafeTests @@ -17,7 +17,8 @@ internal sealed class ExtraUnsafeTests
{
public unsafe static void PinWithTypeMismatch(ref uint managedPtr)
{
fixed (ushort* ptr = &Unsafe.As<uint, ushort>(ref managedPtr)) {
fixed (ushort* ptr = &Unsafe.As<uint, ushort>(ref managedPtr))
{
}
}
@ -29,7 +30,8 @@ internal sealed class ExtraUnsafeTests @@ -29,7 +30,8 @@ internal sealed class ExtraUnsafeTests
public static ref ulong RefAssignTypeMismatch(ref uint a, ref uint b)
{
ref ushort reference = ref Unsafe.As<uint, ushort>(ref a);
if (a != 0) {
if (a != 0)
{
reference = ref Unsafe.As<uint, ushort>(ref b);
}
Console.WriteLine(reference);
@ -40,11 +42,15 @@ internal sealed class ExtraUnsafeTests @@ -40,11 +42,15 @@ internal sealed class ExtraUnsafeTests
{
//The blocks IL_0019 are reachable both inside and outside the pinned region starting at IL_0013. ILSpy has duplicated these blocks in order to place them both within and outside the `fixed` statement.
byte[] array;
if ((array = arr) != null && array.Length != 0) {
fixed (byte* ptr = &array[0]) {
if ((array = arr) != null && array.Length != 0)
{
fixed (byte* ptr = &array[0])
{
*(int*)ptr = val;
}
} else {
}
else
{
/*pinned*/ref byte reference = ref *(byte*)null;
*(int*)Unsafe.AsPointer(ref reference) = val;
}
@ -55,14 +61,17 @@ internal sealed class ExtraUnsafeTests @@ -55,14 +61,17 @@ internal sealed class ExtraUnsafeTests
{
//The blocks IL_0016 are reachable both inside and outside the pinned region starting at IL_0007. ILSpy has duplicated these blocks in order to place them both within and outside the `fixed` statement.
ref int reference;
fixed (int* ptr = &a[0]) {
if (*ptr <= 0) {
fixed (int* ptr = &a[0])
{
if (*ptr <= 0)
{
ptr[4 * 0] = 1;
return;
}
reference = ref *ptr;
}
fixed (int* ptr = &b[reference]) {
fixed (int* ptr = &b[reference])
{
ptr[4 * 0] = 1;
}
}

43
ICSharpCode.Decompiler.Tests/TestCases/Pretty/Async.cs

@ -95,7 +95,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -95,7 +95,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public async void TwoAwaitsWithDifferentAwaiterTypes()
{
Console.WriteLine("Before");
if (await SimpleBoolTaskMethod()) {
if (await SimpleBoolTaskMethod())
{
await Task.Delay(TimeSpan.FromSeconds(1.0));
}
Console.WriteLine("After");
@ -103,7 +104,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -103,7 +104,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public async void AwaitInLoopCondition()
{
while (await SimpleBoolTaskMethod()) {
while (await SimpleBoolTaskMethod())
{
Console.WriteLine("Body");
}
}
@ -111,14 +113,20 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -111,14 +113,20 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
#if CS60
public async Task AwaitInCatch(bool b, Task<int> task1, Task<int> task2)
{
try {
try
{
Console.WriteLine("Start try");
await task1;
Console.WriteLine("End try");
} catch (Exception) {
if (!b) {
}
catch (Exception)
{
if (!b)
{
await task2;
} else {
}
else
{
Console.WriteLine("No await");
}
}
@ -126,14 +134,20 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -126,14 +134,20 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public async Task AwaitInFinally(bool b, Task<int> task1, Task<int> task2)
{
try {
try
{
Console.WriteLine("Start try");
await task1;
Console.WriteLine("End try");
} finally {
if (!b) {
}
finally
{
if (!b)
{
await task2;
} else {
}
else
{
Console.WriteLine("No await");
}
}
@ -144,7 +158,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -144,7 +158,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
{
await Task.Delay(100);
int num = 0;
foreach (int item in items) {
foreach (int item in items)
{
num += item;
}
return num;
@ -174,13 +189,15 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -174,13 +189,15 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public static async Task InfiniteLoop()
{
while (true) {
while (true)
{
}
}
public static async Task InfiniteLoopWithAwait()
{
while (true) {
while (true)
{
await Task.Delay(10);
}
}

12
ICSharpCode.Decompiler.Tests/TestCases/Pretty/AsyncForeach.cs

@ -27,8 +27,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -27,8 +27,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public async Task<int> SumIntegers(IAsyncEnumerable<int> items, CancellationToken token)
{
int sum = 0;
await foreach (int item in items.WithCancellation(token)) {
if (token.IsCancellationRequested) {
await foreach (int item in items.WithCancellation(token))
{
if (token.IsCancellationRequested)
{
break;
}
sum += item;
@ -39,8 +41,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -39,8 +41,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public async Task<int> MaxInteger(IAsyncEnumerable<int> items)
{
int max = int.MinValue;
await foreach (int item in items) {
if (item > max) {
await foreach (int item in items)
{
if (item > max)
{
max = item;
}
}

16
ICSharpCode.Decompiler.Tests/TestCases/Pretty/AsyncStreams.cs

@ -10,7 +10,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -10,7 +10,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
{
public static async IAsyncEnumerable<int> CountTo(int until)
{
for (int i = 0; i < until; i++) {
for (int i = 0; i < until; i++)
{
yield return i;
await Task.Delay(10);
}
@ -24,14 +25,16 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -24,14 +25,16 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public static async IAsyncEnumerator<int> InfiniteLoop()
{
while (true) {
while (true)
{
}
yield break;
}
public static async IAsyncEnumerable<int> InfiniteLoopWithAwait()
{
while (true) {
while (true)
{
await Task.Delay(10);
}
yield break;
@ -39,11 +42,14 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -39,11 +42,14 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public async IAsyncEnumerable<int> AwaitInFinally()
{
try {
try
{
Console.WriteLine("try");
yield return 1;
Console.WriteLine("end try");
} finally {
}
finally
{
Console.WriteLine("finally");
await Task.Yield();
Console.WriteLine("end finally");

12
ICSharpCode.Decompiler.Tests/TestCases/Pretty/AsyncUsing.cs

@ -25,28 +25,32 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -25,28 +25,32 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public static async void TestAsyncUsing(IAsyncDisposable disposable)
{
await using (disposable) {
await using (disposable)
{
Console.WriteLine("Hello");
}
}
public static async void TestAsyncUsingClass()
{
await using (AsyncDisposableClass test = new AsyncDisposableClass()) {
await using (AsyncDisposableClass test = new AsyncDisposableClass())
{
Use(test);
}
}
public static async void TestAsyncUsingStruct()
{
await using (AsyncDisposableStruct asyncDisposableStruct = default(AsyncDisposableStruct)) {
await using (AsyncDisposableStruct asyncDisposableStruct = default(AsyncDisposableStruct))
{
Use(asyncDisposableStruct);
}
}
public static async void TestAsyncUsingNullableStruct()
{
await using (AsyncDisposableStruct? asyncDisposableStruct = new AsyncDisposableStruct?(default(AsyncDisposableStruct))) {
await using (AsyncDisposableStruct? asyncDisposableStruct = new AsyncDisposableStruct?(default(AsyncDisposableStruct)))
{
Use(asyncDisposableStruct);
}
}

18
ICSharpCode.Decompiler.Tests/TestCases/Pretty/CheckedUnchecked.cs

@ -52,8 +52,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -52,8 +52,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public void ForWithCheckedIteratorAndUncheckedBody(int n)
{
checked {
for (int i = n + 1; i < n + 1; i++) {
checked
{
for (int i = n + 1; i < n + 1; i++)
{
n = unchecked(i * i);
}
}
@ -62,7 +64,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -62,7 +64,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public void ForWithCheckedInitializerAndUncheckedIterator(int n)
{
int num = n;
for (num = checked(num - 10); num < n; num++) {
for (num = checked(num - 10); num < n; num++)
{
n--;
}
}
@ -111,13 +114,16 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -111,13 +114,16 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public short Unbox(TypeCode c, object b)
{
checked {
switch (c) {
checked
{
switch (c)
{
case TypeCode.Int32:
return (short)((Box<int>)b).Value;
case TypeCode.UInt32:
return (short)((Box<uint>)b).Value;
case TypeCode.Double: {
case TypeCode.Double:
{
float num = (float)((Box<double>)b).Value;
Console.WriteLine(num);
return (short)num;

10
ICSharpCode.Decompiler.Tests/TestCases/Pretty/CompoundAssignmentTest.cs

@ -624,7 +624,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -624,7 +624,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public void NestedField()
{
if (field1.HasIndex) {
if (field1.HasIndex)
{
Console.WriteLine(field1.Field *= 2);
field1.Field++;
Console.WriteLine(field1.Field++);
@ -4587,9 +4588,12 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -4587,9 +4588,12 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
// The 'chars[i]' result is stored in a temporary, and both branches use the
// same temporary. In order to inline the generated value-type temporary, we
// need to split it, even though it has the address taken for the ToString() call.
if (flag) {
if (flag)
{
strings[1] += chars[i];
} else {
}
else
{
strings[0] += chars[i];
}
}

5
ICSharpCode.Decompiler.Tests/TestCases/Pretty/CustomAttributeConflicts.cs

@ -1,8 +1,9 @@ @@ -1,8 +1,9 @@
using CustomAttributeConflicts.NS1;
using System;
using CustomAttributeConflicts.NS1;
using CustomAttributeConflicts.NS2;
using CustomAttributeConflicts.NSWithConflictingTypes;
using CustomAttributeConflicts.NSWithConflictingTypes2;
using System;
namespace CustomAttributeConflicts
{

41
ICSharpCode.Decompiler.Tests/TestCases/Pretty/CustomShortCircuitOperators.cs

@ -82,13 +82,16 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty.CustomShortCircuitOperat @@ -82,13 +82,16 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty.CustomShortCircuitOperat
private static void Test2()
{
if (GetC(1) && GetC(2)) {
if (GetC(1) && GetC(2))
{
Console.WriteLine(GetC(3));
}
if (GetC(1) || GetC(2)) {
if (GetC(1) || GetC(2))
{
Console.WriteLine(GetC(3));
}
if (!(GetC(1) && GetC(2))) {
if (!(GetC(1) && GetC(2)))
{
Console.WriteLine(GetC(3));
}
}
@ -96,10 +99,12 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty.CustomShortCircuitOperat @@ -96,10 +99,12 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty.CustomShortCircuitOperat
private static void Test3()
{
C c = new C();
if (c) {
if (c)
{
Console.WriteLine(c.ToString());
}
if (!c) {
if (!c)
{
Console.WriteLine(c.ToString());
}
}
@ -108,10 +113,12 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty.CustomShortCircuitOperat @@ -108,10 +113,12 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty.CustomShortCircuitOperat
{
Console.WriteLine(GetC(1) && d.P);
Console.WriteLine(GetC(2) || d.P);
if (GetC(3) && d.P) {
if (GetC(3) && d.P)
{
Console.WriteLine(GetC(4));
}
if (GetC(5) || d.P) {
if (GetC(5) || d.P)
{
Console.WriteLine(GetC(6));
}
}
@ -169,14 +176,20 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty.CustomShortCircuitOperat @@ -169,14 +176,20 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty.CustomShortCircuitOperat
public void InConditionDetection()
{
Console.WriteLine("a");
if (Get(1) && Get(2)) {
if (Get(1) && Get(2))
{
Console.WriteLine("b");
} else {
}
else
{
Console.WriteLine("c");
}
if (Get(1) || Get(2)) {
if (Get(1) || Get(2))
{
Console.WriteLine("d");
} else {
}
else
{
Console.WriteLine("e");
}
}
@ -185,10 +198,12 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty.CustomShortCircuitOperat @@ -185,10 +198,12 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty.CustomShortCircuitOperat
{
Console.WriteLine(Get(1) && d.P);
Console.WriteLine(Get(2) || d.P);
if (Get(3) && d.P) {
if (Get(3) && d.P)
{
Console.WriteLine(Get(4));
}
if (Get(5) || d.P) {
if (Get(5) || d.P)
{
Console.WriteLine(Get(6));
}
}

37
ICSharpCode.Decompiler.Tests/TestCases/Pretty/CustomTaskType.cs

@ -44,7 +44,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -44,7 +44,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public async void TwoAwaitsWithDifferentAwaiterTypes()
{
Console.WriteLine("Before");
if (await SimpleBoolTaskMethod()) {
if (await SimpleBoolTaskMethod())
{
await Task.Delay(TimeSpan.FromSeconds(1.0));
}
Console.WriteLine("After");
@ -52,21 +53,28 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -52,21 +53,28 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public async void AwaitInLoopCondition()
{
while (await SimpleBoolTaskMethod()) {
while (await SimpleBoolTaskMethod())
{
Console.WriteLine("Body");
}
}
public async ValueTask AwaitInCatch(bool b, ValueTask<int> task1, ValueTask<int> task2)
{
try {
try
{
Console.WriteLine("Start try");
await task1;
Console.WriteLine("End try");
} catch (Exception) {
if (!b) {
}
catch (Exception)
{
if (!b)
{
await task2;
} else {
}
else
{
Console.WriteLine("No await");
}
}
@ -74,14 +82,20 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -74,14 +82,20 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public async ValueTask AwaitInFinally(bool b, ValueTask<int> task1, ValueTask<int> task2)
{
try {
try
{
Console.WriteLine("Start try");
await task1;
Console.WriteLine("End try");
} finally {
if (!b) {
}
finally
{
if (!b)
{
await task2;
} else {
}
else
{
Console.WriteLine("No await");
}
}
@ -91,7 +105,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -91,7 +105,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
{
await Task.Delay(100);
int num = 0;
foreach (int item in items) {
foreach (int item in items)
{
num += item;
}
return num;

6
ICSharpCode.Decompiler.Tests/TestCases/Pretty/DeconstructionTests.cs

@ -581,14 +581,16 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -581,14 +581,16 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public void DeconstructDictionaryForEach(Dictionary<string, int> dictionary)
{
foreach (var (str, num2) in dictionary) {
foreach (var (str, num2) in dictionary)
{
Console.WriteLine(str + ": " + num2);
}
}
public void DeconstructTupleListForEach(List<(string, int)> tuples)
{
foreach (var (str, num) in tuples) {
foreach (var (str, num) in tuples)
{
Console.WriteLine(str + ": " + num);
}
}

67
ICSharpCode.Decompiler.Tests/TestCases/Pretty/DelegateConstruction.cs

@ -48,8 +48,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -48,8 +48,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public Action CaptureOfThisAndParameterInForEach(int a)
{
foreach (int item in Enumerable.Empty<int>()) {
if (item > 0) {
foreach (int item in Enumerable.Empty<int>())
{
if (item > 0)
{
return delegate {
CaptureOfThisAndParameter(item + a);
};
@ -60,9 +62,11 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -60,9 +62,11 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public Action CaptureOfThisAndParameterInForEachWithItemCopy(int a)
{
foreach (int item in Enumerable.Empty<int>()) {
foreach (int item in Enumerable.Empty<int>())
{
int copyOfItem = item;
if (item > 0) {
if (item > 0)
{
return delegate {
CaptureOfThisAndParameter(item + a + copyOfItem);
};
@ -73,7 +77,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -73,7 +77,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public void LambdaInForLoop()
{
for (int i = 0; i < 100000; i++) {
for (int i = 0; i < 100000; i++)
{
Bar(() => Foo());
}
}
@ -96,7 +101,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -96,7 +101,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public void Bug951(int amount)
{
DoAction(delegate {
if (amount < 0) {
if (amount < 0)
{
amount = 0;
}
DoAction(delegate {
@ -109,7 +115,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -109,7 +115,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
{
int amount = Foo();
DoAction(delegate {
if (amount < 0) {
if (amount < 0)
{
amount = 0;
}
DoAction(delegate {
@ -225,7 +232,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -225,7 +232,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public Func<TNonCaptured, TNonCapturedMP, TCaptured> GetFunc<TNonCapturedMP>(Func<TCaptured> f)
{
TCaptured captured = f();
return delegate(TNonCaptured a, TNonCapturedMP d) {
return delegate (TNonCaptured a, TNonCapturedMP d) {
Console.WriteLine(a.GetHashCode());
Console.WriteLine(captured.GetType().FullName);
return captured;
@ -248,10 +255,12 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -248,10 +255,12 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public static Predicate<T> And<T>(this Predicate<T> filter1, Predicate<T> filter2)
{
if (filter1 == null) {
if (filter1 == null)
{
return filter2;
}
if (filter2 == null) {
if (filter2 == null)
{
return filter1;
}
return (T m) => filter1(m) && filter2(m);
@ -295,9 +304,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -295,9 +304,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
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(delegate (int x) {
counter = x;
});
}
@ -308,8 +318,9 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -308,8 +318,9 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
{
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(delegate (int x) {
counter = x;
});
}
@ -331,11 +342,14 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -331,11 +342,14 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
// 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 k = 0; k < 10; k++) {
for (int k = 0; k < 10; k++)
{
int i;
for (i = 0; i < 10; i++) {
list.Add(delegate(int j) {
for (int l = 0; l < i; l += j) {
for (i = 0; i < 10; i++)
{
list.Add(delegate (int j) {
for (int l = 0; l < i; l += j)
{
Console.WriteLine();
}
});
@ -346,8 +360,9 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -346,8 +360,9 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public static void NameConflict2(int j)
{
List<Action<int>> list = new List<Action<int>>();
for (int k = 0; k < 10; k++) {
list.Add(delegate(int i) {
for (int k = 0; k < 10; k++)
{
list.Add(delegate (int i) {
Console.WriteLine(i);
});
}
@ -355,8 +370,9 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -355,8 +370,9 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public static Action<int> NameConflict3(int i)
{
return delegate(int j) {
for (int k = 0; k < j; k++) {
return delegate (int j) {
for (int k = 0; k < j; k++)
{
Console.WriteLine(k);
}
};
@ -450,10 +466,13 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -450,10 +466,13 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
{
Issue1867 m1;
Issue1867 m2;
if (x.value > value) {
if (x.value > value)
{
m1 = this;
m2 = x;
} else {
}
else
{
m1 = x;
m2 = this;
}

32
ICSharpCode.Decompiler.Tests/TestCases/Pretty/DynamicTests.cs

@ -126,9 +126,12 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -126,9 +126,12 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
private static void DynamicThrow()
{
try {
try
{
throw (Exception)field;
} catch (Exception ex) {
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
throw;
}
@ -247,7 +250,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -247,7 +250,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
private static void CheckedArithmeticBinaryOperators(dynamic a, dynamic b)
{
checked {
checked
{
DynamicTests.MemberAccess(a + b);
DynamicTests.MemberAccess(a + 1);
DynamicTests.MemberAccess(a + null);
@ -268,7 +272,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -268,7 +272,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
private static void UncheckedArithmeticBinaryOperators(dynamic a, dynamic b)
{
checked {
checked
{
DynamicTests.MemberAccess(a + b);
DynamicTests.MemberAccess(a + 1);
DynamicTests.MemberAccess(a + null);
@ -375,37 +380,44 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -375,37 +380,44 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
private static void Loops(dynamic list)
{
foreach (dynamic item in list) {
foreach (dynamic item in list)
{
DynamicTests.UnaryOperators(item);
}
}
private static void If(dynamic a, dynamic b)
{
if (a == b) {
if (a == b)
{
Console.WriteLine("Equal");
}
}
private static void If2(dynamic a, dynamic b)
{
if (a == null || b == null) {
if (a == null || b == null)
{
Console.WriteLine("One is null");
}
}
private static void If3(dynamic a, dynamic b)
{
if (a == null && b == null) {
if (a == null && b == null)
{
Console.WriteLine("Both are null");
}
}
private static void If4(dynamic a, dynamic b)
{
if ((a == null || b == null) && GetDynamic(1) && !(GetDynamic(2) && GetDynamic(3))) {
if ((a == null || b == null) && GetDynamic(1) && !(GetDynamic(2) && GetDynamic(3)))
{
Console.WriteLine("then");
} else {
}
else
{
Console.WriteLine("else");
}
}

232
ICSharpCode.Decompiler.Tests/TestCases/Pretty/ExceptionHandling.cs

@ -33,21 +33,28 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -33,21 +33,28 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public bool ConditionalReturnInThrow()
{
try {
if (B(0)) {
try
{
if (B(0))
{
return B(1);
}
} catch {
}
catch
{
}
return false;
}
public bool SimpleTryCatchException()
{
try {
try
{
Console.WriteLine("Try");
return B(new Random().Next());
} catch (Exception) {
}
catch (Exception)
{
Console.WriteLine("CatchException");
}
return false;
@ -55,10 +62,13 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -55,10 +62,13 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public bool SimpleTryCatchExceptionWithName()
{
try {
try
{
Console.WriteLine("Try");
return B(new Random().Next());
} catch (Exception ex) {
}
catch (Exception ex)
{
Console.WriteLine("CatchException ex: " + ex.ToString());
}
return false;
@ -67,10 +77,13 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -67,10 +77,13 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
#if CS60
public bool SimpleTryCatchExceptionWithNameAndCondition()
{
try {
try
{
Console.WriteLine("Try");
return B(new Random().Next());
} catch (Exception ex) when (ex.Message.Contains("test")) {
}
catch (Exception ex) when (ex.Message.Contains("test"))
{
Console.WriteLine("CatchException ex: " + ex.ToString());
}
return false;
@ -78,10 +91,13 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -78,10 +91,13 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public bool SimpleTryCatchExceptionWithNameAndConditionWithOr()
{
try {
try
{
Console.WriteLine("Try");
return B(new Random().Next());
} catch (Exception ex) when (ex is ArgumentException || ex is IOException) {
}
catch (Exception ex) when (ex is ArgumentException || ex is IOException)
{
Console.WriteLine("CatchException ex: " + ex.ToString());
}
return false;
@ -89,10 +105,13 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -89,10 +105,13 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public async Task<bool> SimpleAsyncTryCatchExceptionWithNameAndConditionWithOr()
{
try {
try
{
Console.WriteLine("Try");
return await T();
} catch (Exception ex) when (ex is ArgumentException || ex is IOException) {
}
catch (Exception ex) when (ex is ArgumentException || ex is IOException)
{
Console.WriteLine("CatchException ex: " + ex.ToString());
}
return false;
@ -101,9 +120,12 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -101,9 +120,12 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public void CatchWhenWithConditionWithoutExceptionVar()
{
int num = 0;
try {
try
{
throw new Exception();
} catch (Exception) when (num == 0) {
}
catch (Exception) when (num == 0)
{
Console.WriteLine("jo");
}
}
@ -112,9 +134,12 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -112,9 +134,12 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public bool SimpleTryFinally()
{
try {
try
{
Console.WriteLine("Try");
} finally {
}
finally
{
Console.WriteLine("Finally");
}
return false;
@ -122,42 +147,60 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -122,42 +147,60 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public void MethodEndingWithEndFinally()
{
try {
try
{
throw null;
} finally {
}
finally
{
Console.WriteLine();
}
}
public void MethodEndingWithRethrow()
{
try {
try
{
throw null;
} catch {
}
catch
{
throw;
}
}
public void TryCatchFinally()
{
try {
try
{
Console.WriteLine("Try");
} catch (Exception ex) {
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
} finally {
}
finally
{
Console.WriteLine("Finally");
}
}
public void TryCatchMultipleHandlers()
{
try {
try
{
Console.WriteLine("Try");
} catch (InvalidOperationException ex) {
}
catch (InvalidOperationException ex)
{
Console.WriteLine(ex.Message);
} catch (SystemException ex2) {
}
catch (SystemException ex2)
{
Console.WriteLine(ex2.Message);
} catch {
}
catch
{
Console.WriteLine("other");
}
}
@ -179,10 +222,14 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -179,10 +222,14 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public void NoUsingStatementBecauseTheVariableIsAssignedTo()
{
CancellationTokenSource cancellationTokenSource = null;
try {
try
{
cancellationTokenSource = new CancellationTokenSource();
} finally {
if (cancellationTokenSource != null) {
}
finally
{
if (cancellationTokenSource != null)
{
cancellationTokenSource.Dispose();
}
}
@ -190,8 +237,11 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -190,8 +237,11 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public void ThrowInFinally()
{
try {
} finally {
try
{
}
finally
{
throw new Exception();
}
}
@ -214,14 +264,19 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -214,14 +264,19 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
//}
public bool EarlyExitInLoopTry()
{
while (true) {
try {
if (!B(0)) {
while (true)
{
try
{
if (!B(0))
{
return false;
}
Console.WriteLine();
} catch {
}
catch
{
}
}
}
@ -229,14 +284,18 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -229,14 +284,18 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public bool ComplexConditionalReturnInThrow()
{
try {
if (B(0)) {
if (B(1)) {
try
{
if (B(0))
{
if (B(1))
{
Console.WriteLine("0 && 1");
return B(2);
}
if (B(3)) {
if (B(3))
{
Console.WriteLine("0 && 3");
return !B(2);
}
@ -246,22 +305,34 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -246,22 +305,34 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
Console.WriteLine("End Try");
} catch {
try {
try {
if (((B(0) || B(1)) && B(2)) || B(3)) {
}
catch
{
try
{
try
{
if (((B(0) || B(1)) && B(2)) || B(3))
{
return B(4) && !B(5);
}
if (B(6) || B(7)) {
if (B(6) || B(7))
{
return B(8) || B(9);
}
} catch {
}
catch
{
Console.WriteLine("Catch2");
}
return B(10) && B(11);
} catch {
}
catch
{
Console.WriteLine("Catch");
} finally {
}
finally
{
Console.WriteLine("Finally");
}
}
@ -271,12 +342,18 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -271,12 +342,18 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public void AppropriateLockExit()
{
int num = 0;
lock (this) {
if (num <= 256) {
lock (this)
{
if (num <= 256)
{
Console.WriteLine(0);
} else if (num <= 1024) {
}
else if (num <= 1024)
{
Console.WriteLine(1);
} else if (num <= 16384) {
}
else if (num <= 16384)
{
Console.WriteLine(2);
}
}
@ -284,10 +361,14 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -284,10 +361,14 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public void ReassignExceptionVar()
{
try {
try
{
Console.WriteLine("ReassignExceptionVar");
} catch (Exception innerException) {
if (innerException.InnerException != null) {
}
catch (Exception innerException)
{
if (innerException.InnerException != null)
{
innerException = innerException.InnerException;
}
Console.WriteLine(innerException);
@ -297,9 +378,12 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -297,9 +378,12 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public int UseExceptionVarOutsideCatch()
{
Exception ex2;
try {
try
{
return 1;
} catch (Exception ex) {
}
catch (Exception ex)
{
ex2 = ex;
}
Console.WriteLine(ex2 != null);
@ -308,9 +392,12 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -308,9 +392,12 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public void GenericException<TException>(int input) where TException : Exception
{
try {
try
{
Console.WriteLine(input);
} catch (TException val) {
}
catch (TException val)
{
Console.WriteLine(val.Message);
throw;
}
@ -318,14 +405,19 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -318,14 +405,19 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public void GenericException2<T>() where T : Exception
{
try {
try
{
Console.WriteLine("CatchT");
#if ROSLYN
} catch (T val) {
}
catch (T val)
{
Console.WriteLine("{0} {1}", val, val.ToString());
}
#else
} catch (T arg) {
}
catch (T arg)
{
Console.WriteLine("{0} {1}", arg, arg.ToString());
}
#endif
@ -334,9 +426,12 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -334,9 +426,12 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
#if CS60
public void GenericExceptionWithCondition<TException>(int input) where TException : Exception
{
try {
try
{
Console.WriteLine(input);
} catch (TException val) when (val.Message.Contains("Test")) {
}
catch (TException val) when (val.Message.Contains("Test"))
{
Console.WriteLine(val.Message);
throw;
}
@ -344,9 +439,12 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -344,9 +439,12 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public void GenericException2WithCondition<TException>(int input) where TException : Exception
{
try {
try
{
Console.WriteLine(input);
} catch (TException val) when (val.Message.Contains("Test")) {
}
catch (TException val) when (val.Message.Contains("Test"))
{
Console.WriteLine("{0} {1}", val, val.ToString());
}
}

15
ICSharpCode.Decompiler.Tests/TestCases/Pretty/ExpressionTrees.cs

@ -332,7 +332,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -332,7 +332,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
private void Issue1249(int ID)
{
if (ID == 0) {
if (ID == 0)
{
ViewBag.data = "''";
return;
}
@ -960,15 +961,15 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -960,15 +961,15 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
Test<Func<int, string>>((int a) => a.ToString(), (int a) => a.ToString());
Test<Func<string, char[]>>((string a) => a.ToArray(), (string a) => a.ToArray());
Test<Func<bool>>(() => 'a'.CompareTo('b') < 0, () => 'a'.CompareTo('b') < 0);
Test<Action<object, bool>>(delegate(object lockObj, bool lockTaken) {
Test<Action<object, bool>>(delegate (object lockObj, bool lockTaken) {
Monitor.Enter(lockObj, ref lockTaken);
}, (object lockObj, bool lockTaken) => Monitor.Enter(lockObj, ref lockTaken));
Test<Func<string, int, bool>>((string str, int num) => int.TryParse(str, out num), (string str, int num) => int.TryParse(str, out num));
Test<Func<string, SimpleType, bool>>((string str, SimpleType t) => int.TryParse(str, out t.Field), (string str, SimpleType t) => int.TryParse(str, out t.Field));
Test<Action<object>>(delegate(object o) {
Test<Action<object>>(delegate (object o) {
TestCall(o);
}, (object o) => TestCall(o));
Test<Action<object>>(delegate(object o) {
Test<Action<object>>(delegate (object o) {
TestCall(ref o);
}, (object o) => TestCall(ref o));
}
@ -1038,10 +1039,12 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -1038,10 +1039,12 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
{
await Task.Delay(100);
#if CS70
if (string.IsNullOrEmpty(str) && int.TryParse(str, out int id)) {
if (string.IsNullOrEmpty(str) && int.TryParse(str, out int id))
{
#else
int id;
if (string.IsNullOrEmpty(str) && int.TryParse(str, out id)) {
if (string.IsNullOrEmpty(str) && int.TryParse(str, out id))
{
#endif
(from a in new List<int>().AsQueryable()
where a == id

10
ICSharpCode.Decompiler.Tests/TestCases/Pretty/FixProxyCalls.cs

@ -96,10 +96,11 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.ILPretty @@ -96,10 +96,11 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.ILPretty
protected internal override void Test(string test)
{
action = delegate(string a) {
action = delegate (string a) {
base.Test(a);
};
if (test.Equals(1)) {
if (test.Equals(1))
{
throw new Exception("roslyn optimizes is inlining the assignment which lets the test fail");
}
action(test);
@ -118,7 +119,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.ILPretty @@ -118,7 +119,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.ILPretty
{
public Action<object> M(object state)
{
return delegate(object x) {
return delegate (object x) {
base.BaseCall(x, state, (Func<object>)(() => null));
};
}
@ -138,7 +139,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.ILPretty @@ -138,7 +139,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.ILPretty
Action action = delegate {
base.Test(a);
};
if (a.Equals(1)) {
if (a.Equals(1))
{
throw new Exception("roslyn optimize is inlining the assignment which lets the test fail");
}
action();

3
ICSharpCode.Decompiler.Tests/TestCases/Pretty/Generics.cs

@ -73,7 +73,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -73,7 +73,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public void Grow(int capacity)
{
if (capacity >= arr.Length) {
if (capacity >= arr.Length)
{
Size(capacity);
}
}

15
ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.cs

@ -1233,9 +1233,9 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests @@ -1233,9 +1233,9 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests
}
};
}
#endregion
#endregion
#region Object initializers
#region Object initializers
public C Test1()
{
C c = new C();
@ -1537,7 +1537,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests @@ -1537,7 +1537,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests
private Data Issue1279(int p)
{
if (p == 1) {
if (p == 1)
{
Data data = new Data();
data.a = MyEnum.a;
data.TestEvent += Data_TestEvent;
@ -1546,9 +1547,9 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests @@ -1546,9 +1547,9 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests
return null;
}
#endregion
#endregion
#region Collection initializer
#region Collection initializer
public static void ExtensionMethodInCollectionInitializer()
{
@ -1733,6 +1734,6 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests @@ -1733,6 +1734,6 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests
}
#endif
#endregion
}
#endregion
}
}

3
ICSharpCode.Decompiler.Tests/TestCases/Pretty/InlineAssignmentTest.cs

@ -81,7 +81,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -81,7 +81,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public void ReadLoop1(TextReader r)
{
string value;
while ((value = r.ReadLine()) != null) {
while ((value = r.ReadLine()) != null)
{
Console.WriteLine(value);
}
}

3
ICSharpCode.Decompiler.Tests/TestCases/Pretty/Issue1080.cs

@ -13,7 +13,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty.Issue1080 @@ -13,7 +13,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty.Issue1080
private static void Test(object obj)
{
ICSharpCode.Decompiler.Tests.TestCases.Pretty.Issue1080.SpaceA.Type2 type = obj as ICSharpCode.Decompiler.Tests.TestCases.Pretty.Issue1080.SpaceA.Type2;
if (type != null) {
if (type != null)
{
ICSharpCode.Decompiler.Tests.TestCases.Pretty.Issue1080.SpaceC.Extensions.Extension(type);
}
}

171
ICSharpCode.Decompiler.Tests/TestCases/Pretty/LiftedOperators.cs

@ -30,54 +30,67 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -30,54 +30,67 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public static void BoolBasic(bool? a, bool? b)
{
if (a == b) {
if (a == b)
{
Console.WriteLine();
}
if (a != b) {
if (a != b)
{
Console.WriteLine();
}
}
public static void BoolComplex(bool? a, Func<bool> x)
{
if (a == x()) {
if (a == x())
{
Console.WriteLine();
}
if (a != x()) {
if (a != x())
{
Console.WriteLine();
}
if (x() == a) {
if (x() == a)
{
Console.WriteLine();
}
if (x() != a) {
if (x() != a)
{
Console.WriteLine();
}
if (a ?? x()) {
if (a ?? x())
{
Console.WriteLine();
}
}
public static void BoolConst(bool? a)
{
if (a == true) {
if (a == true)
{
Console.WriteLine();
}
if (a != true) {
if (a != true)
{
Console.WriteLine();
}
if (a == false) {
if (a == false)
{
Console.WriteLine();
}
if (a != false) {
if (a != false)
{
Console.WriteLine();
}
if (a ?? true) {
if (a ?? true)
{
Console.WriteLine();
}
#if !ROSLYN
// Roslyn 3 (VS2019) started optimizing this to "a.GetValueOrDefault()"
if (a ?? false) {
if (a ?? false)
{
Console.WriteLine();
}
#endif
@ -136,82 +149,104 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -136,82 +149,104 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public static void IntBasic(int? a, int? b)
{
if (a == b) {
if (a == b)
{
Console.WriteLine();
}
if (a != b) {
if (a != b)
{
Console.WriteLine();
}
if (a > b) {
if (a > b)
{
Console.WriteLine();
}
if (a < b) {
if (a < b)
{
Console.WriteLine();
}
if (a >= b) {
if (a >= b)
{
Console.WriteLine();
}
if (a <= b) {
if (a <= b)
{
Console.WriteLine();
}
if (!(a > b)) {
if (!(a > b))
{
Console.WriteLine();
}
if (!(a <= b)) {
if (!(a <= b))
{
Console.WriteLine();
}
}
public static void IntComplex(int? a, Func<int> x)
{
if (a == x()) {
if (a == x())
{
Console.WriteLine();
}
if (a != x()) {
if (a != x())
{
Console.WriteLine();
}
if (a > x()) {
if (a > x())
{
Console.WriteLine();
}
if (x() == a) {
if (x() == a)
{
Console.WriteLine();
}
if (x() != a) {
if (x() != a)
{
Console.WriteLine();
}
if (x() > a) {
if (x() > a)
{
Console.WriteLine();
}
if (!(a > x())) {
if (!(a > x()))
{
Console.WriteLine();
}
if (!(a <= x())) {
if (!(a <= x()))
{
Console.WriteLine();
}
}
public static void IntConst(int? a)
{
if (a == 2) {
if (a == 2)
{
Console.WriteLine();
}
if (a != 2) {
if (a != 2)
{
Console.WriteLine();
}
if (a > 2) {
if (a > 2)
{
Console.WriteLine();
}
if (2 == a) {
if (2 == a)
{
Console.WriteLine();
}
if (2 != a) {
if (2 != a)
{
Console.WriteLine();
}
if (2 > a) {
if (2 > a)
{
Console.WriteLine();
}
}
@ -328,36 +363,45 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -328,36 +363,45 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public static void NumberBasic(decimal? a, decimal? b)
{
if (a == b) {
if (a == b)
{
Console.WriteLine();
}
#if ROSLYN
// Roslyn 2.9 started invoking op_Equality even if the source code says 'a != b'
if (!(a == b)) {
if (!(a == b))
{
Console.WriteLine();
}
#else
if (a != b) {
if (a != b)
{
Console.WriteLine();
}
#endif
if (a > b) {
if (a > b)
{
Console.WriteLine();
}
if (a < b) {
if (a < b)
{
Console.WriteLine();
}
if (a >= b) {
if (a >= b)
{
Console.WriteLine();
}
if (a <= b) {
if (a <= b)
{
Console.WriteLine();
}
if (!(a > b)) {
if (!(a > b))
{
Console.WriteLine();
}
if (!(a < b)) {
if (!(a < b))
{
Console.WriteLine();
}
}
@ -502,10 +546,12 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -502,10 +546,12 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public static void CompareWithImplictCast(int? a, long? b)
{
if (a < b) {
if (a < b)
{
Console.WriteLine();
}
if (a == b) {
if (a == b)
{
Console.WriteLine();
}
// TODO: unnecessary cast
@ -519,7 +565,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -519,7 +565,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public static void CompareWithSignChange(int? a, int? b)
{
if ((uint?)a < (uint?)b) {
if ((uint?)a < (uint?)b)
{
Console.WriteLine();
}
// TODO: unnecessary cast
@ -530,32 +577,41 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -530,32 +577,41 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public static void StructBasic(TS? a, TS? b)
{
if (a == b) {
if (a == b)
{
Console.WriteLine();
}
if (a != b) {
if (a != b)
{
Console.WriteLine();
}
if (a > b) {
if (a > b)
{
Console.WriteLine();
}
if (a < b) {
if (a < b)
{
Console.WriteLine();
}
if (a >= b) {
if (a >= b)
{
Console.WriteLine();
}
if (a <= b) {
if (a <= b)
{
Console.WriteLine();
}
if (!(a == b)) {
if (!(a == b))
{
Console.WriteLine();
}
if (!(a != b)) {
if (!(a != b))
{
Console.WriteLine();
}
if (!(a > b)) {
if (!(a > b))
{
Console.WriteLine();
}
}
@ -785,7 +841,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -785,7 +841,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public static void CheckedCasts(int? i4, long? i8, float? f)
{
checked {
checked
{
Print((byte?)i4);
Print((short?)i4);
Print((uint?)i4);

47
ICSharpCode.Decompiler.Tests/TestCases/Pretty/LocalFunctions.cs

@ -36,7 +36,8 @@ namespace LocalFunctions @@ -36,7 +36,8 @@ namespace LocalFunctions
#pragma warning disable CS0219
T2 t2 = default(T2);
object z = this;
for (int j = 0; j < 10; j++) {
for (int j = 0; j < 10; j++)
{
int i = 0;
i += NonStaticMethod6<object>(0);
#if CS90
@ -115,7 +116,8 @@ namespace LocalFunctions @@ -115,7 +116,8 @@ namespace LocalFunctions
{
T2 t2 = default(T2);
object z = this;
for (int j = 0; j < 10; j++) {
for (int j = 0; j < 10; j++)
{
int i = 0;
i += StaticInvokeAsFunc(NonStaticMethod6<object>);
int NonStaticMethod6<T3>()
@ -366,7 +368,8 @@ namespace LocalFunctions @@ -366,7 +368,8 @@ namespace LocalFunctions
public static void StaticContextNoCapture(int length)
{
for (int i = 0; i < length; i++) {
for (int i = 0; i < length; i++)
{
LocalWrite("Hello " + i);
}
@ -382,7 +385,8 @@ namespace LocalFunctions @@ -382,7 +385,8 @@ namespace LocalFunctions
public static void StaticContextSimpleCapture(int length)
{
for (int i = 0; i < length; i++) {
for (int i = 0; i < length; i++)
{
LocalWrite();
}
@ -395,7 +399,8 @@ namespace LocalFunctions @@ -395,7 +399,8 @@ namespace LocalFunctions
public static void StaticContextCaptureForLoopVariable(int length)
{
int i;
for (i = 0; i < length; i++) {
for (i = 0; i < length; i++)
{
LocalWrite();
}
void LocalWrite()
@ -406,7 +411,8 @@ namespace LocalFunctions @@ -406,7 +411,8 @@ namespace LocalFunctions
public void ContextNoCapture()
{
for (int i = 0; i < field; i++) {
for (int i = 0; i < field; i++)
{
LocalWrite("Hello " + i);
}
@ -422,7 +428,8 @@ namespace LocalFunctions @@ -422,7 +428,8 @@ namespace LocalFunctions
public void ContextSimpleCapture()
{
for (int i = 0; i < field; i++) {
for (int i = 0; i < field; i++)
{
LocalWrite();
}
@ -435,7 +442,8 @@ namespace LocalFunctions @@ -435,7 +442,8 @@ namespace LocalFunctions
public void ContextCaptureForLoopVariable()
{
int i;
for (i = 0; i < field; i++) {
for (i = 0; i < field; i++)
{
LocalWrite();
}
void LocalWrite()
@ -447,7 +455,8 @@ namespace LocalFunctions @@ -447,7 +455,8 @@ namespace LocalFunctions
public void CapturedOutsideLoop()
{
int i = 0;
while (i < field) {
while (i < field)
{
i = GetInt("asdf");
LocalWrite();
}
@ -460,7 +469,8 @@ namespace LocalFunctions @@ -460,7 +469,8 @@ namespace LocalFunctions
public void CapturedInForeachLoop(IEnumerable<string> args)
{
foreach (string arg2 in args) {
foreach (string arg2 in args)
{
string arg = arg2;
LocalWrite();
void LocalWrite()
@ -563,7 +573,8 @@ namespace LocalFunctions @@ -563,7 +573,8 @@ namespace LocalFunctions
int FibHelper(int n)
#endif
{
if (n <= 0) {
if (n <= 0)
{
return 0;
}
@ -580,7 +591,8 @@ namespace LocalFunctions @@ -580,7 +591,8 @@ namespace LocalFunctions
int A(int i)
#endif
{
if (i > 0) {
if (i > 0)
{
return A(i - 1) + 2 * B(i - 1) + 3 * C(i - 1);
}
return 1;
@ -592,7 +604,8 @@ namespace LocalFunctions @@ -592,7 +604,8 @@ namespace LocalFunctions
int B(int i)
#endif
{
if (i > 0) {
if (i > 0)
{
return 3 * A(i - 1) + B(i - 1);
}
return 1;
@ -604,7 +617,8 @@ namespace LocalFunctions @@ -604,7 +617,8 @@ namespace LocalFunctions
int C(int i)
#endif
{
if (i > 0) {
if (i > 0)
{
return 2 * A(i - 1) + C(i - 1);
}
return 1;
@ -629,7 +643,7 @@ namespace LocalFunctions @@ -629,7 +643,7 @@ namespace LocalFunctions
public static int LocalFunctionInLambda(IEnumerable<int> xs)
{
return xs.First(delegate(int x) {
return xs.First(delegate (int x) {
return Do();
bool Do()
@ -645,7 +659,8 @@ namespace LocalFunctions @@ -645,7 +659,8 @@ namespace LocalFunctions
IEnumerable<int> GetNumbers()
{
for (int i = 0; i < n; i++) {
for (int i = 0; i < n; i++)
{
yield return i;
}
}

6
ICSharpCode.Decompiler.Tests/TestCases/Pretty/Lock.cs

@ -24,14 +24,16 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -24,14 +24,16 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
{
public void LockThis()
{
lock (this) {
lock (this)
{
Console.WriteLine();
}
}
public void LockOnType()
{
lock (typeof(Lock)) {
lock (typeof(Lock))
{
Console.WriteLine();
}
}

295
ICSharpCode.Decompiler.Tests/TestCases/Pretty/Loops.cs

@ -290,14 +290,16 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -290,14 +290,16 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public void ForEachOnField()
{
foreach (string alternative in alternatives) {
foreach (string alternative in alternatives)
{
alternative.ToLower();
}
}
public void ForEach(IEnumerable<string> alternatives)
{
foreach (string alternative in alternatives) {
foreach (string alternative in alternatives)
{
alternative.ToLower();
}
}
@ -305,35 +307,40 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -305,35 +307,40 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public void ForEachOverList(List<string> list)
{
// List has a struct as enumerator, so produces quite different IL than foreach over the IEnumerable interface
foreach (string item in list) {
foreach (string item in list)
{
item.ToLower();
}
}
public void ForEachOverNonGenericEnumerable(IEnumerable enumerable)
{
foreach (object item in enumerable) {
foreach (object item in enumerable)
{
item.ToString();
}
}
public void ForEachOverNonGenericEnumerableWithAutomaticCastValueType(IEnumerable enumerable)
{
foreach (int item in enumerable) {
foreach (int item in enumerable)
{
item.ToString();
}
}
public void ForEachOverNonGenericEnumerableWithAutomaticCastRefType(IEnumerable enumerable)
{
foreach (string item in enumerable) {
foreach (string item in enumerable)
{
Console.WriteLine(item);
}
}
public void ForEachOnCustomClassEnumerator(CustomClassEnumerator e)
{
foreach (object item in e) {
foreach (object item in e)
{
Console.WriteLine(item);
}
}
@ -350,7 +357,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -350,7 +357,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public void ForEachOnGenericCustomClassEnumerator<T>(CustomClassEnumerator<T> e)
{
foreach (T item in e) {
foreach (T item in e)
{
Console.WriteLine(item);
}
}
@ -367,28 +375,32 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -367,28 +375,32 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public void ForEachOnCustomClassEnumeratorWithIDisposable(CustomClassEnumeratorWithIDisposable e)
{
foreach (object item in e) {
foreach (object item in e)
{
Console.WriteLine(item);
}
}
public void ForEachOnCustomStructEnumeratorWithIDisposable(CustomStructEnumeratorWithIDisposable e)
{
foreach (object item in e) {
foreach (object item in e)
{
Console.WriteLine(item);
}
}
public void ForEachOnGenericCustomClassEnumeratorWithIDisposable<T>(CustomClassEnumeratorWithIDisposable<T> e)
{
foreach (T item in e) {
foreach (T item in e)
{
Console.WriteLine(item);
}
}
public void ForEachOnGenericCustomStructEnumeratorWithIDisposable<T>(CustomStructEnumeratorWithIDisposable<T> e)
{
foreach (T item in e) {
foreach (T item in e)
{
Console.WriteLine(item);
}
}
@ -397,16 +409,21 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -397,16 +409,21 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
{
Console.WriteLine("NonGenericForeachWithReturnFallback:");
IEnumerator enumerator = e.GetEnumerator();
try {
try
{
Console.WriteLine("MoveNext");
if (enumerator.MoveNext()) {
if (enumerator.MoveNext())
{
object current = enumerator.Current;
Console.WriteLine("please don't inline 'current'");
Console.WriteLine(current);
}
} finally {
}
finally
{
IDisposable disposable = enumerator as IDisposable;
if (disposable != null) {
if (disposable != null)
{
disposable.Dispose();
}
}
@ -415,7 +432,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -415,7 +432,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public static void ForeachWithRefUsage(List<int> items)
{
foreach (int item in items) {
foreach (int item in items)
{
#if ROSLYN && OPT
// The variable name differs based on whether roslyn optimizes out the 'item' variable
int i = item;
@ -429,7 +447,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -429,7 +447,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public static void ForeachWithCapturedVariable(List<int> items)
{
foreach (int item in items) {
foreach (int item in items)
{
int c = item;
Operation(() => c == 5);
}
@ -438,7 +457,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -438,7 +457,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public static T LastOrDefault<T>(IEnumerable<T> items)
{
T result = default(T);
foreach (T item in items) {
foreach (T item in items)
{
result = item;
}
return result;
@ -446,14 +466,16 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -446,14 +466,16 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public void ForEachOverArray(string[] array)
{
foreach (string text in array) {
foreach (string text in array)
{
Console.WriteLine(text.ToLower() + text.ToUpper());
}
}
public unsafe void ForEachOverArrayOfPointers(int*[] array)
{
foreach (int* value in array) {
foreach (int* value in array)
{
Console.WriteLine(new IntPtr(value));
Console.WriteLine(new IntPtr(value));
}
@ -462,15 +484,19 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -462,15 +484,19 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public void ForEachBreakWhenFound(string name, ref StringComparison output)
{
#if MCS
foreach (int value in Enum.GetValues(typeof(StringComparison))) {
if (((StringComparison)value).ToString() == name) {
foreach (int value in Enum.GetValues(typeof(StringComparison)))
{
if (((StringComparison)value).ToString() == name)
{
output = (StringComparison)value;
break;
}
}
#else
foreach (StringComparison value in Enum.GetValues(typeof(StringComparison))) {
if (value.ToString() == name) {
foreach (StringComparison value in Enum.GetValues(typeof(StringComparison)))
{
if (value.ToString() == name)
{
output = value;
break;
}
@ -480,7 +506,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -480,7 +506,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public void ForEachOverListOfStruct(List<DataItem> items, int value)
{
foreach (DataItem item in items) {
foreach (DataItem item in items)
{
#if ROSLYN && OPT
// The variable name differs based on whether roslyn optimizes out the 'item' variable
DataItem current = item;
@ -494,7 +521,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -494,7 +521,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public void ForEachOverListOfStruct2(List<DataItem> items, int value)
{
foreach (DataItem item in items) {
foreach (DataItem item in items)
{
#if ROSLYN && OPT
// The variable name differs based on whether roslyn optimizes out the 'item' variable
DataItem current = item;
@ -510,7 +538,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -510,7 +538,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public void ForEachOverListOfStruct3(List<DataItem> items, int value)
{
foreach (DataItem item in items) {
foreach (DataItem item in items)
{
item.TestCall();
}
}
@ -518,7 +547,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -518,7 +547,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
#if !MCS
public void ForEachOverMultiDimArray(int[,] items)
{
foreach (int value in items) {
foreach (int value in items)
{
Console.WriteLine(value);
Console.WriteLine(value);
}
@ -526,7 +556,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -526,7 +556,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public void ForEachOverMultiDimArray2(int[,,] items)
{
foreach (int value in items) {
foreach (int value in items)
{
Console.WriteLine(value);
Console.WriteLine(value);
}
@ -535,12 +566,14 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -535,12 +566,14 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public unsafe void ForEachOverMultiDimArray3(int*[,] items)
{
#if ROSLYN && OPT
foreach (int* intPtr in items) {
foreach (int* intPtr in items)
{
Console.WriteLine(*intPtr);
Console.WriteLine(*intPtr);
}
#else
foreach (int* ptr in items) {
foreach (int* ptr in items)
{
Console.WriteLine(*ptr);
Console.WriteLine(*ptr);
}
@ -548,20 +581,23 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -548,20 +581,23 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
}
#endif
#endregion
#endregion
public void ForOverArray(string[] array)
{
for (int i = 0; i < array.Length; i++) {
for (int i = 0; i < array.Length; i++)
{
array[i].ToLower();
}
}
public void NoForeachOverArray(string[] array)
{
for (int i = 0; i < array.Length; i++) {
for (int i = 0; i < array.Length; i++)
{
string value = array[i];
if (i % 5 == 0) {
if (i % 5 == 0)
{
Console.WriteLine(value);
}
}
@ -569,12 +605,17 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -569,12 +605,17 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public void NestedLoops()
{
for (int i = 0; i < 10; i++) {
if (i % 2 == 0) {
for (int j = 0; j < 5; j++) {
for (int i = 0; i < 10; i++)
{
if (i % 2 == 0)
{
for (int j = 0; j < 5; j++)
{
Console.WriteLine("Y");
}
} else {
}
else
{
Console.WriteLine("X");
}
}
@ -583,17 +624,22 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -583,17 +624,22 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public int MultipleExits()
{
int num = 0;
while (true) {
if (num % 4 == 0) {
while (true)
{
if (num % 4 == 0)
{
return 4;
}
if (num % 7 == 0) {
if (num % 7 == 0)
{
break;
}
if (num % 9 == 0) {
if (num % 9 == 0)
{
return 5;
}
if (num % 11 == 0) {
if (num % 11 == 0)
{
break;
}
num++;
@ -630,18 +676,25 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -630,18 +676,25 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public int InterestingLoop()
{
int num = 0;
if (num % 11 == 0) {
while (true) {
if (num % 4 == 0) {
if (num % 7 != 0) {
if (num % 11 == 0)
{
while (true)
{
if (num % 4 == 0)
{
if (num % 7 != 0)
{
Console.WriteLine("!7");
break;
}
if (num % 11 != 0) {
if (num % 11 != 0)
{
Console.WriteLine("7");
break;
}
} else {
}
else
{
num++;
}
}
@ -659,14 +712,19 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -659,14 +712,19 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public void WhileLoop()
{
Console.WriteLine("Initial");
if (Condition("if")) {
while (Condition("while")) {
if (Condition("if"))
{
while (Condition("while"))
{
Console.WriteLine("Loop Body");
if (Condition("test")) {
if (Condition("continue")) {
if (Condition("test"))
{
if (Condition("continue"))
{
continue;
}
if (!Condition("break")) {
if (!Condition("break"))
{
break;
}
}
@ -681,15 +739,18 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -681,15 +739,18 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
#if OPT && !MCS
public void WhileWithGoto()
{
while (Condition("Main Loop")) {
if (Condition("Condition")) {
while (Condition("Main Loop"))
{
if (Condition("Condition"))
{
goto IL_000f;
}
// TODO reorder branches with successive block?
goto IL_0026;
IL_000f:
Console.WriteLine("Block1");
if (Condition("Condition2")) {
if (Condition("Condition2"))
{
continue;
}
// TODO remove redundant goto?
@ -704,14 +765,19 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -704,14 +765,19 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public void DoWhileLoop()
{
Console.WriteLine("Initial");
if (Condition("if")) {
do {
if (Condition("if"))
{
do
{
Console.WriteLine("Loop Body");
if (Condition("test")) {
if (Condition("continue")) {
if (Condition("test"))
{
if (Condition("continue"))
{
continue;
}
if (!Condition("break")) {
if (!Condition("break"))
{
break;
}
}
@ -725,30 +791,38 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -725,30 +791,38 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public void Issue1395(int count)
{
Environment.GetCommandLineArgs();
for (int i = 0; i < count; i++) {
for (int i = 0; i < count; i++)
{
Environment.GetCommandLineArgs();
do {
do
{
#if OPT || MCS
IL_0013:
#else
IL_0016:
#endif
Environment.GetCommandLineArgs();
if (Condition("part1")) {
if (Condition("part1"))
{
Environment.GetEnvironmentVariables();
if (Condition("restart")) {
if (Condition("restart"))
{
#if OPT || MCS
goto IL_0013;
#else
goto IL_0016;
#endif
}
} else {
}
else
{
Environment.GetLogicalDrives();
}
Environment.GetCommandLineArgs();
while (count > 0) {
switch (count) {
while (count > 0)
{
switch (count)
{
case 0:
case 1:
case 2:
@ -774,14 +848,19 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -774,14 +848,19 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public void ForLoop()
{
Console.WriteLine("Initial");
if (Condition("if")) {
for (int i = 0; Condition("for"); i++) {
if (Condition("if"))
{
for (int i = 0; Condition("for"); i++)
{
Console.WriteLine("Loop Body");
if (Condition("test")) {
if (Condition("continue")) {
if (Condition("test"))
{
if (Condition("continue"))
{
continue;
}
if (!Condition("not-break")) {
if (!Condition("not-break"))
{
break;
}
}
@ -794,15 +873,20 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -794,15 +873,20 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public void ReturnFromDoWhileInTryFinally()
{
try {
do {
if (Condition("return")) {
try
{
do
{
if (Condition("return"))
{
return;
}
} while (Condition("repeat"));
Environment.GetCommandLineArgs();
} finally {
}
finally
{
Environment.GetCommandLineArgs();
}
@ -811,10 +895,12 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -811,10 +895,12 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public void ForLoopWithEarlyReturn(int[] ids)
{
for (int i = 0; i < ids.Length; i++) {
for (int i = 0; i < ids.Length; i++)
{
Item item = null;
TryGetItem(ids[i], out item);
if (item == null) {
if (item == null)
{
break;
}
}
@ -822,8 +908,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -822,8 +908,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public void ForeachLoopWithEarlyReturn(List<object> items)
{
foreach (object item in items) {
if ((someObject = item) == null) {
foreach (object item in items)
{
if ((someObject = item) == null)
{
break;
}
}
@ -831,16 +919,20 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -831,16 +919,20 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public void NestedForeach(List<object> items1, List<object> items2)
{
foreach (object item in items1) {
foreach (object item in items1)
{
bool flag = false;
foreach (object item2 in items2) {
if (item2 == item) {
foreach (object item2 in items2)
{
if (item2 == item)
{
flag = true;
break;
}
}
if (!flag) {
if (!flag)
{
Console.WriteLine(item);
}
}
@ -849,20 +941,31 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -849,20 +941,31 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public void MergeAroundContinue()
{
for (int i = 0; i < 20; i++) {
if (i % 3 == 0) {
if (i != 6) {
for (int i = 0; i < 20; i++)
{
if (i % 3 == 0)
{
if (i != 6)
{
continue;
}
} else if (i % 5 == 0) {
if (i != 5) {
}
else if (i % 5 == 0)
{
if (i != 5)
{
continue;
}
} else if (i % 7 == 0) {
if (i != 7) {
}
else if (i % 7 == 0)
{
if (i != 7)
{
continue;
}
} else if (i % 11 == 0) {
}
else if (i % 11 == 0)
{
continue;
}

9
ICSharpCode.Decompiler.Tests/TestCases/Pretty/NativeInts.cs

@ -143,15 +143,18 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -143,15 +143,18 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public void CompoundAssign()
{
GetInstance(0).i += i32;
checked {
checked
{
GetInstance(1).i += i32;
}
GetInstance(2).u *= 2u;
checked {
checked
{
GetInstance(3).u *= 2u;
}
GetInstance(4).intptr += (nint)i32;
checked {
checked
{
// Note: the cast is necessary here, without it we'd call IntPtr.op_Addition
// but that is always unchecked.
GetInstance(5).intptr += (nint)i32;

12
ICSharpCode.Decompiler.Tests/TestCases/Pretty/NullPropagation.cs

@ -250,10 +250,12 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -250,10 +250,12 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
private void NotNullPropagation(MyClass c)
{
// don't decompile this to "(c?.IntVal ?? 0) != 0"
if (c != null && c.IntVal != 0) {
if (c != null && c.IntVal != 0)
{
Console.WriteLine("non-zero");
}
if (c == null || c.IntVal == 0) {
if (c == null || c.IntVal == 0)
{
Console.WriteLine("null or zero");
}
Console.WriteLine("end of method");
@ -261,11 +263,13 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -261,11 +263,13 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
private void Setter(MyClass c)
{
if (c != null) {
if (c != null)
{
c.IntVal = 1;
}
Console.WriteLine();
if (c != null) {
if (c != null)
{
c.Property = null;
}
}

6
ICSharpCode.Decompiler.Tests/TestCases/Pretty/OutVariables.cs

@ -25,7 +25,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -25,7 +25,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
{
public static void OutVarInShortCircuit(Dictionary<int, string> d)
{
if (d.Count > 2 && d.TryGetValue(42, out string value)) {
if (d.Count > 2 && d.TryGetValue(42, out string value))
{
Console.WriteLine(value);
}
}
@ -34,7 +35,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -34,7 +35,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
{
// Note: needs reasoning about "definitely assigned if true"
// to ensure that the value is initialized when the delegate is declared.
if (d.Count > 2 && d.TryGetValue(42, out string value)) {
if (d.Count > 2 && d.TryGetValue(42, out string value))
{
return delegate {
Console.WriteLine(value);
};

2
ICSharpCode.Decompiler.Tests/TestCases/Pretty/PInvoke.cs

@ -88,7 +88,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -88,7 +88,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
}
[DllImport("ws2_32.dll", SetLastError = true)]
internal static extern IntPtr ioctlsocket([In] IntPtr socketHandle, [In] int cmd, [In] [Out] ref int argp);
internal static extern IntPtr ioctlsocket([In] IntPtr socketHandle, [In] int cmd, [In][Out] ref int argp);
public void CallMethodWithInOutParameter()
{

3
ICSharpCode.Decompiler.Tests/TestCases/Pretty/QualifierTests.cs

@ -264,7 +264,8 @@ namespace ICSharpCode.Decompiler.Tests.Pretty @@ -264,7 +264,8 @@ namespace ICSharpCode.Decompiler.Tests.Pretty
private void LocalConflictsWithTypeName()
{
for (int i = 0; i < 10; i++) {
for (int i = 0; i < 10; i++)
{
QualifierTests.i.Test();
}
}

6
ICSharpCode.Decompiler.Tests/TestCases/Pretty/QueryExpressions.cs

@ -165,11 +165,11 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -165,11 +165,11 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
let pname = pi.Name
let pvalue = pi.GetValue(customers, null)
select new HbmParam {
Name = pname,
Text = new string[1] {
Name = pname,
Text = new string[1] {
(pvalue == null) ? "null" : pvalue.ToString()
}
}).ToArray();
}).ToArray();
}
public object Join()

288
ICSharpCode.Decompiler.Tests/TestCases/Pretty/ReduceNesting.cs

@ -9,12 +9,14 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -9,12 +9,14 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public void IfIf()
{
if (B(0)) {
if (B(0))
{
Console.WriteLine(0);
return;
}
if (B(1)) {
if (B(1))
{
Console.WriteLine(1);
}
@ -23,13 +25,15 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -23,13 +25,15 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public void IfSwitch()
{
if (B(0)) {
if (B(0))
{
Console.WriteLine(0);
return;
}
Console.WriteLine("switch");
switch (I(0)) {
switch (I(0))
{
case 0:
Console.WriteLine("case 0");
break;
@ -44,13 +48,15 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -44,13 +48,15 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public void IfSwitchSwitch()
{
if (B(0)) {
if (B(0))
{
Console.WriteLine(0);
return;
}
Console.WriteLine("switch 0");
switch (I(1)) {
switch (I(1))
{
case 0:
Console.WriteLine("case 0");
return;
@ -60,7 +66,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -60,7 +66,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
}
Console.WriteLine("switch 1");
switch (I(1)) {
switch (I(1))
{
case 0:
Console.WriteLine("case 0");
break;
@ -75,12 +82,14 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -75,12 +82,14 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public void IfLoop()
{
if (B(0)) {
if (B(0))
{
Console.WriteLine(0);
return;
}
for (int i = 0; i < 10; i++) {
for (int i = 0; i < 10; i++)
{
Console.WriteLine(i);
}
@ -89,14 +98,17 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -89,14 +98,17 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public void LoopContinue()
{
for (int i = 0; i < 10; i++) {
for (int i = 0; i < 10; i++)
{
Console.WriteLine(i);
if (B(0)) {
if (B(0))
{
Console.WriteLine(0);
continue;
}
if (B(1)) {
if (B(1))
{
Console.WriteLine(1);
}
Console.WriteLine("loop-tail");
@ -105,19 +117,23 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -105,19 +117,23 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public void LoopBreak()
{
for (int i = 0; i < 10; i++) {
for (int i = 0; i < 10; i++)
{
Console.WriteLine(i);
if (B(0)) {
if (B(0))
{
Console.WriteLine(0);
continue;
}
if (B(1)) {
if (B(1))
{
Console.WriteLine(1);
break;
}
if (B(2)) {
if (B(2))
{
Console.WriteLine(2);
}
@ -129,16 +145,21 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -129,16 +145,21 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public void LoopBreakElseIf()
{
for (int i = 0; i < 10; i++) {
for (int i = 0; i < 10; i++)
{
Console.WriteLine(i);
if (B(0)) {
if (B(0))
{
Console.WriteLine(0);
continue;
}
if (B(1)) {
if (B(1))
{
Console.WriteLine(1);
} else if (B(2)) {
}
else if (B(2))
{
Console.WriteLine(2);
}
break;
@ -148,7 +169,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -148,7 +169,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public void SwitchIf()
{
switch (I(0)) {
switch (I(0))
{
case 0:
Console.WriteLine("case 0");
return;
@ -157,7 +179,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -157,7 +179,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
return;
}
if (B(0)) {
if (B(0))
{
Console.WriteLine(0);
}
Console.WriteLine("end");
@ -165,8 +188,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -165,8 +188,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public void NestedSwitchIf()
{
if (B(0)) {
switch (I(0)) {
if (B(0))
{
switch (I(0))
{
case 0:
Console.WriteLine("case 0");
return;
@ -175,10 +200,13 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -175,10 +200,13 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
return;
}
if (B(1)) {
if (B(1))
{
Console.WriteLine(1);
}
} else {
}
else
{
Console.WriteLine("else");
}
}
@ -186,8 +214,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -186,8 +214,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
// nesting should not be reduced as maximum nesting level is 1
public void EarlyExit1()
{
if (!B(0)) {
for (int i = 0; i < 10; i++) {
if (!B(0))
{
for (int i = 0; i < 10; i++)
{
Console.WriteLine(i);
}
Console.WriteLine("end");
@ -197,13 +227,16 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -197,13 +227,16 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
// nesting should be reduced as maximum nesting level is 2
public void EarlyExit2()
{
if (B(0)) {
if (B(0))
{
return;
}
for (int i = 0; i < 10; i++) {
for (int i = 0; i < 10; i++)
{
Console.WriteLine(i);
if (i % 2 == 0) {
if (i % 2 == 0)
{
Console.WriteLine("even");
}
}
@ -214,13 +247,18 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -214,13 +247,18 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
// nesting should not be reduced as maximum nesting level is 1 and the else block has no more instructions than any other block
public void BalancedIf()
{
if (B(0)) {
if (B(0))
{
Console.WriteLine("true");
if (B(1)) {
if (B(1))
{
Console.WriteLine(1);
}
} else {
if (B(2)) {
}
else
{
if (B(2))
{
Console.WriteLine(2);
}
Console.WriteLine("false");
@ -229,23 +267,31 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -229,23 +267,31 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public string ComplexCase1(string s)
{
if (B(0)) {
if (B(0))
{
return s;
}
for (int i = 0; i < s.Length; i++) {
if (B(1)) {
for (int i = 0; i < s.Length; i++)
{
if (B(1))
{
Console.WriteLine(1);
} else if (B(2)) {
switch (i) {
}
else if (B(2))
{
switch (i)
{
case 1:
if (B(3)) {
if (B(3))
{
Console.WriteLine(3);
break;
}
Console.WriteLine("case1");
if (B(4)) {
if (B(4))
{
Console.WriteLine(4);
}
break;
@ -255,10 +301,15 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -255,10 +301,15 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
break;
}
Console.WriteLine(2);
} else if (B(5)) {
}
else if (B(5))
{
Console.WriteLine(5);
} else {
if (B(6)) {
}
else
{
if (B(6))
{
Console.WriteLine(6);
}
Console.WriteLine("else");
@ -269,48 +320,64 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -269,48 +320,64 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public void EarlyExitBeforeTry()
{
if (B(0)) {
if (B(0))
{
return;
}
try {
if (B(1)) {
try
{
if (B(1))
{
Console.WriteLine();
}
} catch {
}
catch
{
}
}
public void EarlyExitInTry()
{
try {
if (B(0)) {
try
{
if (B(0))
{
return;
}
Console.WriteLine();
if (B(1)) {
for (int i = 0; i < 10; i++) {
if (B(1))
{
for (int i = 0; i < 10; i++)
{
Console.WriteLine(i);
}
}
} catch {
}
catch
{
}
}
public void ContinueLockInLoop()
{
while (B(0)) {
lock (Console.Out) {
if (B(1)) {
while (B(0))
{
lock (Console.Out)
{
if (B(1))
{
continue;
}
Console.WriteLine();
if (B(2)) {
for (int i = 0; i < 10; i++) {
if (B(2))
{
for (int i = 0; i < 10; i++)
{
Console.WriteLine(i);
}
}
@ -320,18 +387,23 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -320,18 +387,23 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public void BreakLockInLoop()
{
while (B(0)) {
lock (Console.Out) {
while (B(0))
{
lock (Console.Out)
{
// Before ReduceNestingTransform, the rest of the lock body is nested in if(!B(1)) with a continue;
// the B(1) case falls through to a break outside the lock
if (B(1)) {
if (B(1))
{
break;
}
Console.WriteLine();
if (B(2)) {
for (int i = 0; i < 10; i++) {
if (B(2))
{
for (int i = 0; i < 10; i++)
{
Console.WriteLine(i);
}
}
@ -347,16 +419,21 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -347,16 +419,21 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public unsafe void BreakPinnedInLoop(int[] arr)
{
while (B(0)) {
fixed (int* ptr = arr) {
if (B(1)) {
while (B(0))
{
fixed (int* ptr = arr)
{
if (B(1))
{
break;
}
Console.WriteLine();
if (B(2)) {
for (int i = 0; i < 10; i++) {
if (B(2))
{
for (int i = 0; i < 10; i++)
{
Console.WriteLine(ptr[i]);
}
}
@ -370,29 +447,39 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -370,29 +447,39 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public void CannotEarlyExitInTry()
{
try {
if (B(0)) {
try
{
if (B(0))
{
Console.WriteLine();
if (B(1)) {
for (int i = 0; i < 10; i++) {
if (B(1))
{
for (int i = 0; i < 10; i++)
{
Console.WriteLine(i);
}
}
}
} catch {
}
catch
{
}
Console.WriteLine();
}
public void EndpointUnreachableDueToEarlyExit()
{
using (Console.Out) {
if (B(0)) {
using (Console.Out)
{
if (B(0))
{
return;
}
do {
if (B(1)) {
do
{
if (B(1))
{
return;
}
} while (B(2));
@ -402,8 +489,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -402,8 +489,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public void SwitchInTry()
{
try {
switch (I(0)) {
try
{
switch (I(0))
{
case 1:
Console.WriteLine(1);
return;
@ -412,19 +501,25 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -412,19 +501,25 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
return;
}
Console.WriteLine(3);
for (int i = 0; i < 10; i++) {
for (int i = 0; i < 10; i++)
{
Console.WriteLine(i);
}
} catch {
}
catch
{
throw;
}
}
public void SwitchInTryInLoopReturn()
{
for (int i = 0; i < 10; i++) {
try {
switch (I(0)) {
for (int i = 0; i < 10; i++)
{
try
{
switch (I(0))
{
case 1:
Console.WriteLine(1);
return;
@ -433,10 +528,13 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -433,10 +528,13 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
return;
}
Console.WriteLine(3);
for (int j = 0; j < 10; j++) {
for (int j = 0; j < 10; j++)
{
Console.WriteLine(j);
}
} catch {
}
catch
{
throw;
}
}
@ -444,9 +542,12 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -444,9 +542,12 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public void SwitchInTryInLoopContinue()
{
for (int i = 0; i < 10; i++) {
try {
switch (I(0)) {
for (int i = 0; i < 10; i++)
{
try
{
switch (I(0))
{
case 1:
Console.WriteLine(1);
continue;
@ -455,10 +556,13 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -455,10 +556,13 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
continue;
}
Console.WriteLine(3);
for (int j = 0; j < 10; j++) {
for (int j = 0; j < 10; j++)
{
Console.WriteLine(j);
}
} catch {
}
catch
{
throw;
}
}

21
ICSharpCode.Decompiler.Tests/TestCases/Pretty/RefLocalsAndReturns.cs

@ -36,7 +36,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -36,7 +36,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
{
Issue1630[] array = new Issue1630[1];
int num = 0;
while (num >= 0) {
while (num >= 0)
{
ref Issue1630 reference = ref array[num];
Console.WriteLine(reference.data);
num = reference.next;
@ -225,8 +226,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -225,8 +226,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public static ref int FindNumber(int target)
{
for (int i = 0; i < numbers.Length; i++) {
if (numbers[i] >= target) {
for (int i = 0; i < numbers.Length; i++)
{
if (numbers[i] >= target)
{
return ref numbers[i];
}
}
@ -240,7 +243,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -240,7 +243,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public static ref int ElementAtOrDefault(int index)
{
if (index >= 0 && index < numbers.Length) {
if (index >= 0 && index < numbers.Length)
{
return ref numbers[index];
}
return ref DefaultInt;
@ -248,7 +252,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -248,7 +252,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public static ref int LastOrDefault()
{
if (numbers.Length != 0) {
if (numbers.Length != 0)
{
return ref numbers[numbers.Length - 1];
}
return ref DefaultInt;
@ -263,7 +268,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -263,7 +268,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public static ref string GetOrSetString(int index)
{
if (index < 0 || index >= strings.Length) {
if (index < 0 || index >= strings.Length)
{
return ref NullString;
}
@ -285,7 +291,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -285,7 +291,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
{
ref NormalStruct @ref = ref GetRef<NormalStruct>();
RefReassignment(ref @ref);
if (s.GetHashCode() == 0) {
if (s.GetHashCode() == 0)
{
@ref = ref GetRef<NormalStruct>();
}
RefReassignment(ref @ref.GetHashCode() == 4 ? ref @ref : ref s);

140
ICSharpCode.Decompiler.Tests/TestCases/Pretty/ShortCircuit.cs

@ -69,9 +69,12 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -69,9 +69,12 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public void StmtAnd2()
{
if (F(0) && F(1)) {
if (F(0) && F(1))
{
M1();
} else {
}
else
{
M2();
}
E();
@ -79,16 +82,20 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -79,16 +82,20 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public void StmtOr2A()
{
if (F(0) || F(1)) {
if (F(0) || F(1))
{
M1();
}
}
public void StmtOr2B()
{
if (F(0) || F(1)) {
if (F(0) || F(1))
{
M1();
} else {
}
else
{
M2();
}
E();
@ -96,9 +103,12 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -96,9 +103,12 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public void StmtAnd3()
{
if (F(0) && F(1) && F(2)) {
if (F(0) && F(1) && F(2))
{
M1();
} else {
}
else
{
M2();
}
E();
@ -106,9 +116,12 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -106,9 +116,12 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public void StmtOr3()
{
if (F(0) || F(1) || F(2)) {
if (F(0) || F(1) || F(2))
{
M1();
} else {
}
else
{
M2();
}
E();
@ -116,9 +129,12 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -116,9 +129,12 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public void StmtOr4()
{
if (GetInt(0) != 0 || GetInt(1) != 0) {
if (GetInt(0) != 0 || GetInt(1) != 0)
{
M1();
} else {
}
else
{
M2();
}
E();
@ -126,73 +142,92 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -126,73 +142,92 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public void StmtMix3A()
{
if ((F(0) || F(1)) && F(2)) {
if ((F(0) || F(1)) && F(2))
{
M1();
}
}
public void StmtMix3B()
{
if ((F(0) || F(1)) && F(2)) {
if ((F(0) || F(1)) && F(2))
{
M1();
} else {
}
else
{
M2();
}
}
public void StmtMix4V1A()
{
if (((F(0) || F(1)) && F(2)) || F(3)) {
if (((F(0) || F(1)) && F(2)) || F(3))
{
M1();
}
}
public void StmtMix4V1B()
{
if (((F(0) || F(1)) && F(2)) || F(3)) {
if (((F(0) || F(1)) && F(2)) || F(3))
{
M1();
} else {
}
else
{
M2();
}
}
public void StmtMix4V2A()
{
if ((F(0) || F(1)) && (F(2) || F(3))) {
if ((F(0) || F(1)) && (F(2) || F(3)))
{
M1();
}
}
public void StmtMix4V2B()
{
if ((F(0) || F(1)) && (F(2) || F(3))) {
if ((F(0) || F(1)) && (F(2) || F(3)))
{
M1();
} else {
}
else
{
M2();
}
}
public void StmtMix4V3A()
{
if ((F(0) && F(1)) || (F(2) && F(3))) {
if ((F(0) && F(1)) || (F(2) && F(3)))
{
M1();
}
}
public void StmtMix4V3B()
{
if ((F(0) && F(1)) || (F(2) && F(3))) {
if ((F(0) && F(1)) || (F(2) && F(3)))
{
M1();
} else {
}
else
{
M2();
}
}
public void StmtComplex()
{
if (F(0) && F(1) && !F(2) && (F(3) || F(4))) {
if (F(0) && F(1) && !F(2) && (F(3) || F(4)))
{
M1();
} else {
}
else
{
M2();
}
E();
@ -200,9 +235,12 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -200,9 +235,12 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public void StmtComplex2(int i)
{
if (i > 1000 || (i >= 1 && i <= 8) || i == 42) {
if (i > 1000 || (i >= 1 && i <= 8) || i == 42)
{
M1();
} else {
}
else
{
M2();
}
E();
@ -210,9 +248,12 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -210,9 +248,12 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public void StmtComplex3(int i)
{
if (i > 1000 || (i >= 1 && i <= 8) || (i >= 100 && i <= 200) || i == 42) {
if (i > 1000 || (i >= 1 && i <= 8) || (i >= 100 && i <= 200) || i == 42)
{
M1();
} else {
}
else
{
M2();
}
E();
@ -220,9 +261,12 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -220,9 +261,12 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public void StmtComplex4(int i)
{
if (i > 1000 || (i >= 1 && i <= 8) || i == 42 || i == 23) {
if (i > 1000 || (i >= 1 && i <= 8) || i == 42 || i == 23)
{
M1();
} else {
}
else
{
M2();
}
E();
@ -230,11 +274,15 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -230,11 +274,15 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public void StmtComplex5()
{
if (F(0)) {
if (!F(1) && !F(2)) {
if (F(0))
{
if (!F(1) && !F(2))
{
return;
}
} else if (!F(3) || !F(4)) {
}
else if (!F(3) || !F(4))
{
M2();
return;
}
@ -243,9 +291,11 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -243,9 +291,11 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public int StmtComplex6()
{
if (F(0)) {
if (F(0))
{
M1();
if (F(1) || F(2)) {
if (F(1) || F(2))
{
return 1;
}
}
@ -254,7 +304,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -254,7 +304,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public int InferCorrectOrder()
{
if (F(1) || F(2)) {
if (F(1) || F(2))
{
return 1;
}
return 2;
@ -263,15 +314,20 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -263,15 +314,20 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
#if !OPT
public void EmptyIf()
{
if (F(0)) {
if (F(0))
{
}
if (!F(1)) {
if (!F(1))
{
}
if (F(2) && F(3)) {
if (F(2) && F(3))
{
}
if (F(4) || F(5)) {
if (F(4) || F(5))
{
}
if (F(0) && F(1) && !F(2) && (F(3) || F(4))) {
if (F(0) && F(1) && !F(2) && (F(3) || F(4)))
{
}
E();
}

368
ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.cs

@ -52,7 +52,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -52,7 +52,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
#if !ROSLYN
public static State SwitchOverNullableBool(bool? value)
{
switch (value) {
switch (value)
{
case false:
return State.False;
case true:
@ -67,7 +68,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -67,7 +68,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public static bool? SwitchOverNullableEnum(State? state)
{
switch (state) {
switch (state)
{
case State.False:
return false;
case State.True:
@ -82,7 +84,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -82,7 +84,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public static string SparseIntegerSwitch(int i)
{
Console.WriteLine("SparseIntegerSwitch: " + i);
switch (i) {
switch (i)
{
case -10000000:
return "-10 mln";
case -100:
@ -112,7 +115,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -112,7 +115,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public static void SparseIntegerSwitch2(int i)
{
switch (i) {
switch (i)
{
case 4:
case 10:
case 11:
@ -130,7 +134,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -130,7 +134,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public static bool SparseIntegerSwitch3(int i)
{
switch (i) {
switch (i)
{
case 0:
case 10:
case 11:
@ -146,7 +151,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -146,7 +151,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public static string SwitchOverNullableInt(int? i)
{
switch (i) {
switch (i)
{
case null:
return "null";
case 0:
@ -162,7 +168,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -162,7 +168,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public static string SwitchOverNullableIntNullCaseCombined(int? i)
{
switch (i) {
switch (i)
{
case null:
case 0:
return "zero";
@ -177,7 +184,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -177,7 +184,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public static string SwitchOverNullableIntShifted(int? i)
{
switch (i + 5) {
switch (i + 5)
{
case null:
return "null";
case 0:
@ -193,7 +201,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -193,7 +201,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public static string SwitchOverNullableIntShiftedNullCaseCombined(int? i)
{
switch (i + 5) {
switch (i + 5)
{
case null:
case 0:
return "zero";
@ -208,7 +217,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -208,7 +217,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public static string SwitchOverNullableIntNoNullCase(int? i)
{
switch (i) {
switch (i)
{
case 0:
return "zero";
case 5:
@ -222,7 +232,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -222,7 +232,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public static string SwitchOverNullableIntNoNullCaseShifted(int? i)
{
switch (i + 5) {
switch (i + 5)
{
case 0:
return "zero";
case 5:
@ -236,7 +247,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -236,7 +247,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public static void SwitchOverInt(int i)
{
switch (i) {
switch (i)
{
case 0:
Console.WriteLine("zero");
break;
@ -264,7 +276,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -264,7 +276,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
// SwitchDetection.UseCSharpSwitch requires more complex heuristic to identify this when compiled with Roslyn
public static void CompactSwitchOverInt(int i)
{
switch (i) {
switch (i)
{
case 0:
case 1:
case 2:
@ -283,7 +296,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -283,7 +296,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public static string ShortSwitchOverString(string text)
{
Console.WriteLine("ShortSwitchOverString: " + text);
switch (text) {
switch (text)
{
case "First case":
return "Text1";
case "Second case":
@ -298,7 +312,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -298,7 +312,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public static string ShortSwitchOverStringWithNullCase(string text)
{
Console.WriteLine("ShortSwitchOverStringWithNullCase: " + text);
switch (text) {
switch (text)
{
case "First case":
return "Text1";
case "Second case":
@ -313,7 +328,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -313,7 +328,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public static string SwitchOverString1(string text)
{
Console.WriteLine("SwitchOverString1: " + text);
switch (text) {
switch (text)
{
case "First case":
return "Text1";
case "Second case":
@ -337,7 +353,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -337,7 +353,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public static string SwitchOverString2()
{
Console.WriteLine("SwitchOverString2:");
switch (Environment.UserName) {
switch (Environment.UserName)
{
case "First case":
return "Text1";
case "Second case":
@ -369,7 +386,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -369,7 +386,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public static string SwitchOverBool(bool b)
{
Console.WriteLine("SwitchOverBool: " + b);
switch (b) {
switch (b)
{
case true:
return bool.TrueString;
case false:
@ -383,8 +401,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -383,8 +401,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public static void SwitchInLoop(int i)
{
Console.WriteLine("SwitchInLoop: " + i);
while (true) {
switch (i) {
while (true)
{
switch (i)
{
case 1:
Console.WriteLine("one");
break;
@ -409,7 +429,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -409,7 +429,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public static void SwitchWithGoto(int i)
{
Console.WriteLine("SwitchWithGoto: " + i);
switch (i) {
switch (i)
{
case 1:
Console.WriteLine("one");
goto default;
@ -433,7 +454,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -433,7 +454,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public static void SwitchWithGotoString(string s)
{
Console.WriteLine("SwitchWithGotoString: " + s);
switch (s) {
switch (s)
{
case "1":
Console.WriteLine("one");
goto default;
@ -471,7 +493,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -471,7 +493,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public static void SwitchWithGotoComplex(string s)
{
Console.WriteLine("SwitchWithGotoComplex: " + s);
switch (s) {
switch (s)
{
case "1":
Console.WriteLine("one");
goto case "8";
@ -480,7 +503,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -480,7 +503,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
goto case "3";
case "3":
Console.WriteLine("three");
if (s.Length != 2) {
if (s.Length != 2)
{
break;
}
goto case "5";
@ -518,10 +542,12 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -518,10 +542,12 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
List<SetProperty> list = new List<SetProperty>();
List<SetProperty> list2 = new List<SetProperty>();
SetProperty[] properties = GetProperties();
for (int i = 0; i < properties.Length; i++) {
for (int i = 0; i < properties.Length; i++)
{
Console.WriteLine("In for-loop");
SetProperty setProperty = properties[i];
switch (setProperty.Property.Name) {
switch (setProperty.Property.Name)
{
case "Name1":
setProperty.Set = 1;
list.Add(setProperty);
@ -551,8 +577,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -551,8 +577,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public static void SwitchInTryBlock(string value)
{
try {
switch (value.Substring(5)) {
try
{
switch (value.Substring(5))
{
case "Name1":
Console.WriteLine("1");
break;
@ -573,14 +601,17 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -573,14 +601,17 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
Console.WriteLine("default");
break;
}
} catch (Exception) {
}
catch (Exception)
{
Console.WriteLine("catch block");
}
}
public static void SwitchWithComplexCondition(string[] args)
{
switch ((args.Length == 0) ? "dummy" : args[0]) {
switch ((args.Length == 0) ? "dummy" : args[0])
{
case "a":
Console.WriteLine("a");
break;
@ -599,7 +630,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -599,7 +630,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public static void SwitchWithArray(string[] args)
{
switch (args[0]) {
switch (args[0])
{
case "a":
Console.WriteLine("a");
break;
@ -618,19 +650,23 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -618,19 +650,23 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public static void SwitchWithContinue1(int i, bool b)
{
while (true) {
switch (i) {
while (true)
{
switch (i)
{
#if OPT
case 1:
continue;
#endif
case 0:
if (b) {
if (b)
{
continue;
}
break;
case 2:
if (!b) {
if (!b)
{
continue;
}
break;
@ -646,10 +682,13 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -646,10 +682,13 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
// while condition, return and break cases
public static void SwitchWithContinue2(int i, bool b)
{
while (i < 10) {
switch (i) {
while (i < 10)
{
switch (i)
{
case 0:
if (b) {
if (b)
{
Console.WriteLine("0b");
continue;
}
@ -657,14 +696,16 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -657,14 +696,16 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
break;
case 2:
#if OPT
if (b) {
if (b)
{
Console.WriteLine("2b");
return;
}
Console.WriteLine("2!b");
continue;
#else
if (!b) {
if (!b)
{
Console.WriteLine("2!b");
continue;
}
@ -687,10 +728,13 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -687,10 +728,13 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
// for loop version
public static void SwitchWithContinue3(bool b)
{
for (int i = 0; i < 10; i++) {
switch (i) {
for (int i = 0; i < 10; i++)
{
switch (i)
{
case 0:
if (b) {
if (b)
{
Console.WriteLine("0b");
continue;
}
@ -698,14 +742,16 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -698,14 +742,16 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
break;
case 2:
#if OPT
if (b) {
if (b)
{
Console.WriteLine("2b");
return;
}
Console.WriteLine("2!b");
continue;
#else
if (!b) {
if (!b)
{
Console.WriteLine("2!b");
continue;
}
@ -727,16 +773,20 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -727,16 +773,20 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
// foreach version
public static void SwitchWithContinue4(bool b)
{
foreach (int item in Enumerable.Range(0, 10)) {
foreach (int item in Enumerable.Range(0, 10))
{
Console.WriteLine("loop: " + item);
switch (item) {
switch (item)
{
case 1:
if (b) {
if (b)
{
continue;
}
break;
case 3:
if (!b) {
if (!b)
{
continue;
}
return;
@ -747,20 +797,24 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -747,20 +797,24 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
Console.WriteLine(5);
goto default;
case 6:
if (b) {
if (b)
{
continue;
}
goto case 3;
case 7:
if (item % 2 == 0) {
if (item % 2 == 0)
{
goto case 3;
}
if (!b) {
if (!b)
{
continue;
}
goto case 8;
case 8:
if (b) {
if (b)
{
continue;
}
goto case 5;
@ -776,11 +830,15 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -776,11 +830,15 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
// internal if statement, loop increment block not dominated by the switch head
public static void SwitchWithContinue5(bool b)
{
for (int i = 0; i < 10; i++) {
if (i < 5) {
switch (i) {
for (int i = 0; i < 10; i++)
{
if (i < 5)
{
switch (i)
{
case 0:
if (b) {
if (b)
{
Console.WriteLine("0b");
continue;
}
@ -788,14 +846,16 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -788,14 +846,16 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
break;
case 2:
#if OPT
if (b) {
if (b)
{
Console.WriteLine("2b");
return;
}
Console.WriteLine("2!b");
continue;
#else
if (!b) {
if (!b)
{
Console.WriteLine("2!b");
continue;
}
@ -819,10 +879,13 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -819,10 +879,13 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
// do-while loop version
public static void SwitchWithContinue6(int i, bool b)
{
do {
switch (i) {
do
{
switch (i)
{
case 0:
if (!b) {
if (!b)
{
Console.WriteLine("0!b");
break;
}
@ -830,7 +893,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -830,7 +893,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
// ConditionDetection doesn't recognise Do-While continues yet
continue;
case 2:
if (b) {
if (b)
{
Console.WriteLine("2b");
return;
}
@ -851,9 +915,11 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -851,9 +915,11 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
// double break from switch to loop exit requires additional pattern matching in HighLevelLoopTransform
public static void SwitchWithContinue7()
{
for (int num = 0; num >= 0; num--) {
for (int num = 0; num >= 0; num--)
{
Console.WriteLine("loop-head");
switch (num) {
switch (num)
{
default:
Console.WriteLine("default");
break;
@ -870,9 +936,12 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -870,9 +936,12 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public static void SwitchWithContinueInDoubleLoop()
{
bool value = false;
for (int i = 0; i < 10; i++) {
for (int j = 0; j < 10; j++) {
switch (i + j) {
for (int i = 0; i < 10; i++)
{
for (int j = 0; j < 10; j++)
{
switch (i + j)
{
case 1:
case 3:
case 5:
@ -893,8 +962,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -893,8 +962,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public static void SwitchLoopNesting()
{
for (int i = 0; i < 10; i++) {
switch (i) {
for (int i = 0; i < 10; i++)
{
switch (i)
{
case 0:
Console.WriteLine(0);
break;
@ -902,8 +973,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -902,8 +973,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
Console.WriteLine(1);
break;
default:
if (i % 2 == 0) {
while (i % 3 != 0) {
if (i % 2 == 0)
{
while (i % 3 != 0)
{
Console.WriteLine(i++);
}
}
@ -911,9 +984,12 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -911,9 +984,12 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
break;
}
if (i > 4) {
if (i > 4)
{
Console.WriteLine("high");
} else {
}
else
{
Console.WriteLine("low");
}
}
@ -925,7 +1001,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -925,7 +1001,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
#if ROSLYN || OPT
public static void SingleIf1(int i, bool a)
{
if (i == 1 || (i == 2 && a)) {
if (i == 1 || (i == 2 && a))
{
Console.WriteLine(1);
}
Console.WriteLine(2);
@ -934,7 +1011,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -934,7 +1011,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public static void SingleIf2(int i, bool a, bool b)
{
if (i == 1 || (i == 2 && a) || (i == 3 && b)) {
if (i == 1 || (i == 2 && a) || (i == 3 && b))
{
Console.WriteLine(1);
}
Console.WriteLine(2);
@ -942,7 +1020,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -942,7 +1020,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public static void SingleIf3(int i, bool a, bool b)
{
if (a || i == 1 || (i == 2 && b)) {
if (a || i == 1 || (i == 2 && b))
{
Console.WriteLine(1);
}
Console.WriteLine(2);
@ -950,7 +1029,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -950,7 +1029,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public static void SingleIf4(int i, bool a)
{
if (i == 1 || i == 2 || (i != 3 && a) || i != 4) {
if (i == 1 || i == 2 || (i != 3 && a) || i != 4)
{
Console.WriteLine(1);
}
Console.WriteLine(2);
@ -958,8 +1038,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -958,8 +1038,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public static void NestedIf(int i)
{
if (i != 1) {
if (i == 2) {
if (i != 1)
{
if (i == 2)
{
Console.WriteLine(2);
}
Console.WriteLine("default");
@ -969,19 +1051,32 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -969,19 +1051,32 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public static void IfChainWithCondition(int i)
{
if (i == 0) {
if (i == 0)
{
Console.WriteLine(0);
} else if (i == 1) {
}
else if (i == 1)
{
Console.WriteLine(1);
} else if (i == 2) {
}
else if (i == 2)
{
Console.WriteLine(2);
} else if (i == 3) {
}
else if (i == 3)
{
Console.WriteLine(3);
} else if (i == 4) {
}
else if (i == 4)
{
Console.WriteLine(4);
} else if (i == 5 && Console.CapsLock) {
}
else if (i == 5 && Console.CapsLock)
{
Console.WriteLine("5A");
} else {
}
else
{
Console.WriteLine("default");
}
@ -990,37 +1085,48 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -990,37 +1085,48 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public static bool SwitchlikeIf(int i, int j)
{
if (i != 0 && j != 0) {
if (i == -1 && j == -1) {
if (i != 0 && j != 0)
{
if (i == -1 && j == -1)
{
Console.WriteLine("-1, -1");
}
if (i == -1 && j == 1) {
if (i == -1 && j == 1)
{
Console.WriteLine("-1, 1");
}
if (i == 1 && j == -1) {
if (i == 1 && j == -1)
{
Console.WriteLine("1, -1");
}
if (i == 1 && j == 1) {
if (i == 1 && j == 1)
{
Console.WriteLine("1, 1");
}
return false;
}
if (i != 0) {
if (i == -1) {
if (i != 0)
{
if (i == -1)
{
Console.WriteLine("-1, 0");
}
if (i == 1) {
if (i == 1)
{
Console.WriteLine("1, 0");
}
return false;
}
if (j != 0) {
if (j == -1) {
if (j != 0)
{
if (j == -1)
{
Console.WriteLine("0, -1");
}
if (j == 1) {
if (j == 1)
{
Console.WriteLine("0, 1");
}
return false;
@ -1031,15 +1137,19 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -1031,15 +1137,19 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public static bool SwitchlikeIf2(int i)
{
if (i != 0) {
if (i != 0)
{
// note that using else-if in this chain creates a nice-looking switch here (as expected)
if (i == 1) {
if (i == 1)
{
Console.WriteLine(1);
}
if (i == 2) {
if (i == 2)
{
Console.WriteLine(2);
}
if (i == 3) {
if (i == 3)
{
Console.WriteLine(3);
}
return false;
@ -1049,7 +1159,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -1049,7 +1159,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public static void SingleIntervalIf(char c)
{
if (c >= 'A' && c <= 'Z') {
if (c >= 'A' && c <= 'Z')
{
Console.WriteLine("alphabet");
}
Console.WriteLine("end");
@ -1057,8 +1168,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -1057,8 +1168,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public static bool Loop8(char c, bool b, Func<char> getChar)
{
if (b) {
while ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) {
if (b)
{
while ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'))
{
c = getChar();
}
}
@ -1069,7 +1182,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -1069,7 +1182,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public static void Loop9(Func<char> getChar)
{
char c;
do {
do
{
c = getChar();
} while (c != -1 && c != '\n' && c != '\u2028' && c != '\u2029');
}
@ -1078,8 +1192,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -1078,8 +1192,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
// Ensure correctness of SwitchDetection.UseCSharpSwitch control flow heuristics
public static void SwitchWithBreakCase(int i, bool b)
{
if (b) {
switch (i) {
if (b)
{
switch (i)
{
case 1:
Console.WriteLine(1);
break;
@ -1096,14 +1212,17 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -1096,14 +1212,17 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public static void SwitchWithReturnAndBreak(int i, bool b)
{
switch (i) {
switch (i)
{
case 0:
if (b) {
if (b)
{
return;
}
break;
case 1:
if (!b) {
if (!b)
{
return;
}
break;
@ -1113,13 +1232,15 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -1113,13 +1232,15 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public static int SwitchWithReturnAndBreak2(int i, bool b)
{
switch (i) {
switch (i)
{
case 4:
case 33:
Console.WriteLine();
return 1;
case 334:
if (b) {
if (b)
{
return 2;
}
break;
@ -1135,7 +1256,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -1135,7 +1256,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public static void SwitchWithReturnAndBreak3(int i)
{
switch (i) {
switch (i)
{
default:
return;
case 0:
@ -1150,10 +1272,12 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -1150,10 +1272,12 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public static string Issue1621(int x)
{
if (x == 5) {
if (x == 5)
{
return "5";
}
switch (x) {
switch (x)
{
case 1:
return "1";
case 2:
@ -1173,7 +1297,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -1173,7 +1297,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public static int Issue1602(string x)
{
switch (x) {
switch (x)
{
case null:
return 0;
case "":
@ -1197,7 +1322,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -1197,7 +1322,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public static void Issue1745(string aaa)
{
switch (aaa) {
switch (aaa)
{
case "a":
case "b":
case "c":
@ -1218,7 +1344,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -1218,7 +1344,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public static bool DoNotRemoveAssignmentBeforeSwitch(string x, out ConsoleKey key)
{
key = (ConsoleKey)0;
switch (x) {
switch (x)
{
case "A":
key = ConsoleKey.A;
break;
@ -1234,7 +1361,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -1234,7 +1361,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public static void Issue1767(string s)
{
switch (s) {
switch (s)
{
case "a":
ch1767 = s[0];
break;

21
ICSharpCode.Decompiler.Tests/TestCases/Pretty/SwitchExpressions.cs

@ -31,7 +31,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -31,7 +31,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public static bool? SwitchOverNullableEnum(State? state)
{
return state switch {
return state switch
{
State.False => false,
State.True => true,
State.Null => null,
@ -42,7 +43,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -42,7 +43,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public static string SparseIntegerSwitch(int i)
{
Console.WriteLine("SparseIntegerSwitch: " + i);
return i switch {
return i switch
{
-10000000 => "-10 mln",
-100 => "-hundred",
-1 => "-1",
@ -61,7 +63,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -61,7 +63,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public static bool SparseIntegerSwitch3(int i)
{
// not using a switch expression because we'd have to duplicate the 'true' branch
switch (i) {
switch (i)
{
case 0:
case 10:
case 11:
@ -77,7 +80,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -77,7 +80,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public static string SwitchOverNullableInt(int? i, int? j)
{
return (i + j) switch {
return (i + j) switch
{
null => "null",
0 => "zero",
5 => "five",
@ -88,7 +92,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -88,7 +92,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public static void SwitchOverInt(int i)
{
Console.WriteLine(i switch {
Console.WriteLine(i switch
{
0 => "zero",
5 => "five",
10 => "ten",
@ -103,7 +108,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -103,7 +108,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public static string SwitchOverString1(string text)
{
Console.WriteLine("SwitchOverString1: " + text);
return text switch {
return text switch
{
"First case" => "Text1",
"Second case" => "Text2",
"Third case" => "Text3",
@ -119,7 +125,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -119,7 +125,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
{
Console.WriteLine("SwitchOverString1: " + text);
// Cannot use switch expression, because "return Text2;" would need to be duplicated
switch (text) {
switch (text)
{
case "First case":
return "Text1";
case "Second case":

3
ICSharpCode.Decompiler.Tests/TestCases/Pretty/ThrowExpressions.cs

@ -32,7 +32,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -32,7 +32,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
private static int? GetIntOrNull(string v)
{
if (int.TryParse(v, out int result)) {
if (int.TryParse(v, out int result))
{
return result;
}

12
ICSharpCode.Decompiler.Tests/TestCases/Pretty/TupleTests.cs

@ -129,7 +129,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -129,7 +129,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public void UseDict()
{
if (TupleDict.Count > 10) {
if (TupleDict.Count > 10)
{
TupleDict.Clear();
}
// TODO: it would be nice if we could infer the name 'c' for the local
@ -153,21 +154,24 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -153,21 +154,24 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public void Foreach(IEnumerable<(int, string)> input)
{
foreach (var item in input) {
foreach (var item in input)
{
Console.WriteLine($"{item.Item1}: {item.Item2}");
}
}
public void ForeachNamedElements(IEnumerable<(int Index, string Data)> input)
{
foreach (var item in input) {
foreach (var item in input)
{
Console.WriteLine($"{item.Index}: {item.Data}");
}
}
public void NonGenericForeach(IEnumerable input)
{
foreach ((string, int) item in input) {
foreach ((string, int) item in input)
{
Console.WriteLine($"{item.Item1}: {item.Item2}");
}
}

3
ICSharpCode.Decompiler.Tests/TestCases/Pretty/TypeAnalysisTests.cs

@ -118,7 +118,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -118,7 +118,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public void TernaryOp(Random a, Random b, bool c)
{
if ((c ? a : b) == null) {
if ((c ? a : b) == null)
{
Console.WriteLine();
}
}

2
ICSharpCode.Decompiler.Tests/TestCases/Pretty/TypeMemberTests.cs

@ -201,7 +201,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -201,7 +201,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
}
}
public interface T15_IMyInterface_PropertyInterfaceImplementation
{
{
int MyProperty {
get;
set;

61
ICSharpCode.Decompiler.Tests/TestCases/Pretty/UnsafeCode.cs

@ -170,7 +170,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -170,7 +170,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public unsafe void PassRefParameterAsPointer(ref int p)
{
fixed (int* ptr = &p) {
fixed (int* ptr = &p)
{
UsePointer(ptr);
}
}
@ -187,7 +188,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -187,7 +188,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public unsafe void AddressInMultiDimensionalArray(double[,] matrix)
{
fixed (double* d = &matrix[1, 2]) {
fixed (double* d = &matrix[1, 2])
{
PointerReferenceExpression(d);
PointerReferenceExpression(d);
}
@ -195,8 +197,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -195,8 +197,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public unsafe void FixedStringAccess(string text)
{
fixed (char* ptr = text) {
for (char* ptr2 = ptr; *ptr2 == 'a'; ptr2++) {
fixed (char* ptr = text)
{
for (char* ptr2 = ptr; *ptr2 == 'a'; ptr2++)
{
*ptr2 = 'A';
}
}
@ -204,7 +208,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -204,7 +208,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public unsafe void FixedStringNoPointerUse(string text)
{
fixed (char* ptr = text) {
fixed (char* ptr = text)
{
}
}
@ -213,21 +218,24 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -213,21 +218,24 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
// leaving no pinned region we could detect.
public unsafe void FixedArrayNoPointerUse(int[] arr)
{
fixed (int* ptr = arr) {
fixed (int* ptr = arr)
{
}
}
#endif
public unsafe void PutDoubleIntoLongArray1(long[] array, int index, double val)
{
fixed (long* ptr = array) {
fixed (long* ptr = array)
{
*(double*)(ptr + index) = val;
}
}
public unsafe void PutDoubleIntoLongArray2(long[] array, int index, double val)
{
fixed (long* ptr = &array[index]) {
fixed (long* ptr = &array[index])
{
*(double*)ptr = val;
}
}
@ -355,7 +363,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -355,7 +363,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public unsafe void PinFixedMember(ref StructWithFixedSizeMembers m)
{
fixed (int* ptr = m.Integers) {
fixed (int* ptr = m.Integers)
{
UsePointer(ptr);
}
}
@ -376,7 +385,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -376,7 +385,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public unsafe void FixedMultiDimArray(int[,] arr)
{
fixed (int* ptr = arr) {
fixed (int* ptr = arr)
{
UsePointer(ptr);
}
}
@ -384,7 +394,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -384,7 +394,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
#if CS73
public unsafe void FixedSpan(Span<int> span)
{
fixed (int* ptr = span) {
fixed (int* ptr = span)
{
UsePointer(ptr);
}
}
@ -401,7 +412,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -401,7 +412,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
{
char* ptr = stackalloc char[count];
char* ptr2 = stackalloc char[100];
for (int i = 0; i < count; i++) {
for (int i = 0; i < count; i++)
{
ptr[i] = (char)i;
ptr2[i] = '\0';
}
@ -417,7 +429,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -417,7 +429,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
#endif
ptr->X = count;
ptr[1].X = ptr->X;
for (int i = 2; i < 10; i++) {
for (int i = 2; i < 10; i++)
{
ptr[i].X = count;
}
return UsePointer(&ptr->Y);
@ -450,13 +463,18 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -450,13 +463,18 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
private unsafe static ResultStruct NestedFixedBlocks(byte[] array)
{
try {
fixed (byte* ptr = array) {
fixed (byte* ptr2 = Get<byte[]>()) {
try
{
fixed (byte* ptr = array)
{
fixed (byte* ptr2 = Get<byte[]>())
{
return new ResultStruct(ptr, ptr2);
}
}
} finally {
}
finally
{
Console.WriteLine("Finally");
}
}
@ -468,17 +486,20 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -468,17 +486,20 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
private unsafe static object Issue1386(int arraySize, bool createFirstBuffer)
{
if (createFirstBuffer) {
if (createFirstBuffer)
{
byte[] array = new byte[arraySize];
Console.WriteLine("first fixed");
fixed (byte* ptr = array) {
fixed (byte* ptr = array)
{
return CreateBuffer(array.Length, ptr);
}
}
byte[] array2 = new byte[arraySize];
Console.WriteLine("second fixed");
fixed (byte* ptr2 = array2) {
fixed (byte* ptr2 = array2)
{
return CreateBuffer(array2.Length, ptr2);
}
}

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

@ -62,7 +62,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -62,7 +62,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
// roslyn optimizes out the try-finally; mcs has a compiler bug on using(null-literal)
public void SimpleUsingNullStatement()
{
using (null) {
using (null)
{
Console.WriteLine("using (null)");
}
}
@ -70,14 +71,16 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -70,14 +71,16 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public void SimpleUsingExpressionStatement()
{
using (new MemoryStream()) {
using (new MemoryStream())
{
Console.WriteLine("using-body");
}
}
public void SimpleUsingExpressionStatementWithDeclaration()
{
using (MemoryStream memoryStream = new MemoryStream()) {
using (MemoryStream memoryStream = new MemoryStream())
{
memoryStream.WriteByte(42);
Console.WriteLine("using-body: " + memoryStream.Position);
}
@ -86,7 +89,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -86,7 +89,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public void UsingStatementThatChangesTheVariable()
{
CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();
using (cancellationTokenSource) {
using (cancellationTokenSource)
{
cancellationTokenSource = new CancellationTokenSource();
}
cancellationTokenSource.Cancel();
@ -94,49 +98,56 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -94,49 +98,56 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public void UsingStatementOnStruct()
{
using (new UsingStruct(1)) {
using (new UsingStruct(1))
{
Console.WriteLine("using-body");
}
}
public void UsingStatementOnStructWithVariable()
{
using (UsingStruct usingStruct = new UsingStruct(2)) {
using (UsingStruct usingStruct = new UsingStruct(2))
{
Console.WriteLine("using-body: " + usingStruct);
}
}
private void UsingStatementOnNullableStruct(UsingStruct? us)
{
using (us) {
using (us)
{
Console.WriteLine("using-body: " + us.ToString());
}
}
public void GenericUsing<T>(T t) where T : IDisposable
{
using (t) {
using (t)
{
Console.WriteLine(t);
}
}
public void GenericStructUsing<T>(T t) where T : struct, IDisposable
{
using (t) {
using (t)
{
Console.WriteLine(t);
}
}
public void GenericClassUsing<T>(T t) where T : class, IDisposable
{
using (t) {
using (t)
{
Console.WriteLine(t);
}
}
public void GenericNullableUsing<T>(T? t) where T : struct, IDisposable
{
using (t) {
using (t)
{
Console.WriteLine(t);
}
}
@ -144,7 +155,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -144,7 +155,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
#if CS80
public void UsingRefStruct1(UsingRefStruct s)
{
using (s) {
using (s)
{
Console.WriteLine(s.i);
}
}

6
ICSharpCode.Decompiler.Tests/TestCases/Pretty/UsingVariables.cs

@ -54,7 +54,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -54,7 +54,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public void NotAUsingVar()
{
Console.WriteLine("before using");
using (IDisposable disposable = GetDisposable()) {
using (IDisposable disposable = GetDisposable())
{
Console.WriteLine("inside using");
Use(disposable);
}
@ -63,7 +64,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -63,7 +64,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public void UsingVarInNestedBlocks(bool condition)
{
if (condition) {
if (condition)
{
using IDisposable disposable = GetDisposable();
Console.WriteLine("inside using");
Use(disposable);

9
ICSharpCode.Decompiler.Tests/TestCases/Pretty/ValueTypes.cs

@ -228,21 +228,24 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -228,21 +228,24 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public static void UseRefBoolInCondition(ref bool x)
{
if (x) {
if (x)
{
Console.WriteLine("true");
}
}
public static void CompareNotEqual0IsReallyNotEqual(IComparable<int> a)
{
if (a.CompareTo(0) != 0) {
if (a.CompareTo(0) != 0)
{
Console.WriteLine("true");
}
}
public static void CompareEqual0IsReallyEqual(IComparable<int> a)
{
if (a.CompareTo(0) == 0) {
if (a.CompareTo(0) == 0)
{
Console.WriteLine("true");
}
}

181
ICSharpCode.Decompiler.Tests/TestCases/Pretty/YieldReturn.cs

@ -47,7 +47,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -47,7 +47,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
internal static void Print<T>(string name, IEnumerator<T> enumerator)
{
Console.WriteLine(name + ": Test start");
while (enumerator.MoveNext()) {
while (enumerator.MoveNext())
{
Console.WriteLine(name + ": " + enumerator.Current);
}
}
@ -80,7 +81,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -80,7 +81,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public static IEnumerable<int> YieldReturnInLoop()
{
for (int i = 0; i < 100; i++) {
for (int i = 0; i < 100; i++)
{
yield return i;
}
}
@ -88,9 +90,12 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -88,9 +90,12 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public static IEnumerable<int> YieldReturnWithTryFinally()
{
yield return 0;
try {
try
{
yield return 1;
} finally {
}
finally
{
Console.WriteLine("Finally!");
}
yield return 2;
@ -120,28 +125,35 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -120,28 +125,35 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
Console.WriteLine("Start of method - 1");
yield return "Start of method";
Console.WriteLine("Start of method - 2");
try {
try
{
Console.WriteLine("Within outer try - 1");
yield return "Within outer try";
Console.WriteLine("Within outer try - 2");
try {
try
{
Console.WriteLine("Within inner try - 1");
yield return "Within inner try";
Console.WriteLine("Within inner try - 2");
if (breakInMiddle) {
if (breakInMiddle)
{
Console.WriteLine("Breaking...");
yield break;
}
Console.WriteLine("End of inner try - 1");
yield return "End of inner try";
Console.WriteLine("End of inner try - 2");
} finally {
}
finally
{
Console.WriteLine("Inner Finally");
}
Console.WriteLine("End of outer try - 1");
yield return "End of outer try";
Console.WriteLine("End of outer try - 2");
} finally {
}
finally
{
Console.WriteLine("Outer Finally");
}
Console.WriteLine("End of method - 1");
@ -152,11 +164,15 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -152,11 +164,15 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public static IEnumerable<string> YieldReturnWithTwoNonNestedFinallyBlocks(IEnumerable<string> input)
{
// outer try-finally block
foreach (string line in input) {
foreach (string line in input)
{
// nested try-finally block
try {
try
{
yield return line;
} finally {
}
finally
{
Console.WriteLine("Processed " + line);
}
}
@ -167,21 +183,24 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -167,21 +183,24 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
yield return "E";
yield return "F";
// outer try-finally block
foreach (string item in input) {
foreach (string item in input)
{
yield return item.ToUpper();
}
}
public static IEnumerable<Func<string>> YieldReturnWithAnonymousMethods1(IEnumerable<string> input)
{
foreach (string line in input) {
foreach (string line in input)
{
yield return () => line;
}
}
public static IEnumerable<Func<string>> YieldReturnWithAnonymousMethods2(IEnumerable<string> input)
{
foreach (string item in input) {
foreach (string item in input)
{
string copy = item;
yield return () => copy;
}
@ -189,8 +208,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -189,8 +208,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public static IEnumerable<int> GetEvenNumbers(int n)
{
for (int i = 0; i < n; i++) {
if (i % 2 == 0) {
for (int i = 0; i < n; i++)
{
if (i % 2 == 0)
{
yield return i;
}
}
@ -199,20 +220,29 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -199,20 +220,29 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public static IEnumerable<char> ExceptionHandling()
{
yield return 'a';
try {
try
{
Console.WriteLine("1 - try");
} catch (Exception) {
}
catch (Exception)
{
Console.WriteLine("1 - catch");
}
yield return 'b';
try {
try {
try
{
try
{
Console.WriteLine("2 - try");
} finally {
}
finally
{
Console.WriteLine("2 - finally");
}
yield return 'c';
} finally {
}
finally
{
Console.WriteLine("outer finally");
}
}
@ -220,9 +250,12 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -220,9 +250,12 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public static IEnumerable<int> YieldBreakInCatch()
{
yield return 0;
try {
try
{
Console.WriteLine("In Try");
} catch {
}
catch
{
// yield return is not allowed in catch, but yield break is
yield break;
}
@ -231,11 +264,15 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -231,11 +264,15 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public static IEnumerable<int> YieldBreakInCatchInTryFinally()
{
try {
try
{
yield return 0;
try {
try
{
Console.WriteLine("In Try");
} catch {
}
catch
{
// yield return is not allowed in catch, but yield break is
// Note that pre-roslyn, this code triggers a compiler bug:
// If the finally block throws an exception, it ends up getting
@ -243,43 +280,58 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -243,43 +280,58 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
yield break;
}
yield return 1;
} finally {
}
finally
{
Console.WriteLine("Finally");
}
}
public static IEnumerable<int> YieldBreakInTryCatchInTryFinally()
{
try {
try
{
yield return 0;
try {
try
{
Console.WriteLine("In Try");
// same compiler bug as in YieldBreakInCatchInTryFinally
yield break;
} catch {
}
catch
{
Console.WriteLine("Catch");
}
yield return 1;
} finally {
}
finally
{
Console.WriteLine("Finally");
}
}
public static IEnumerable<int> YieldBreakInTryFinallyInTryFinally(bool b)
{
try {
try
{
yield return 0;
try {
try
{
Console.WriteLine("In Try");
if (b) {
if (b)
{
// same compiler bug as in YieldBreakInCatchInTryFinally
yield break;
}
} finally {
}
finally
{
Console.WriteLine("Inner Finally");
}
yield return 1;
} finally {
}
finally
{
Console.WriteLine("Finally");
}
}
@ -293,10 +345,13 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -293,10 +345,13 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
{
// Here, MoveNext() doesn't call the finally methods at all
// (only indirectly via Dispose())
try {
try
{
yield return 0;
throw new NotImplementedException();
} finally {
}
finally
{
Console.WriteLine("Finally");
}
}
@ -304,13 +359,19 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -304,13 +359,19 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public static IEnumerable<int> NestedTryFinallyStartingOnSamePosition()
{
// The first user IL instruction is already in 2 nested try blocks.
try {
try {
try
{
try
{
yield return 0;
} finally {
}
finally
{
Console.WriteLine("Inner Finally");
}
} finally {
}
finally
{
Console.WriteLine("Outer Finally");
}
}
@ -318,9 +379,12 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -318,9 +379,12 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public static IEnumerable<int> LocalInFinally<T>(T a) where T : IDisposable
{
yield return 1;
try {
try
{
yield return 2;
} finally {
}
finally
{
T val = a;
val.Dispose();
val.Dispose();
@ -331,27 +395,34 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -331,27 +395,34 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public static IEnumerable<T> GenericYield<T>() where T : new()
{
T val = new T();
for (int i = 0; i < 3; i++) {
for (int i = 0; i < 3; i++)
{
yield return val;
}
}
public static IEnumerable<int> MultipleYieldBreakInTryFinally(int i)
{
try {
if (i == 2) {
try
{
if (i == 2)
{
yield break;
}
while (i < 40) {
if (i % 2 == 0) {
while (i < 40)
{
if (i % 2 == 0)
{
yield break;
}
i++;
yield return i;
}
} finally {
}
finally
{
Console.WriteLine("finally");
}
Console.WriteLine("normal exit");
@ -362,8 +433,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -362,8 +433,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
// This loop needs to pick the implicit "yield break;" as exit point
// in order to produce pretty code; not the "throw" which would
// be a less-pretty option.
for (int i = 0; i < end; i++) {
if (i == evil) {
for (int i = 0; i < end; i++)
{
if (i == evil)
{
throw new InvalidOperationException("Found evil number");
}
yield return i;

26
ICSharpCode.Decompiler.Tests/TestCases/Ugly/AggressiveScalarReplacementOfAggregates.Expected.cs

@ -58,9 +58,12 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Ugly @@ -58,9 +58,12 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Ugly
int field1 = 4711;
string field2 = "ILSpy";
DisplayClass field3;
if (displayClass.field1 > 100) {
if (displayClass.field1 > 100)
{
field3 = displayClass;
} else {
}
else
{
field3 = null;
}
Console.WriteLine("{0} {1}", displayClass, field3);
@ -76,9 +79,12 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Ugly @@ -76,9 +79,12 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Ugly
int field1 = 4711;
string field2 = "ILSpy";
DisplayClass field3;
if (displayClass.field1 > 100) {
if (displayClass.field1 > 100)
{
field3 = displayClass;
} else {
}
else
{
field3 = null;
}
Console.WriteLine("{0} {1}", field2 + field1, field3);
@ -93,8 +99,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Ugly @@ -93,8 +99,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Ugly
int field1 = default(int);
string field2 = default(string);
DisplayClass field3 = default(DisplayClass);
while (true) {
switch (Rand()) {
while (true)
{
switch (Rand())
{
case 1:
field1 = Rand();
continue;
@ -115,7 +123,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Ugly @@ -115,7 +123,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Ugly
{
int field1 = i;
string field2 = "Hello World!";
if (i < 0) {
if (i < 0)
{
i = -i;
}
Console.WriteLine("{0} {1}", field1, field2);
@ -126,7 +135,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Ugly @@ -126,7 +135,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Ugly
int num = i;
int field1 = num;
string field2 = "Hello World!";
if (num < 0) {
if (num < 0)
{
num = -num;
}
Console.WriteLine("{0} {1}", field1, field2);

46
ICSharpCode.Decompiler.Tests/TestCases/Ugly/AggressiveScalarReplacementOfAggregates.cs

@ -61,9 +61,12 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Ugly @@ -61,9 +61,12 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Ugly
field1 = 4711,
field2 = "ILSpy"
};
if (displayClass.field1 > 100) {
if (displayClass.field1 > 100)
{
nested.field3 = displayClass;
} else {
}
else
{
nested.field3 = null;
}
Console.WriteLine("{0} {1}", displayClass, nested.field3);
@ -80,9 +83,12 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Ugly @@ -80,9 +83,12 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Ugly
field1 = 4711,
field2 = "ILSpy"
};
if (displayClass.field1 > 100) {
if (displayClass.field1 > 100)
{
nested.field3 = displayClass;
} else {
}
else
{
nested.field3 = null;
}
Console.WriteLine("{0} {1}", nested.field2 + nested.field1, nested.field3);
@ -95,8 +101,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Ugly @@ -95,8 +101,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Ugly
field1 = i
};
NestedDisplayClass nested = new NestedDisplayClass();
while (true) {
switch (Rand()) {
while (true)
{
switch (Rand())
{
case 1:
nested.field1 = Rand();
break;
@ -121,7 +129,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Ugly @@ -121,7 +129,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Ugly
field1 = i,
field2 = "Hello World!"
};
if (i < 0) {
if (i < 0)
{
i = -i;
}
Console.WriteLine("{0} {1}", displayClass.field1, displayClass.field2);
@ -134,7 +143,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Ugly @@ -134,7 +143,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Ugly
field1 = num,
field2 = "Hello World!"
};
if (num < 0) {
if (num < 0)
{
num = -num;
}
Console.WriteLine("{0} {1}", displayClass.field1, displayClass.field2);
@ -170,15 +180,15 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Ugly @@ -170,15 +180,15 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Ugly
Console.WriteLine("{0} {1}", displayClass.field1, displayClass.field2);
}
// public void Test9()
// {
// DisplayClass displayClass = new DisplayClass {
// thisField = this,
// field1 = 1,
// field2 = "Hello World!"
// };
// displayClass.thisField = new Program();
// Console.WriteLine("{0} {1}", this, displayClass.thisField);
// }
// public void Test9()
// {
// DisplayClass displayClass = new DisplayClass {
// thisField = this,
// field1 = 1,
// field2 = "Hello World!"
// };
// displayClass.thisField = new Program();
// Console.WriteLine("{0} {1}", this, displayClass.thisField);
// }
}
}

2
ICSharpCode.Decompiler.Tests/TestCases/Ugly/NoDecimalConstants.Expected.cs

@ -7,7 +7,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Ugly @@ -7,7 +7,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Ugly
{
[DecimalConstant(1, 0, 0u, 0u, 10u)]
private static readonly decimal constant = 1.0m;
private void MethodWithOptionalParameter([Optional] [DecimalConstant(1, 0, 0u, 0u, 10u)] decimal parameter)
private void MethodWithOptionalParameter([Optional][DecimalConstant(1, 0, 0u, 0u, 10u)] decimal parameter)
{
}
}

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save