5 changed files with 4108 additions and 0 deletions
@ -0,0 +1,530 @@
@@ -0,0 +1,530 @@
|
||||
//
|
||||
// TestBraceStyle.cs
|
||||
//
|
||||
// Author:
|
||||
// Mike Krüger <mkrueger@novell.com>
|
||||
//
|
||||
// Copyright (c) 2010 Novell, Inc (http://www.novell.com)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
/* |
||||
using System; |
||||
using NUnit.Framework; |
||||
using MonoDevelop.Ide.Gui; |
||||
using MonoDevelop.Projects; |
||||
using MonoDevelop.Core; |
||||
using MonoDevelop.Ide.CodeCompletion; |
||||
using MonoDevelop.Ide.Gui.Content; |
||||
using MonoDevelop.Projects.Dom.Parser; |
||||
using MonoDevelop.CSharp.Parser; |
||||
using MonoDevelop.CSharp.Resolver; |
||||
using MonoDevelop.CSharp.Completion; |
||||
using Mono.TextEditor; |
||||
using MonoDevelop.CSharp.Formatting; |
||||
|
||||
namespace MonoDevelop.CSharpBinding.FormattingTests |
||||
{ |
||||
[TestFixture()] |
||||
public class TestBraceStyle : UnitTests.TestBase |
||||
{ |
||||
[Test()] |
||||
[Ignore("currently failing because namespaces are not inserted")] |
||||
public void TestNamespaceBraceStyle () |
||||
{ |
||||
TextEditorData data = new TextEditorData (); |
||||
data.Document.FileName = "a.cs"; |
||||
data.Document.Text = @"namespace A
|
||||
{ |
||||
namespace B { |
||||
class Test {} |
||||
} |
||||
}";
|
||||
|
||||
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); |
||||
policy.NamespaceBraceStyle = BraceStyle.EndOfLine; |
||||
policy.ClassBraceStyle = BraceStyle.DoNotChange; |
||||
|
||||
CSharp.Dom.CompilationUnit compilationUnit = new CSharpParser ().Parse (data); |
||||
compilationUnit.AcceptVisitor (new DomIndentationVisitor (policy, data), null); |
||||
Assert.AreEqual (@"namespace A {
|
||||
namespace B { |
||||
class Test {} |
||||
} |
||||
}", data.Document.Text);
|
||||
|
||||
policy.NamespaceBraceStyle = BraceStyle.NextLineShifted; |
||||
compilationUnit = new CSharpParser ().Parse (data); |
||||
compilationUnit.AcceptVisitor (new DomIndentationVisitor (policy, data), null); |
||||
Assert.AreEqual (@"namespace A
|
||||
{ |
||||
namespace B |
||||
{ |
||||
class Test {} |
||||
} |
||||
}", data.Document.Text);
|
||||
} |
||||
|
||||
|
||||
[Test()] |
||||
public void TestClassBraceStlye () |
||||
{ |
||||
TextEditorData data = new TextEditorData (); |
||||
data.Document.FileName = "a.cs"; |
||||
data.Document.Text = @"class Test {}"; |
||||
|
||||
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); |
||||
policy.ClassBraceStyle = BraceStyle.EndOfLine; |
||||
|
||||
CSharp.Dom.CompilationUnit compilationUnit = new CSharpParser ().Parse (data); |
||||
compilationUnit.AcceptVisitor (new DomIndentationVisitor (policy, data), null); |
||||
Assert.AreEqual (@"class Test {
|
||||
}", data.Document.Text);
|
||||
} |
||||
|
||||
[Test()] |
||||
public void TestStructBraceStyle () |
||||
{ |
||||
TextEditorData data = new TextEditorData (); |
||||
data.Document.FileName = "a.cs"; |
||||
data.Document.Text = @"struct Test {}"; |
||||
|
||||
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); |
||||
policy.StructBraceStyle = BraceStyle.NextLine; |
||||
|
||||
CSharp.Dom.CompilationUnit compilationUnit = new CSharpParser ().Parse (data); |
||||
compilationUnit.AcceptVisitor (new DomIndentationVisitor (policy, data), null); |
||||
Assert.AreEqual (@"struct Test
|
||||
{ |
||||
}", data.Document.Text);
|
||||
} |
||||
|
||||
[Test()] |
||||
public void TestInterfaceBraceStyle () |
||||
{ |
||||
TextEditorData data = new TextEditorData (); |
||||
data.Document.FileName = "a.cs"; |
||||
data.Document.Text = @"interface Test {}"; |
||||
|
||||
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); |
||||
policy.InterfaceBraceStyle = BraceStyle.NextLine; |
||||
|
||||
CSharp.Dom.CompilationUnit compilationUnit = new CSharpParser ().Parse (data); |
||||
compilationUnit.AcceptVisitor (new DomIndentationVisitor (policy, data), null); |
||||
Assert.AreEqual (@"interface Test
|
||||
{ |
||||
}", data.Document.Text);
|
||||
} |
||||
|
||||
[Test()] |
||||
public void TestEnumBraceStyle () |
||||
{ |
||||
TextEditorData data = new TextEditorData (); |
||||
data.Document.FileName = "a.cs"; |
||||
data.Document.Text = @"enum Test {
|
||||
A |
||||
}";
|
||||
|
||||
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); |
||||
policy.EnumBraceStyle = BraceStyle.NextLineShifted; |
||||
|
||||
CSharp.Dom.CompilationUnit compilationUnit = new CSharpParser ().Parse (data); |
||||
compilationUnit.AcceptVisitor (new DomIndentationVisitor (policy, data), null); |
||||
Assert.AreEqual (@"enum Test
|
||||
{ |
||||
A |
||||
}", data.Document.Text);
|
||||
} |
||||
|
||||
[Test()] |
||||
public void TestMethodBraceStlye () |
||||
{ |
||||
TextEditorData data = new TextEditorData (); |
||||
data.Document.FileName = "a.cs"; |
||||
data.Document.Text = @"class Test
|
||||
{ |
||||
Test MyMethod() {} |
||||
}";
|
||||
|
||||
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); |
||||
policy.MethodBraceStyle = BraceStyle.NextLine; |
||||
|
||||
CSharp.Dom.CompilationUnit compilationUnit = new CSharpParser ().Parse (data); |
||||
compilationUnit.AcceptVisitor (new DomIndentationVisitor (policy, data), null); |
||||
|
||||
Console.WriteLine (data.Document.Text); |
||||
Assert.AreEqual (@"class Test
|
||||
{ |
||||
Test MyMethod() |
||||
{ |
||||
} |
||||
}", data.Document.Text);
|
||||
} |
||||
|
||||
[Test()] |
||||
public void TestConstructorBraceStyle () |
||||
{ |
||||
TextEditorData data = new TextEditorData (); |
||||
data.Document.FileName = "a.cs"; |
||||
data.Document.Text = @"class Test
|
||||
{ |
||||
Test() {} |
||||
}";
|
||||
|
||||
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); |
||||
policy.ConstructorBraceStyle = BraceStyle.NextLine; |
||||
|
||||
CSharp.Dom.CompilationUnit compilationUnit = new CSharpParser ().Parse (data); |
||||
compilationUnit.AcceptVisitor (new DomIndentationVisitor (policy, data), null); |
||||
|
||||
Console.WriteLine (data.Document.Text); |
||||
Assert.AreEqual (@"class Test
|
||||
{ |
||||
Test() |
||||
{ |
||||
} |
||||
}", data.Document.Text);
|
||||
} |
||||
|
||||
[Test()] |
||||
public void TestDestructorBraceStyle () |
||||
{ |
||||
TextEditorData data = new TextEditorData (); |
||||
data.Document.FileName = "a.cs"; |
||||
data.Document.Text = @"class Test
|
||||
{ |
||||
~Test() {} |
||||
}";
|
||||
|
||||
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); |
||||
policy.DestructorBraceStyle = BraceStyle.NextLine; |
||||
|
||||
CSharp.Dom.CompilationUnit compilationUnit = new CSharpParser ().Parse (data); |
||||
compilationUnit.AcceptVisitor (new DomIndentationVisitor (policy, data), null); |
||||
|
||||
Console.WriteLine (data.Document.Text); |
||||
Assert.AreEqual (@"class Test
|
||||
{ |
||||
~Test() |
||||
{ |
||||
} |
||||
}", data.Document.Text);
|
||||
} |
||||
|
||||
[Test()] |
||||
public void TestPropertyBraceStyle () |
||||
{ |
||||
TextEditorData data = new TextEditorData (); |
||||
data.Document.FileName = "a.cs"; |
||||
data.Document.Text = @"class Test
|
||||
{ |
||||
Test A { |
||||
get; |
||||
set; |
||||
} |
||||
}";
|
||||
|
||||
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); |
||||
policy.PropertyBraceStyle = BraceStyle.NextLine; |
||||
|
||||
CSharp.Dom.CompilationUnit compilationUnit = new CSharpParser ().Parse (data); |
||||
compilationUnit.AcceptVisitor (new DomIndentationVisitor (policy, data), null); |
||||
|
||||
Console.WriteLine (data.Document.Text); |
||||
Assert.AreEqual (@"class Test
|
||||
{ |
||||
Test A |
||||
{ |
||||
get; |
||||
set; |
||||
} |
||||
}", data.Document.Text);
|
||||
} |
||||
|
||||
[Test()] |
||||
public void TestPropertyGetBraceStyle () |
||||
{ |
||||
TextEditorData data = new TextEditorData (); |
||||
data.Document.FileName = "a.cs"; |
||||
data.Document.Text = @"class Test
|
||||
{ |
||||
Test A { |
||||
get { |
||||
return null; |
||||
} |
||||
set; |
||||
} |
||||
}";
|
||||
|
||||
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); |
||||
policy.PropertyGetBraceStyle = BraceStyle.NextLine; |
||||
|
||||
CSharp.Dom.CompilationUnit compilationUnit = new CSharpParser ().Parse (data); |
||||
compilationUnit.AcceptVisitor (new DomIndentationVisitor (policy, data), null); |
||||
|
||||
Console.WriteLine (data.Document.Text); |
||||
Assert.AreEqual (@"class Test
|
||||
{ |
||||
Test A { |
||||
get |
||||
{ |
||||
return null; |
||||
} |
||||
set; |
||||
} |
||||
}", data.Document.Text);
|
||||
} |
||||
|
||||
[Test()] |
||||
public void TestAllowPropertyGetBlockInline () |
||||
{ |
||||
TextEditorData data = new TextEditorData (); |
||||
data.Document.FileName = "a.cs"; |
||||
data.Document.Text = @"class Test
|
||||
{ |
||||
Test A { |
||||
get { return null; } |
||||
set { ; } |
||||
} |
||||
}";
|
||||
|
||||
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); |
||||
policy.PropertyBraceStyle = BraceStyle.DoNotChange; |
||||
policy.AllowPropertyGetBlockInline = true; |
||||
policy.AllowPropertySetBlockInline = false; |
||||
|
||||
CSharp.Dom.CompilationUnit compilationUnit = new CSharpParser ().Parse (data); |
||||
compilationUnit.AcceptVisitor (new DomIndentationVisitor (policy, data), null); |
||||
|
||||
Console.WriteLine (data.Document.Text); |
||||
Assert.AreEqual (@"class Test
|
||||
{ |
||||
Test A { |
||||
get { return null; } |
||||
set { |
||||
; |
||||
} |
||||
} |
||||
}", data.Document.Text);
|
||||
|
||||
policy.AllowPropertyGetBlockInline = false; |
||||
compilationUnit = new CSharpParser ().Parse (data); |
||||
compilationUnit.AcceptVisitor (new DomIndentationVisitor (policy, data), null); |
||||
|
||||
Assert.AreEqual (@"class Test
|
||||
{ |
||||
Test A { |
||||
get { |
||||
return null; |
||||
} |
||||
set { |
||||
; |
||||
} |
||||
} |
||||
}", data.Document.Text);
|
||||
} |
||||
|
||||
[Test()] |
||||
public void TestAllowPropertySetBlockInline () |
||||
{ |
||||
TextEditorData data = new TextEditorData (); |
||||
data.Document.FileName = "a.cs"; |
||||
data.Document.Text = @"class Test
|
||||
{ |
||||
Test A { |
||||
get { return null; } |
||||
set { ; } |
||||
} |
||||
}";
|
||||
|
||||
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); |
||||
policy.PropertyBraceStyle = BraceStyle.DoNotChange; |
||||
policy.AllowPropertyGetBlockInline = false; |
||||
policy.AllowPropertySetBlockInline = true; |
||||
|
||||
CSharp.Dom.CompilationUnit compilationUnit = new CSharpParser ().Parse (data); |
||||
compilationUnit.AcceptVisitor (new DomIndentationVisitor (policy, data), null); |
||||
|
||||
Console.WriteLine (data.Document.Text); |
||||
Assert.AreEqual (@"class Test
|
||||
{ |
||||
Test A { |
||||
get { |
||||
return null; |
||||
} |
||||
set { ; } |
||||
} |
||||
}", data.Document.Text);
|
||||
|
||||
policy.AllowPropertySetBlockInline = false; |
||||
compilationUnit = new CSharpParser ().Parse (data); |
||||
compilationUnit.AcceptVisitor (new DomIndentationVisitor (policy, data), null); |
||||
|
||||
Assert.AreEqual (@"class Test
|
||||
{ |
||||
Test A { |
||||
get { |
||||
return null; |
||||
} |
||||
set { |
||||
; |
||||
} |
||||
} |
||||
}", data.Document.Text);
|
||||
} |
||||
|
||||
[Test()] |
||||
public void TestPropertySetBraceStyle () |
||||
{ |
||||
TextEditorData data = new TextEditorData (); |
||||
data.Document.FileName = "a.cs"; |
||||
data.Document.Text = @"class Test
|
||||
{ |
||||
Test A { |
||||
get; |
||||
set { |
||||
; |
||||
} |
||||
} |
||||
}";
|
||||
|
||||
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); |
||||
policy.PropertySetBraceStyle = BraceStyle.NextLine; |
||||
|
||||
CSharp.Dom.CompilationUnit compilationUnit = new CSharpParser ().Parse (data); |
||||
compilationUnit.AcceptVisitor (new DomIndentationVisitor (policy, data), null); |
||||
|
||||
Console.WriteLine (data.Document.Text); |
||||
Assert.AreEqual (@"class Test
|
||||
{ |
||||
Test A { |
||||
get; |
||||
set |
||||
{ |
||||
; |
||||
} |
||||
} |
||||
}", data.Document.Text);
|
||||
} |
||||
|
||||
[Test()] |
||||
public void TestEventBraceStyle () |
||||
{ |
||||
TextEditorData data = new TextEditorData (); |
||||
data.Document.FileName = "a.cs"; |
||||
data.Document.Text = @"class Test
|
||||
{ |
||||
public event EventHandler Handler { |
||||
add { |
||||
} |
||||
remove { |
||||
} |
||||
} |
||||
}";
|
||||
|
||||
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); |
||||
policy.EventBraceStyle = BraceStyle.NextLine; |
||||
policy.EventAddBraceStyle = BraceStyle.NextLine; |
||||
policy.EventRemoveBraceStyle = BraceStyle.NextLine; |
||||
|
||||
CSharp.Dom.CompilationUnit compilationUnit = new CSharpParser ().Parse (data); |
||||
compilationUnit.AcceptVisitor (new DomIndentationVisitor (policy, data), null); |
||||
|
||||
Console.WriteLine (data.Document.Text); |
||||
Assert.AreEqual (@"class Test
|
||||
{ |
||||
public event EventHandler Handler |
||||
{ |
||||
add |
||||
{ |
||||
} |
||||
remove |
||||
{ |
||||
} |
||||
} |
||||
}", data.Document.Text);
|
||||
} |
||||
|
||||
[Test()] |
||||
public void TestAllowEventAddBlockInline () |
||||
{ |
||||
TextEditorData data = new TextEditorData (); |
||||
data.Document.FileName = "a.cs"; |
||||
data.Document.Text = @"class Test
|
||||
{ |
||||
public event EventHandler Handler { |
||||
add { ; } |
||||
remove { ; } |
||||
} |
||||
}";
|
||||
|
||||
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); |
||||
policy.AllowEventAddBlockInline = true; |
||||
policy.AllowEventRemoveBlockInline = false; |
||||
|
||||
CSharp.Dom.CompilationUnit compilationUnit = new CSharpParser ().Parse (data); |
||||
compilationUnit.AcceptVisitor (new DomIndentationVisitor (policy, data), null); |
||||
|
||||
Console.WriteLine (data.Document.Text); |
||||
Assert.AreEqual (@"class Test
|
||||
{ |
||||
public event EventHandler Handler { |
||||
add { ; } |
||||
remove { |
||||
; |
||||
} |
||||
} |
||||
}", data.Document.Text);
|
||||
} |
||||
|
||||
[Test()] |
||||
public void TestAllowEventRemoveBlockInline () |
||||
{ |
||||
TextEditorData data = new TextEditorData (); |
||||
data.Document.FileName = "a.cs"; |
||||
data.Document.Text = @"class Test
|
||||
{ |
||||
public event EventHandler Handler { |
||||
add { ; } |
||||
remove { ; } |
||||
} |
||||
}";
|
||||
|
||||
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); |
||||
policy.AllowEventAddBlockInline = false; |
||||
policy.AllowEventRemoveBlockInline = true; |
||||
|
||||
CSharp.Dom.CompilationUnit compilationUnit = new CSharpParser ().Parse (data); |
||||
compilationUnit.AcceptVisitor (new DomIndentationVisitor (policy, data), null); |
||||
|
||||
Console.WriteLine (data.Document.Text); |
||||
Assert.AreEqual (@"class Test
|
||||
{ |
||||
public event EventHandler Handler { |
||||
add { |
||||
; |
||||
} |
||||
remove { ; } |
||||
} |
||||
}", data.Document.Text);
|
||||
} |
||||
|
||||
|
||||
|
||||
} |
||||
}*/ |
||||
@ -0,0 +1,162 @@
@@ -0,0 +1,162 @@
|
||||
//
|
||||
// TestFormattingBugs.cs
|
||||
//
|
||||
// Author:
|
||||
// Mike Krüger <mkrueger@novell.com>
|
||||
//
|
||||
// Copyright (c) 2010 Novell, Inc (http://www.novell.com)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
/* |
||||
using System; |
||||
using NUnit.Framework; |
||||
using MonoDevelop.Ide.Gui; |
||||
using MonoDevelop.Projects; |
||||
using MonoDevelop.Core; |
||||
using MonoDevelop.Ide.CodeCompletion; |
||||
using MonoDevelop.Ide.Gui.Content; |
||||
using MonoDevelop.Projects.Dom.Parser; |
||||
using MonoDevelop.CSharp.Parser; |
||||
using MonoDevelop.CSharp.Resolver; |
||||
using MonoDevelop.CSharp.Completion; |
||||
using Mono.TextEditor; |
||||
using MonoDevelop.CSharp.Formatting; |
||||
using System.Collections.Generic; |
||||
using MonoDevelop.Refactoring; |
||||
|
||||
namespace MonoDevelop.CSharpBinding.FormattingTests |
||||
{ |
||||
[TestFixture()] |
||||
public class TestFormattingBugs : UnitTests.TestBase |
||||
{ |
||||
/// <summary>
|
||||
/// Bug 325187 - Bug in smart indent
|
||||
/// </summary>
|
||||
[Test()] |
||||
public void TestBug325187 () |
||||
{ |
||||
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); |
||||
policy.PlaceElseOnNewLine = true; |
||||
|
||||
TestStatementFormatting (policy, |
||||
@"foreach (int i in myints)
|
||||
if (i == 6) |
||||
Console.WriteLine (""Yeah""); |
||||
else |
||||
Console.WriteLine (""Bad indent"");",
|
||||
@"foreach (int i in myints)
|
||||
if (i == 6) |
||||
Console.WriteLine (""Yeah""); |
||||
else |
||||
Console.WriteLine (""Bad indent"");");
|
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Bug 415469 - return ternary in a switch is not tabbed properly
|
||||
/// </summary>
|
||||
[Test()] |
||||
[Ignore("currently failing because of 'string' has the wrong offset - mcs bug")] |
||||
public void TestBug415469 () |
||||
{ |
||||
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); |
||||
|
||||
TestStatementFormatting (policy, |
||||
@"switch (condition) {
|
||||
case CONDITION1: |
||||
return foo != null ? foo.Bar : null; |
||||
case CONDITION2: |
||||
string goo = foo != null ? foo.Bar : null; |
||||
return ""Should be indented like this""; |
||||
}", @"switch (condition) { |
||||
case CONDITION1: |
||||
return foo != null ? foo.Bar : null; |
||||
case CONDITION2: |
||||
string goo = foo != null ? foo.Bar : null; |
||||
return ""Should be indented like this""; |
||||
}");
|
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Bug 540043 - Format option for alignment of using-statements
|
||||
/// </summary>
|
||||
[Test()] |
||||
public void TestBug540043 () |
||||
{ |
||||
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); |
||||
|
||||
TestStatementFormatting (policy, |
||||
@"using (IDisposable a = null)
|
||||
using (IDisposable b = null) { |
||||
int c; |
||||
} |
||||
", @"using (IDisposable a = null) |
||||
using (IDisposable b = null) { |
||||
int c; |
||||
}");
|
||||
} |
||||
|
||||
|
||||
|
||||
|
||||
|
||||
static void TestStatementFormatting (CSharpFormattingPolicy policy, string input, string expectedOutput) |
||||
{ |
||||
TextEditorData data = new TextEditorData (); |
||||
data.Document.FileName = "a.cs"; |
||||
data.Document.Text = |
||||
@"class Test
|
||||
{ |
||||
MyType TestMethod () |
||||
{ |
||||
" + input + @" |
||||
} |
||||
}";
|
||||
|
||||
Console.WriteLine (data.Document.Text); |
||||
|
||||
CSharp.Dom.CompilationUnit compilationUnit = new CSharpParser ().Parse (data); |
||||
DomSpacingVisitor domSpacingVisitor = new DomSpacingVisitor (policy, data); |
||||
domSpacingVisitor.AutoAcceptChanges = false; |
||||
compilationUnit.AcceptVisitor (domSpacingVisitor, null); |
||||
|
||||
DomIndentationVisitor domIndentationVisitor = new DomIndentationVisitor (policy, data); |
||||
domIndentationVisitor.AutoAcceptChanges = false; |
||||
compilationUnit.AcceptVisitor (domIndentationVisitor, null); |
||||
|
||||
List<Change> changes = new List<Change> (); |
||||
changes.AddRange (domSpacingVisitor.Changes); |
||||
changes.AddRange (domIndentationVisitor.Changes); |
||||
RefactoringService.AcceptChanges (null, null, changes); |
||||
|
||||
for (int i = 0; i < data.Document.LineCount; i++) { |
||||
LineSegment line = data.Document.GetLine (i); |
||||
if (line.EditableLength < 2) |
||||
continue; |
||||
data.Remove (line.Offset, 2); |
||||
} |
||||
string text = data.Document.GetTextBetween (data.Document.GetLine (4).Offset, |
||||
data.Document.GetLine (data.Document.LineCount - 2).Offset).Trim (); |
||||
Console.WriteLine (text); |
||||
Assert.AreEqual (expectedOutput, text); |
||||
} |
||||
|
||||
|
||||
} |
||||
} |
||||
*/ |
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,500 @@
@@ -0,0 +1,500 @@
|
||||
//
|
||||
// TestTypeLevelIndentation.cs
|
||||
//
|
||||
// Author:
|
||||
// Mike Krüger <mkrueger@novell.com>
|
||||
//
|
||||
// Copyright (c) 2010 Novell, Inc (http://www.novell.com)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
/* |
||||
using System; |
||||
using NUnit.Framework; |
||||
using MonoDevelop.Ide.Gui; |
||||
using MonoDevelop.Projects; |
||||
using MonoDevelop.Core; |
||||
using MonoDevelop.Ide.CodeCompletion; |
||||
using MonoDevelop.Ide.Gui.Content; |
||||
using MonoDevelop.Projects.Dom.Parser; |
||||
using MonoDevelop.CSharp.Parser; |
||||
using MonoDevelop.CSharp.Resolver; |
||||
using MonoDevelop.CSharp.Completion; |
||||
using Mono.TextEditor; |
||||
using MonoDevelop.CSharp.Formatting; |
||||
|
||||
namespace MonoDevelop.CSharpBinding.FormattingTests |
||||
{ |
||||
[TestFixture()] |
||||
public class TestTypeLevelIndentation : UnitTests.TestBase |
||||
{ |
||||
[Test()] |
||||
public void TestClassIndentation () |
||||
{ |
||||
TextEditorData data = new TextEditorData (); |
||||
data.Document.FileName = "a.cs"; |
||||
data.Document.Text = |
||||
@" class Test {}"; |
||||
|
||||
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); |
||||
policy.ClassBraceStyle = BraceStyle.DoNotChange; |
||||
|
||||
CSharp.Dom.CompilationUnit compilationUnit = new CSharpParser ().Parse (data); |
||||
compilationUnit.AcceptVisitor (new DomIndentationVisitor (policy, data), null); |
||||
Assert.AreEqual (@"class Test {}", data.Document.Text); |
||||
} |
||||
|
||||
[Test()] |
||||
public void TestIndentClassBody () |
||||
{ |
||||
TextEditorData data = new TextEditorData (); |
||||
data.Document.FileName = "a.cs"; |
||||
data.Document.Text = |
||||
@"class Test
|
||||
{ |
||||
Test a; |
||||
}";
|
||||
|
||||
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); |
||||
policy.IndentClassBody = true; |
||||
|
||||
CSharp.Dom.CompilationUnit compilationUnit = new CSharpParser ().Parse (data); |
||||
compilationUnit.AcceptVisitor (new DomIndentationVisitor (policy, data), null); |
||||
Assert.AreEqual (@"class Test
|
||||
{ |
||||
Test a; |
||||
}", data.Document.Text);
|
||||
policy.IndentClassBody = false; |
||||
compilationUnit = new CSharpParser ().Parse (data); |
||||
compilationUnit.AcceptVisitor (new DomIndentationVisitor (policy, data), null); |
||||
Assert.AreEqual (@"class Test
|
||||
{ |
||||
Test a; |
||||
}", data.Document.Text);
|
||||
} |
||||
|
||||
[Test()] |
||||
public void TestIndentInterfaceBody () |
||||
{ |
||||
TextEditorData data = new TextEditorData (); |
||||
data.Document.FileName = "a.cs"; |
||||
data.Document.Text = |
||||
@"interface Test
|
||||
{ |
||||
Test Foo (); |
||||
}";
|
||||
|
||||
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); |
||||
policy.IndentInterfaceBody = true; |
||||
|
||||
CSharp.Dom.CompilationUnit compilationUnit = new CSharpParser ().Parse (data); |
||||
compilationUnit.AcceptVisitor (new DomIndentationVisitor (policy, data), null); |
||||
Assert.AreEqual (@"interface Test
|
||||
{ |
||||
Test Foo (); |
||||
}", data.Document.Text);
|
||||
policy.IndentInterfaceBody = false; |
||||
compilationUnit = new CSharpParser ().Parse (data); |
||||
compilationUnit.AcceptVisitor (new DomIndentationVisitor (policy, data), null); |
||||
Assert.AreEqual (@"interface Test
|
||||
{ |
||||
Test Foo (); |
||||
}", data.Document.Text);
|
||||
} |
||||
|
||||
[Test()] |
||||
public void TestIndentStructBody () |
||||
{ |
||||
TextEditorData data = new TextEditorData (); |
||||
data.Document.FileName = "a.cs"; |
||||
data.Document.Text = |
||||
@"struct Test
|
||||
{ |
||||
Test a; |
||||
}";
|
||||
|
||||
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); |
||||
policy.IndentStructBody = true; |
||||
|
||||
CSharp.Dom.CompilationUnit compilationUnit = new CSharpParser ().Parse (data); |
||||
compilationUnit.AcceptVisitor (new DomIndentationVisitor (policy, data), null); |
||||
Assert.AreEqual (@"struct Test
|
||||
{ |
||||
Test a; |
||||
}", data.Document.Text);
|
||||
policy.IndentStructBody = false; |
||||
compilationUnit = new CSharpParser ().Parse (data); |
||||
compilationUnit.AcceptVisitor (new DomIndentationVisitor (policy, data), null); |
||||
Assert.AreEqual (@"struct Test
|
||||
{ |
||||
Test a; |
||||
}", data.Document.Text);
|
||||
} |
||||
|
||||
[Test()] |
||||
public void TestIndentEnumBody () |
||||
{ |
||||
TextEditorData data = new TextEditorData (); |
||||
data.Document.FileName = "a.cs"; |
||||
data.Document.Text = |
||||
@"enum Test
|
||||
{ |
||||
A |
||||
}";
|
||||
|
||||
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); |
||||
policy.IndentEnumBody = true; |
||||
|
||||
CSharp.Dom.CompilationUnit compilationUnit = new CSharpParser ().Parse (data); |
||||
compilationUnit.AcceptVisitor (new DomIndentationVisitor (policy, data), null); |
||||
Assert.AreEqual (@"enum Test
|
||||
{ |
||||
A |
||||
}", data.Document.Text);
|
||||
policy.IndentEnumBody = false; |
||||
compilationUnit = new CSharpParser ().Parse (data); |
||||
compilationUnit.AcceptVisitor (new DomIndentationVisitor (policy, data), null); |
||||
Assert.AreEqual (@"enum Test
|
||||
{ |
||||
A |
||||
}", data.Document.Text);
|
||||
} |
||||
|
||||
[Test()] |
||||
public void TestIndentMethodBody () |
||||
{ |
||||
TextEditorData data = new TextEditorData (); |
||||
data.Document.FileName = "a.cs"; |
||||
data.Document.Text = |
||||
@"class Test
|
||||
{ |
||||
Test Foo () |
||||
{ |
||||
; |
||||
; |
||||
} |
||||
}";
|
||||
|
||||
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); |
||||
policy.IndentMethodBody = true; |
||||
|
||||
CSharp.Dom.CompilationUnit compilationUnit = new CSharpParser ().Parse (data); |
||||
compilationUnit.AcceptVisitor (new DomIndentationVisitor (policy, data), null); |
||||
Assert.AreEqual (@"class Test
|
||||
{ |
||||
Test Foo () |
||||
{ |
||||
; |
||||
; |
||||
} |
||||
}", data.Document.Text);
|
||||
policy.IndentMethodBody = false; |
||||
compilationUnit = new CSharpParser ().Parse (data); |
||||
compilationUnit.AcceptVisitor (new DomIndentationVisitor (policy, data), null); |
||||
Assert.AreEqual (@"class Test
|
||||
{ |
||||
Test Foo () |
||||
{ |
||||
; |
||||
; |
||||
} |
||||
}", data.Document.Text);
|
||||
} |
||||
|
||||
[Test()] |
||||
public void TestIndentMethodBodyOperatorCase () |
||||
{ |
||||
TextEditorData data = new TextEditorData (); |
||||
data.Document.FileName = "a.cs"; |
||||
data.Document.Text = |
||||
@"class Test
|
||||
{ |
||||
static Test operator+(Test left, Test right) |
||||
{ |
||||
; |
||||
; |
||||
} |
||||
}";
|
||||
|
||||
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); |
||||
policy.IndentMethodBody = true; |
||||
|
||||
CSharp.Dom.CompilationUnit compilationUnit = new CSharpParser ().Parse (data); |
||||
compilationUnit.AcceptVisitor (new DomIndentationVisitor (policy, data), null); |
||||
Assert.AreEqual (@"class Test
|
||||
{ |
||||
static Test operator+(Test left, Test right) |
||||
{ |
||||
; |
||||
; |
||||
} |
||||
}", data.Document.Text);
|
||||
policy.IndentMethodBody = false; |
||||
compilationUnit = new CSharpParser ().Parse (data); |
||||
compilationUnit.AcceptVisitor (new DomIndentationVisitor (policy, data), null); |
||||
Assert.AreEqual (@"class Test
|
||||
{ |
||||
static Test operator+(Test left, Test right) |
||||
{ |
||||
; |
||||
; |
||||
} |
||||
}", data.Document.Text);
|
||||
} |
||||
|
||||
[Test()] |
||||
public void TestIndentPropertyBody () |
||||
{ |
||||
TextEditorData data = new TextEditorData (); |
||||
data.Document.FileName = "a.cs"; |
||||
data.Document.Text = |
||||
@"class Test
|
||||
{ |
||||
Test TestMe { |
||||
get; |
||||
set; |
||||
} |
||||
}";
|
||||
|
||||
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); |
||||
policy.IndentPropertyBody = true; |
||||
|
||||
CSharp.Dom.CompilationUnit compilationUnit = new CSharpParser ().Parse (data); |
||||
compilationUnit.AcceptVisitor (new DomIndentationVisitor (policy, data), null); |
||||
Assert.AreEqual (@"class Test
|
||||
{ |
||||
Test TestMe { |
||||
get; |
||||
set; |
||||
} |
||||
}", data.Document.Text);
|
||||
policy.IndentPropertyBody = false; |
||||
compilationUnit = new CSharpParser ().Parse (data); |
||||
compilationUnit.AcceptVisitor (new DomIndentationVisitor (policy, data), null); |
||||
Assert.AreEqual (@"class Test
|
||||
{ |
||||
Test TestMe { |
||||
get; |
||||
set; |
||||
} |
||||
}", data.Document.Text);
|
||||
} |
||||
|
||||
[Test()] |
||||
public void TestIndentPropertyBodyIndexerCase () |
||||
{ |
||||
TextEditorData data = new TextEditorData (); |
||||
data.Document.FileName = "a.cs"; |
||||
data.Document.Text = |
||||
@"class Test
|
||||
{ |
||||
Test this[int a] { |
||||
get { |
||||
return null; |
||||
} |
||||
set { |
||||
; |
||||
} |
||||
} |
||||
}";
|
||||
|
||||
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); |
||||
policy.IndentPropertyBody = true; |
||||
|
||||
CSharp.Dom.CompilationUnit compilationUnit = new CSharpParser ().Parse (data); |
||||
compilationUnit.AcceptVisitor (new DomIndentationVisitor (policy, data), null); |
||||
Assert.AreEqual (@"class Test
|
||||
{ |
||||
Test this[int a] { |
||||
get { |
||||
return null; |
||||
} |
||||
set { |
||||
; |
||||
} |
||||
} |
||||
}", data.Document.Text);
|
||||
policy.IndentPropertyBody = false; |
||||
compilationUnit = new CSharpParser ().Parse (data); |
||||
compilationUnit.AcceptVisitor (new DomIndentationVisitor (policy, data), null); |
||||
Assert.AreEqual (@"class Test
|
||||
{ |
||||
Test this[int a] { |
||||
get { |
||||
return null; |
||||
} |
||||
set { |
||||
; |
||||
} |
||||
} |
||||
}", data.Document.Text);
|
||||
} |
||||
|
||||
|
||||
[Test()] |
||||
[Ignore("currently failing because namespaces are not inserted")] |
||||
public void TestIndentNamespaceBody () |
||||
{ |
||||
TextEditorData data = new TextEditorData (); |
||||
data.Document.FileName = "a.cs"; |
||||
data.Document.Text = |
||||
@" namespace Test {
|
||||
class FooBar {} |
||||
}";
|
||||
|
||||
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); |
||||
policy.ClassBraceStyle = BraceStyle.DoNotChange; |
||||
policy.IndentNamespaceBody = true; |
||||
|
||||
CSharp.Dom.CompilationUnit compilationUnit = new CSharpParser ().Parse (data); |
||||
compilationUnit.AcceptVisitor (new DomIndentationVisitor (policy, data), null); |
||||
Assert.AreEqual (@"namespace Test {
|
||||
class FooBar {} |
||||
}", data.Document.Text);
|
||||
|
||||
policy.IndentNamespaceBody = false; |
||||
compilationUnit = new CSharpParser ().Parse (data); |
||||
compilationUnit.AcceptVisitor (new DomIndentationVisitor (policy, data), null); |
||||
Assert.AreEqual (@"namespace Test {
|
||||
class FooBar {} |
||||
}", data.Document.Text);
|
||||
} |
||||
|
||||
[Test()] |
||||
public void TestMethodIndentation () |
||||
{ |
||||
TextEditorData data = new TextEditorData (); |
||||
data.Document.FileName = "a.cs"; |
||||
data.Document.Text = |
||||
@"class Test
|
||||
{ |
||||
MyType TestMethod () {} |
||||
}";
|
||||
|
||||
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); |
||||
policy.MethodBraceStyle = BraceStyle.DoNotChange; |
||||
|
||||
CSharp.Dom.CompilationUnit compilationUnit = new CSharpParser ().Parse (data); |
||||
compilationUnit.AcceptVisitor (new DomIndentationVisitor (policy, data), null); |
||||
Assert.AreEqual (@"class Test
|
||||
{ |
||||
MyType TestMethod () {} |
||||
}", data.Document.Text);
|
||||
} |
||||
|
||||
[Test()] |
||||
public void TestPropertyIndentation () |
||||
{ |
||||
TextEditorData data = new TextEditorData (); |
||||
data.Document.FileName = "a.cs"; |
||||
data.Document.Text = |
||||
@"class Test
|
||||
{ |
||||
public int Prop { get; set; } |
||||
}";
|
||||
|
||||
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); |
||||
policy.PropertyBraceStyle = BraceStyle.DoNotChange; |
||||
|
||||
CSharp.Dom.CompilationUnit compilationUnit = new CSharpParser ().Parse (data); |
||||
compilationUnit.AcceptVisitor (new DomIndentationVisitor (policy, data), null); |
||||
Assert.AreEqual (@"class Test
|
||||
{ |
||||
public int Prop { get; set; } |
||||
}", data.Document.Text);
|
||||
} |
||||
|
||||
[Test()] |
||||
public void TestPropertyIndentationCase2 () |
||||
{ |
||||
TextEditorData data = new TextEditorData (); |
||||
data.Document.FileName = "a.cs"; |
||||
data.Document.Text = |
||||
@"class Test
|
||||
{ |
||||
public int Prop { |
||||
get; |
||||
set; |
||||
} |
||||
}";
|
||||
|
||||
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); |
||||
|
||||
CSharp.Dom.CompilationUnit compilationUnit = new CSharpParser ().Parse (data); |
||||
compilationUnit.AcceptVisitor (new DomIndentationVisitor (policy, data), null); |
||||
Assert.AreEqual (@"class Test
|
||||
{ |
||||
public int Prop { |
||||
get; |
||||
set; |
||||
} |
||||
}", data.Document.Text);
|
||||
} |
||||
|
||||
|
||||
[Test()] |
||||
public void TestIndentEventBody () |
||||
{ |
||||
TextEditorData data = new TextEditorData (); |
||||
data.Document.FileName = "a.cs"; |
||||
data.Document.Text = |
||||
@"class Test
|
||||
{ |
||||
public event EventHandler TestMe { |
||||
add { |
||||
; |
||||
} |
||||
remove { |
||||
; |
||||
} |
||||
} |
||||
}";
|
||||
|
||||
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); |
||||
policy.IndentEventBody = true; |
||||
|
||||
CSharp.Dom.CompilationUnit compilationUnit = new CSharpParser ().Parse (data); |
||||
compilationUnit.AcceptVisitor (new DomIndentationVisitor (policy, data), null); |
||||
Assert.AreEqual (@"class Test
|
||||
{ |
||||
public event EventHandler TestMe { |
||||
add { |
||||
; |
||||
} |
||||
remove { |
||||
; |
||||
} |
||||
} |
||||
}", data.Document.Text);
|
||||
policy.IndentEventBody = false; |
||||
compilationUnit = new CSharpParser ().Parse (data); |
||||
compilationUnit.AcceptVisitor (new DomIndentationVisitor (policy, data), null); |
||||
Assert.AreEqual (@"class Test
|
||||
{ |
||||
public event EventHandler TestMe { |
||||
add { |
||||
; |
||||
} |
||||
remove { |
||||
; |
||||
} |
||||
} |
||||
}", data.Document.Text);
|
||||
} |
||||
} |
||||
}*/ |
||||
Loading…
Reference in new issue