Browse Source

Fixed some issues in the formatter.

newNRvisualizers
Mike Krüger 14 years ago
parent
commit
cd349d26ce
  1. 1482
      ICSharpCode.NRefactory.CSharp/Formatter/AstFormattingVisitor.cs
  2. 4
      ICSharpCode.NRefactory.CSharp/Parser/CSharpParser.cs
  3. 2
      ICSharpCode.NRefactory.Tests/CSharp/ContextAction/TestRefactoringContext.cs
  4. 2
      ICSharpCode.NRefactory.Tests/FormattingTests/TestBlankLineFormatting.cs
  5. 2
      ICSharpCode.NRefactory.Tests/FormattingTests/TestBraceStlye.cs
  6. 4
      ICSharpCode.NRefactory.Tests/FormattingTests/TestFormattingBugs.cs
  7. 2
      ICSharpCode.NRefactory.Tests/FormattingTests/TestSpacingVisitor.cs
  8. 229
      ICSharpCode.NRefactory.Tests/FormattingTests/TestStatementIndentation.cs
  9. 2
      ICSharpCode.NRefactory.Tests/FormattingTests/TestTypeLevelIndentation.cs
  10. 2
      ICSharpCode.NRefactory.Tests/FormattingTests/TextEditorTestAdapter.cs
  11. 1
      ICSharpCode.NRefactory.Tests/ICSharpCode.NRefactory.Tests.csproj

1482
ICSharpCode.NRefactory.CSharp/Formatter/AstFormattingVisitor.cs

File diff suppressed because it is too large Load Diff

4
ICSharpCode.NRefactory.CSharp/Parser/CSharpParser.cs

