Browse Source

#2128: Adjust formatting settings used in tests to match our new style.

pull/2134/head
Siegfried Pammer 5 years ago
parent
commit
f245d93fef
  1. 14
      ICSharpCode.Decompiler.Tests/Helpers/Tester.cs
  2. 7
      ICSharpCode.Decompiler.Tests/TestCases/ILPretty/FSharpLoops_Debug.cs
  3. 7
      ICSharpCode.Decompiler.Tests/TestCases/ILPretty/FSharpLoops_Release.cs
  4. 8
      ICSharpCode.Decompiler.Tests/TestCases/ILPretty/Issue1325.cs
  5. 5
      ICSharpCode.Decompiler.Tests/TestCases/ILPretty/Issue646.cs
  6. 15
      ICSharpCode.Decompiler/CSharp/OutputVisitor/CSharpFormattingOptions.cs
  7. 13
      ICSharpCode.Decompiler/CSharp/OutputVisitor/CSharpOutputVisitor.cs
  8. 5
      ICSharpCode.Decompiler/CSharp/Transforms/IntroduceUsingDeclarations.cs

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

@ -566,7 +566,8 @@ namespace ICSharpCode.Decompiler.Tests.Helpers @@ -566,7 +566,8 @@ namespace ICSharpCode.Decompiler.Tests.Helpers
var syntaxTree = decompiler.DecompileWholeModuleAsSingleFile(sortTypes: true);
StringWriter output = new StringWriter();
var visitor = new CSharpOutputVisitor(output, FormattingOptionsFactory.CreateSharpDevelop());
CSharpFormattingOptions formattingPolicy = CreateFormattingPolicyForTests();
var visitor = new CSharpOutputVisitor(output, formattingPolicy);
syntaxTree.AcceptVisitor(visitor);
string fileName = Path.GetTempFileName();
@ -576,6 +577,17 @@ namespace ICSharpCode.Decompiler.Tests.Helpers @@ -576,6 +577,17 @@ namespace ICSharpCode.Decompiler.Tests.Helpers
}
}
private static CSharpFormattingOptions CreateFormattingPolicyForTests()
{
var formattingPolicy = FormattingOptionsFactory.CreateSharpDevelop();
formattingPolicy.StatementBraceStyle = BraceStyle.NextLine;
formattingPolicy.CatchNewLinePlacement = NewLinePlacement.NewLine;
formattingPolicy.ElseNewLinePlacement = NewLinePlacement.NewLine;
formattingPolicy.FinallyNewLinePlacement = NewLinePlacement.NewLine;
formattingPolicy.SpaceBeforeAnonymousMethodParentheses = true;
return formattingPolicy;
}
public static void RunAndCompareOutput(string testFileName, string outputFile, string decompiledOutputFile, string decompiledCodeFile = null)
{
string output1, output2, error1, error2;

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

@ -5,9 +5,6 @@ @@ -5,9 +5,6 @@
// Architecture: AnyCPU (32-bit preferred)
// Runtime: .NET 4.0
using Microsoft.FSharp.Collections;
using Microsoft.FSharp.Core;
using Microsoft.FSharp.Core.CompilerServices;
using System;
using System.Collections.Generic;
using System.Diagnostics;
@ -15,6 +12,10 @@ using System.Reflection; @@ -15,6 +12,10 @@ using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using Microsoft.FSharp.Collections;
using Microsoft.FSharp.Core;
using Microsoft.FSharp.Core.CompilerServices;
[assembly: FSharpInterfaceDataVersion(2, 0, 0)]
[assembly: AssemblyTitle("ConsoleApplication1")]
[assembly: AssemblyCompany("")]

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

@ -6,9 +6,6 @@ @@ -6,9 +6,6 @@
// Architecture: AnyCPU (32-bit preferred)
// Runtime: .NET 4.0
using Microsoft.FSharp.Collections;
using Microsoft.FSharp.Core;
using Microsoft.FSharp.Core.CompilerServices;
using System;
using System.Collections.Generic;
using System.Diagnostics;
@ -16,6 +13,10 @@ using System.Reflection; @@ -16,6 +13,10 @@ using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using Microsoft.FSharp.Collections;
using Microsoft.FSharp.Core;
using Microsoft.FSharp.Core.CompilerServices;
[assembly: FSharpInterfaceDataVersion(2, 0, 0)]
[assembly: AssemblyTitle("ConsoleApplication1")]
[assembly: AssemblyCompany("")]

8
ICSharpCode.Decompiler.Tests/TestCases/ILPretty/Issue1325.cs

@ -1,11 +1,13 @@ @@ -1,11 +1,13 @@
using Microsoft.VisualBasic;
using Microsoft.VisualBasic.CompilerServices;
using System;
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using Microsoft.VisualBasic;
using Microsoft.VisualBasic.CompilerServices;
[assembly: Embedded]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyConfiguration("Debug")]

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

