From 774e949bdbf9ffae804026f310fe393871c39ae0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20Kr=C3=BCger?= Date: Fri, 24 May 2013 07:39:58 +0200 Subject: [PATCH] Fixed formatting bug. --- .../Formatter/Indent.cs | 2 +- .../FormattingTests/TestWrapping.cs | 33 ++++++++++++++++++- .../FormattingTests/TextEditorTestAdapter.cs | 17 ++++++---- 3 files changed, 44 insertions(+), 8 deletions(-) diff --git a/ICSharpCode.NRefactory.CSharp/Formatter/Indent.cs b/ICSharpCode.NRefactory.CSharp/Formatter/Indent.cs index 52bdf3f792..4b9bfa9f2b 100644 --- a/ICSharpCode.NRefactory.CSharp/Formatter/Indent.cs +++ b/ICSharpCode.NRefactory.CSharp/Formatter/Indent.cs @@ -126,7 +126,7 @@ namespace ICSharpCode.NRefactory.CSharp void Update() { if (options.TabsToSpaces) { - indentString = new string(' ', curIndent); + indentString = new string(' ', curIndent + ExtraSpaces); return; } indentString = new string('\t', curIndent / options.TabSize) + new string(' ', curIndent % options.TabSize) + new string(' ', ExtraSpaces); diff --git a/ICSharpCode.NRefactory.Tests/FormattingTests/TestWrapping.cs b/ICSharpCode.NRefactory.Tests/FormattingTests/TestWrapping.cs index 1a348ece85..4d1d387f35 100644 --- a/ICSharpCode.NRefactory.Tests/FormattingTests/TestWrapping.cs +++ b/ICSharpCode.NRefactory.Tests/FormattingTests/TestWrapping.cs @@ -181,7 +181,7 @@ namespace ICSharpCode.NRefactory.CSharp.FormattingTests Foo (1, 2, 3); } }", -@"class Test + @"class Test { void TestMe () { @@ -864,5 +864,36 @@ int foo) } }"); } + + + [Test] + public void TestWrappingWithSpaceIndent() + { + var policy = FormattingOptionsFactory.CreateMono(); + + TextEditorOptions options = new TextEditorOptions(); + options.IndentSize = options.TabSize = 2; + options.TabsToSpaces = true; + options.EolMarker = "\n"; + + Test(policy, @"class Test +{ + void TestMe () + { + Foo (1, + 2, + 3); + } +}", + @"class Test +{ + void TestMe () + { + Foo (1, + 2, + 3); + } +}", FormattingMode.Intrusive, options); + } } } diff --git a/ICSharpCode.NRefactory.Tests/FormattingTests/TextEditorTestAdapter.cs b/ICSharpCode.NRefactory.Tests/FormattingTests/TextEditorTestAdapter.cs index ca8b95386a..577ff7d8e3 100644 --- a/ICSharpCode.NRefactory.Tests/FormattingTests/TextEditorTestAdapter.cs +++ b/ICSharpCode.NRefactory.Tests/FormattingTests/TextEditorTestAdapter.cs @@ -28,13 +28,17 @@ namespace ICSharpCode.NRefactory.CSharp.FormattingTests return b.ToString(); }*/ - protected static IDocument GetResult(CSharpFormattingOptions policy, string input, FormattingMode mode = FormattingMode.Intrusive) + protected static IDocument GetResult(CSharpFormattingOptions policy, string input, FormattingMode mode = FormattingMode.Intrusive, TextEditorOptions options = null) { + if (options == null) { + options = new TextEditorOptions(); + options.EolMarker = "\n"; + options.WrapLineLength = 80; + } + + input = NormalizeNewlines(input); var document = new StringBuilderDocument(input); - var options = new TextEditorOptions(); - options.EolMarker = "\n"; - options.WrapLineLength = 80; var visitor = new CSharpFormatter (policy, options); visitor.FormattingMode = mode; var syntaxTree = new CSharpParser ().Parse (document, "test.cs"); @@ -43,10 +47,11 @@ namespace ICSharpCode.NRefactory.CSharp.FormattingTests return document; } - protected static IDocument Test (CSharpFormattingOptions policy, string input, string expectedOutput, FormattingMode mode = FormattingMode.Intrusive) + protected static IDocument Test (CSharpFormattingOptions policy, string input, string expectedOutput, FormattingMode mode = FormattingMode.Intrusive, TextEditorOptions options = null) { expectedOutput = NormalizeNewlines(expectedOutput); - IDocument doc = GetResult(policy, input, mode); + + IDocument doc = GetResult(policy, input, mode, options); if (expectedOutput != doc.Text) { Console.WriteLine ("expected:"); Console.WriteLine (expectedOutput);