@ -775,9 +775,9 @@ namespace ICSharpCode.NRefactory.CSharp @@ -775,9 +775,9 @@ namespace ICSharpCode.NRefactory.CSharp
}
public override void Visit (Field f)
public override void Visit(Field f)
{
var location = LocationsBag.GetMemberLocation (f);
var location = LocationsBag.GetMemberLocation(f);
FieldDeclaration newField = new FieldDeclaration ();
AddAttributeSection (newField, f);

2
ICSharpCode.NRefactory.Tests/CSharp/ContextAction/TestRefactoringContext.cs

@ -31,7 +31,7 @@ using ICSharpCode.NRefactory.CSharp.Refactoring; @@ -31,7 +31,7 @@ using ICSharpCode.NRefactory.CSharp.Refactoring;
using ICSharpCode.NRefactory.CSharp.Resolver;
using ICSharpCode.NRefactory.CSharp.TypeSystem;
using ICSharpCode.NRefactory.Editor;
using ICSharpCode.NRefactory.FormattingTests;
using ICSharpCode.NRefactory.CSharp.FormattingTests;
using ICSharpCode.NRefactory.Semantics;
using ICSharpCode.NRefactory.TypeSystem;
using NUnit.Framework;

2
ICSharpCode.NRefactory.Tests/FormattingTests/TestBlankLineFormatting.cs

@ -29,7 +29,7 @@ using System.IO; @@ -29,7 +29,7 @@ using System.IO;
using NUnit.Framework;
using ICSharpCode.NRefactory.CSharp;
namespace ICSharpCode.NRefactory.FormattingTests
namespace ICSharpCode.NRefactory.CSharp.FormattingTests
{
[TestFixture()]
public class TestBlankLineFormatting : TestBase

2
ICSharpCode.NRefactory.Tests/FormattingTests/TestBraceStlye.cs

@ -29,7 +29,7 @@ using System.IO; @@ -29,7 +29,7 @@ using System.IO;
using NUnit.Framework;
using ICSharpCode.NRefactory.CSharp;
namespace ICSharpCode.NRefactory.FormattingTests
namespace ICSharpCode.NRefactory.CSharp.FormattingTests
{
[TestFixture()]
public class TestBraceStyle : TestBase

4
ICSharpCode.NRefactory.Tests/FormattingTests/TestFormattingBugs.cs

@ -29,7 +29,7 @@ using System.IO; @@ -29,7 +29,7 @@ using System.IO;
using NUnit.Framework;
using ICSharpCode.NRefactory.CSharp;
namespace ICSharpCode.NRefactory.FormattingTests
namespace ICSharpCode.NRefactory.CSharp.FormattingTests
{
[TestFixture()]
public class TestFormattingBugs : TestBase
@ -134,6 +134,8 @@ using (IDisposable b = null) { @@ -134,6 +134,8 @@ using (IDisposable b = null) {
int end = result.GetOffset (result.LineCount - 1, 1);
string text = result.GetText (start, end - start).Trim ();
expectedOutput = NormalizeNewlines(expectedOutput).Replace ("\n", "\n\t\t");
if (expectedOutput != text)
Console.WriteLine (text);
Assert.AreEqual (expectedOutput, text);
}

2
ICSharpCode.NRefactory.Tests/FormattingTests/TestSpacingVisitor.cs

@ -29,7 +29,7 @@ using System.IO; @@ -29,7 +29,7 @@ using System.IO;
using NUnit.Framework;
using ICSharpCode.NRefactory.CSharp;
namespace ICSharpCode.NRefactory.FormattingTests
namespace ICSharpCode.NRefactory.CSharp.FormattingTests
{
[TestFixture()]
public class TestSpacingVisitor : TestBase

229
ICSharpCode.NRefactory.Tests/FormattingTests/TestStatementIndentation.cs

@ -29,10 +29,10 @@ using System.IO; @@ -29,10 +29,10 @@ using System.IO;
using NUnit.Framework;
using ICSharpCode.NRefactory.CSharp;
namespace ICSharpCode.NRefactory.FormattingTests
namespace ICSharpCode.NRefactory.CSharp.FormattingTests
{
[TestFixture()]
public class TestStatementIndentation : TestBase
public class TestStatements : TestBase
{
[Test()]
public void TestInvocationIndentation ()
@ -148,6 +148,28 @@ this.TestMethod (); @@ -148,6 +148,28 @@ this.TestMethod ();
}");
}
[Test()]
public void TestBreakSemicolon ()
{
CSharpFormattingOptions policy = new CSharpFormattingOptions ();
Test (policy,
@"class Test
{
Test TestMethod ()
{
break ;
}
}",
@"class Test
{
Test TestMethod ()
{
break;
}
}");
}
[Test()]
public void TestCheckedIndentation ()
{
@ -231,6 +253,26 @@ continue; @@ -231,6 +253,26 @@ continue;
}");
}
[Test()]
public void TestContinueSemicolon ()
{
CSharpFormattingOptions policy = new CSharpFormattingOptions ();
Test (policy, @"class Test
{
Test TestMethod ()
{
continue ;
}
}",
@"class Test
{
Test TestMethod ()
{
continue;
}
}");
}
[Test()]
public void TestEmptyStatementIndentation ()
{
@ -367,6 +409,27 @@ goto label; @@ -367,6 +409,27 @@ goto label;
}");
}
[Test()]
public void TestGotoSemicolon ()
{
CSharpFormattingOptions policy = new CSharpFormattingOptions ();
Test (policy, @"class Test
{
Test TestMethod ()
{
goto label
;
}
}",
@"class Test
{
Test TestMethod ()
{
goto label;
}
}");
}
[Test()]
public void TestReturnIndentation ()
{
@ -376,7 +439,7 @@ goto label; @@ -376,7 +439,7 @@ goto label;
Test (policy, @"class Test {
Test TestMethod ()
{
return;
return;
}
}",
@"class Test {
@ -387,6 +450,25 @@ return; @@ -387,6 +450,25 @@ return;
}");
}
[Test()]
public void TestReturnSemicolon ()
{
CSharpFormattingOptions policy = new CSharpFormattingOptions ();
Test (policy, @"class Test
{
Test TestMethod ()
{
return ;
}
}",
@"class Test
{
Test TestMethod ()
{
return;
}
}");
}
[Test()]
public void TestLockIndentation ()
{
@ -430,6 +512,26 @@ throw new NotSupportedException (); @@ -430,6 +512,26 @@ throw new NotSupportedException ();
}");
}
[Test()]
public void TestThrowSemicolon ()
{
CSharpFormattingOptions policy = new CSharpFormattingOptions ();
Test (policy, @"class Test
{
Test TestMethod ()
{
throw new NotSupportedException () ;
}
}",
@"class Test
{
Test TestMethod ()
{
throw new NotSupportedException ();
}
}");
}
[Test()]
public void TestUnsafeIndentation ()
{
@ -609,7 +711,7 @@ const int a = 5; @@ -609,7 +711,7 @@ const int a = 5;
}
[Test()]
public void TestYieldIndentation ()
public void TestYieldReturnIndentation ()
{
CSharpFormattingOptions policy = new CSharpFormattingOptions ();
@ -628,6 +730,65 @@ yield return null; @@ -628,6 +730,65 @@ yield return null;
}");
}
[Test()]
public void TestYieldReturnSemicolon ()
{
CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.ClassBraceStyle = BraceStyle.EndOfLine;
Test (policy, @"class Test {
Test TestMethod ()
{
yield return null ;
}
}",
@"class Test {
Test TestMethod ()
{
yield return null;
}
}");
}
[Test()]
public void TestYieldBreakIndentation ()
{
CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.ClassBraceStyle = BraceStyle.EndOfLine;
Test (policy, @"class Test {
Test TestMethod ()
{
yield break;
}
}",
@"class Test {
Test TestMethod ()
{
yield break;
}
}");
}
[Test()]
public void TestYieldBreakSemicolon ()
{
CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.ClassBraceStyle = BraceStyle.EndOfLine;
Test (policy, @"class Test {
Test TestMethod ()
{
yield break ;
}
}",
@"class Test {
Test TestMethod ()
{
yield break;
}
}");
}
[Test()]
public void TestWhileIndentation ()
{
@ -1061,8 +1222,7 @@ if (b) { @@ -1061,8 +1222,7 @@ if (b) {
{
void TestMethod ()
{
if (true) {
// TestComment
if (true) { // TestComment
Call ();
}
}
@ -1312,6 +1472,7 @@ if (b) { @@ -1312,6 +1472,7 @@ if (b) {
{
fixed (object* obj = &obj)
{
;
}
}
@ -1790,6 +1951,62 @@ if (b) { @@ -1790,6 +1951,62 @@ if (b) {
}
}");
}
[Test()]
public void TestBlockStatementWithComments ()
{
CSharpFormattingOptions policy = new CSharpFormattingOptions ();
Test (policy, @"class Test
{
Test TestMethod ()
{
{
//CMT1
;
/* cmt 2 */
}
}
}", @"class Test
{
Test TestMethod ()
{
{
//CMT1
;
/* cmt 2 */
}
}
}");
}
[Test()]
public void TestBlockStatementWithPreProcessorDirective ()
{
CSharpFormattingOptions policy = new CSharpFormattingOptions ();
Test (policy, @"class Test
{
Test TestMethod ()
{
{
" + @"#if true
;
" + @"#endif
}
}
}", @"class Test
{
Test TestMethod ()
{
{
" + @" #if true
;
" + @" #endif
}
}
}");
}
}
}

2
ICSharpCode.NRefactory.Tests/FormattingTests/TestTypeLevelIndentation.cs

@ -29,7 +29,7 @@ using System.IO; @@ -29,7 +29,7 @@ using System.IO;
using NUnit.Framework;
using ICSharpCode.NRefactory.CSharp;
namespace ICSharpCode.NRefactory.FormattingTests
namespace ICSharpCode.NRefactory.CSharp.FormattingTests
{
[TestFixture()]
public class TestTypeLevelIndentation : TestBase

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

@ -7,7 +7,7 @@ using ICSharpCode.NRefactory.Editor; @@ -7,7 +7,7 @@ using ICSharpCode.NRefactory.Editor;
using NUnit.Framework;
using ICSharpCode.NRefactory.CSharp.Refactoring;
namespace ICSharpCode.NRefactory.FormattingTests
namespace ICSharpCode.NRefactory.CSharp.FormattingTests
{
public abstract class TestBase
{

1
ICSharpCode.NRefactory.Tests/ICSharpCode.NRefactory.Tests.csproj

@ -73,7 +73,6 @@ @@ -73,7 +73,6 @@
<Reference Include="System.Xml.Linq" />
<Reference Include="nunit.framework, Version=2.6.0.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77">
<HintPath>..\..\Mono.Cecil\Test\libs\nunit-2.5.10\nunit.framework.dll</HintPath>
<Private>True</Private>
<SpecificVersion>False</SpecificVersion>
</Reference>
</ItemGroup>

Loading…
Cancel
Save