@ -1,8 +1,9 @@ @@ -1,8 +1,9 @@
using Microsoft.VisualBasic.CompilerServices;
using System;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using Microsoft.VisualBasic.CompilerServices;
namespace ICSharpCode.Decompiler.Tests.TestCases.ILPretty
{
[StandardModule]

15
ICSharpCode.Decompiler/CSharp/OutputVisitor/CSharpFormattingOptions.cs

@ -353,6 +353,11 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor @@ -353,6 +353,11 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor
#endregion
#region Spaces
public bool SpaceBetweenParameterAttributeSections {
get;
set;
}
// Methods
public bool SpaceBeforeMethodDeclarationParentheses { // tested
get;
@ -734,6 +739,16 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor @@ -734,6 +739,16 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor
set;
}
public bool SpaceBeforeAnonymousMethodParentheses {
get;
set;
}
public bool SpaceWithinAnonymousMethodParentheses {
get;
set;
}
// brackets
public bool SpacesWithinBrackets { // tested
get;

13
ICSharpCode.Decompiler/CSharp/OutputVisitor/CSharpOutputVisitor.cs

@ -563,8 +563,8 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor @@ -563,8 +563,8 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor
WriteKeyword(AnonymousMethodExpression.DelegateKeywordRole);
if (anonymousMethodExpression.HasParameterList)
{
Space(policy.SpaceBeforeMethodDeclarationParentheses);
WriteCommaSeparatedListInParenthesis(anonymousMethodExpression.Parameters, policy.SpaceWithinMethodDeclarationParentheses);
Space(policy.SpaceBeforeAnonymousMethodParentheses);
WriteCommaSeparatedListInParenthesis(anonymousMethodExpression.Parameters, policy.SpaceWithinAnonymousMethodParentheses);
}
WriteBlock(anonymousMethodExpression.Body, policy.AnonymousMethodBraceStyle);
EndNode(anonymousMethodExpression);
@ -1407,6 +1407,11 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor @@ -1407,6 +1407,11 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor
switch (attributeSection.Parent)
{
case ParameterDeclaration _:
if (attributeSection.NextSibling is AttributeSection)
Space(policy.SpaceBetweenParameterAttributeSections);
else
Space();
break;
case TypeParameterDeclaration _:
case ComposedType _:
Space();
@ -1916,14 +1921,14 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor @@ -1916,14 +1921,14 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor
switchExpression.Expression.AcceptVisitor(this);
Space();
WriteKeyword(SwitchExpression.SwitchKeywordRole);
OpenBrace(BraceStyle.EndOfLine);
OpenBrace(policy.StatementBraceStyle);
foreach (AstNode node in switchExpression.SwitchSections)
{
node.AcceptVisitor(this);
Comma(node);
NewLine();
}
CloseBrace(BraceStyle.EndOfLine);
CloseBrace(policy.StatementBraceStyle);
EndNode(switchExpression);
}

5
ICSharpCode.Decompiler/CSharp/Transforms/IntroduceUsingDeclarations.cs

@ -49,7 +49,10 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms @@ -49,7 +49,10 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms
var insertionPoint = rootNode.Children.LastOrDefault(n => n is PreProcessorDirective p && p.Type == PreProcessorDirectiveType.Define);
// Now add using declarations for those namespaces:
foreach (string ns in requiredImports.ImportedNamespaces.OrderByDescending(n => n))
IOrderedEnumerable<string> sortedImports = requiredImports.ImportedNamespaces
.OrderBy(n => n.StartsWith("System", StringComparison.Ordinal))
.ThenByDescending(n => n);
foreach (string ns in sortedImports)
{
Debug.Assert(context.RequiredNamespacesSuperset.Contains(ns), $"Should not insert using declaration for namespace that is missing from the superset: {ns}");
// we go backwards (OrderByDescending) through the list of namespaces because we insert them backwards

Loading…
Cancel
Save