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
void Update() void Update()
{ {
if (options.TabsToSpaces) { if (options.TabsToSpaces) {
indentString = new string(' ', curIndent); indentString = new string(' ', curIndent + ExtraSpaces);
return; return;
} }
indentString = new string('\t', curIndent / options.TabSize) + new string(' ', curIndent % options.TabSize) + new string(' ', ExtraSpaces); 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
Foo (1, 2, 3); Foo (1, 2, 3);
} }
}", }",
@"class Test @"class Test
{ {
void TestMe () 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);
}
} }
} }

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

@ -28,13 +28,17 @@ namespace ICSharpCode.NRefactory.CSharp.FormattingTests
return b.ToString(); 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); if (options == null) {
var document = new StringBuilderDocument(input); options = new TextEditorOptions();
var options = new TextEditorOptions();
options.EolMarker = "\n"; options.EolMarker = "\n";
options.WrapLineLength = 80; options.WrapLineLength = 80;
}
input = NormalizeNewlines(input);
var document = new StringBuilderDocument(input);
var visitor = new CSharpFormatter (policy, options); var visitor = new CSharpFormatter (policy, options);
visitor.FormattingMode = mode; visitor.FormattingMode = mode;
var syntaxTree = new CSharpParser ().Parse (document, "test.cs"); var syntaxTree = new CSharpParser ().Parse (document, "test.cs");
@ -43,10 +47,11 @@ namespace ICSharpCode.NRefactory.CSharp.FormattingTests
return document; 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); expectedOutput = NormalizeNewlines(expectedOutput);
IDocument doc = GetResult(policy, input, mode);
IDocument doc = GetResult(policy, input, mode, options);
if (expectedOutput != doc.Text) { if (expectedOutput != doc.Text) {
Console.WriteLine ("expected:"); Console.WriteLine ("expected:");
Console.WriteLine (expectedOutput); Console.WriteLine (expectedOutput);

Loading…
Cancel
Save