Browse Source

Fixed formatting bug.

pull/45/merge
Mike Krüger 12 years ago
parent
commit
774e949bdb
  1. 2
      ICSharpCode.NRefactory.CSharp/Formatter/Indent.cs
  2. 33
      ICSharpCode.NRefactory.Tests/FormattingTests/TestWrapping.cs
  3. 17
      ICSharpCode.NRefactory.Tests/FormattingTests/TextEditorTestAdapter.cs

2
ICSharpCode.NRefactory.CSharp/Formatter/Indent.cs

@ -126,7 +126,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -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);

33
ICSharpCode.NRefactory.Tests/FormattingTests/TestWrapping.cs

@ -181,7 +181,7 @@ namespace ICSharpCode.NRefactory.CSharp.FormattingTests @@ -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) @@ -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);
}
}
}

17
ICSharpCode.NRefactory.Tests/FormattingTests/TextEditorTestAdapter.cs

@ -28,13 +28,17 @@ namespace ICSharpCode.NRefactory.CSharp.FormattingTests @@ -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)
{
input = NormalizeNewlines(input);
var document = new StringBuilderDocument(input);
var options = new TextEditorOptions();
if (options == null) {
options = new TextEditorOptions();
options.EolMarker = "\n";
options.WrapLineLength = 80;
}
input = NormalizeNewlines(input);
var document = new StringBuilderDocument(input);
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 @@ -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);

Loading…
Cancel
Save