From e93009afeec11144cbba6752e1e9c5a028226e90 Mon Sep 17 00:00:00 2001 From: mike Date: Mon, 12 Mar 2012 16:35:44 +0100 Subject: [PATCH] Fixed context action unit tests. --- ICSharpCode.NRefactory.CSharp/Ast/CSharpUtil.cs | 4 +--- .../Refactoring/ContextAction/AddAnotherAccessor.cs | 6 +++++- .../Refactoring/ContextAction/InvertIf.cs | 6 +++--- .../CSharp/ContextAction/AddAnotherAccessorTests.cs | 2 -- .../CSharp/ContextAction/GenerateGetterTests.cs | 1 - .../CSharp/ContextAction/GeneratePropertyTests.cs | 1 - .../CSharp/ContextAction/InvertIfTests.cs | 1 - .../CSharp/ContextAction/RemoveBracesTests.cs | 8 ++++---- 8 files changed, 13 insertions(+), 16 deletions(-) diff --git a/ICSharpCode.NRefactory.CSharp/Ast/CSharpUtil.cs b/ICSharpCode.NRefactory.CSharp/Ast/CSharpUtil.cs index 46f528d46b..e13bf334c3 100644 --- a/ICSharpCode.NRefactory.CSharp/Ast/CSharpUtil.cs +++ b/ICSharpCode.NRefactory.CSharp/Ast/CSharpUtil.cs @@ -74,7 +74,6 @@ namespace ICSharpCode.NRefactory.CSharp return new UnaryOperatorExpression (UnaryOperatorType.Not, new ParenthesizedExpression (condition)); } } - if (condition is ConditionalExpression) { var cEx = condition as ConditionalExpression; cEx.Condition = InvertCondition (cEx.Condition); @@ -83,8 +82,7 @@ namespace ICSharpCode.NRefactory.CSharp if (condition is PrimitiveExpression) { var pex = condition as PrimitiveExpression; if (pex.Value is bool) { - pex.Value = !((bool)pex.Value); - return pex; + return new PrimitiveExpression (!((bool)pex.Value)); } } diff --git a/ICSharpCode.NRefactory.CSharp/Refactoring/ContextAction/AddAnotherAccessor.cs b/ICSharpCode.NRefactory.CSharp/Refactoring/ContextAction/AddAnotherAccessor.cs index b950e032ea..57a7931a15 100644 --- a/ICSharpCode.NRefactory.CSharp/Refactoring/ContextAction/AddAnotherAccessor.cs +++ b/ICSharpCode.NRefactory.CSharp/Refactoring/ContextAction/AddAnotherAccessor.cs @@ -56,7 +56,11 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring accessor.Role = pdecl.Setter.IsNull ? PropertyDeclaration.SetterRole : PropertyDeclaration.GetterRole; using (var script = context.StartScript ()) { - script.InsertBefore (pdecl.RBraceToken, accessor); + if (pdecl.Setter.IsNull && !pdecl.Getter.IsNull) { + script.InsertBefore (pdecl.RBraceToken, accessor); + } else { + script.InsertBefore (pdecl.Getter, accessor); + } script.Select (accessorStatement); script.FormatText (pdecl); } diff --git a/ICSharpCode.NRefactory.CSharp/Refactoring/ContextAction/InvertIf.cs b/ICSharpCode.NRefactory.CSharp/Refactoring/ContextAction/InvertIf.cs index 113a24b650..f6bb8a1824 100644 --- a/ICSharpCode.NRefactory.CSharp/Refactoring/ContextAction/InvertIf.cs +++ b/ICSharpCode.NRefactory.CSharp/Refactoring/ContextAction/InvertIf.cs @@ -44,9 +44,9 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring var ifStatement = GetIfElseStatement (context); using (var script = context.StartScript ()) { - script.Replace (ifStatement.Condition, CSharpUtil.InvertCondition (ifStatement.Condition)); - script.Replace (ifStatement.TrueStatement, ifStatement.FalseStatement); - script.Replace (ifStatement.FalseStatement, ifStatement.TrueStatement); + script.Replace (ifStatement.Condition, CSharpUtil.InvertCondition (ifStatement.Condition.Clone ())); + script.Replace (ifStatement.TrueStatement, ifStatement.FalseStatement.Clone ()); + script.Replace (ifStatement.FalseStatement, ifStatement.TrueStatement.Clone ()); script.FormatText (ifStatement); } } diff --git a/ICSharpCode.NRefactory.Tests/CSharp/ContextAction/AddAnotherAccessorTests.cs b/ICSharpCode.NRefactory.Tests/CSharp/ContextAction/AddAnotherAccessorTests.cs index 1334c46987..3de69bf599 100644 --- a/ICSharpCode.NRefactory.Tests/CSharp/ContextAction/AddAnotherAccessorTests.cs +++ b/ICSharpCode.NRefactory.Tests/CSharp/ContextAction/AddAnotherAccessorTests.cs @@ -33,7 +33,6 @@ namespace ICSharpCode.NRefactory.CSharp.ContextActions [TestFixture] public class AddAnotherAccessorTests : ContextActionTestBase { - [Ignore("Format action is not implemented.")] [Test()] public void TestAddSet () { @@ -65,7 +64,6 @@ namespace ICSharpCode.NRefactory.CSharp.ContextActions "}", result); } - [Ignore("Format action is not implemented.")] [Test()] public void TestAddGet () { diff --git a/ICSharpCode.NRefactory.Tests/CSharp/ContextAction/GenerateGetterTests.cs b/ICSharpCode.NRefactory.Tests/CSharp/ContextAction/GenerateGetterTests.cs index e721a4c91f..4436f15dff 100644 --- a/ICSharpCode.NRefactory.Tests/CSharp/ContextAction/GenerateGetterTests.cs +++ b/ICSharpCode.NRefactory.Tests/CSharp/ContextAction/GenerateGetterTests.cs @@ -33,7 +33,6 @@ namespace ICSharpCode.NRefactory.CSharp.ContextActions [TestFixture] public class GenerateGetterTests : ContextActionTestBase { - [Ignore("Insert with cursor is not implemented.")] [Test()] public void Test () { diff --git a/ICSharpCode.NRefactory.Tests/CSharp/ContextAction/GeneratePropertyTests.cs b/ICSharpCode.NRefactory.Tests/CSharp/ContextAction/GeneratePropertyTests.cs index 50263c560f..58b5140acd 100644 --- a/ICSharpCode.NRefactory.Tests/CSharp/ContextAction/GeneratePropertyTests.cs +++ b/ICSharpCode.NRefactory.Tests/CSharp/ContextAction/GeneratePropertyTests.cs @@ -32,7 +32,6 @@ namespace ICSharpCode.NRefactory.CSharp.ContextActions [TestFixture] public class GeneratePropertyTests : ContextActionTestBase { - [Ignore("Insert with cursor is not implemented.")] [Test()] public void Test () { diff --git a/ICSharpCode.NRefactory.Tests/CSharp/ContextAction/InvertIfTests.cs b/ICSharpCode.NRefactory.Tests/CSharp/ContextAction/InvertIfTests.cs index a1d8c75978..a830b9ed5e 100644 --- a/ICSharpCode.NRefactory.Tests/CSharp/ContextAction/InvertIfTests.cs +++ b/ICSharpCode.NRefactory.Tests/CSharp/ContextAction/InvertIfTests.cs @@ -33,7 +33,6 @@ namespace ICSharpCode.NRefactory.CSharp.ContextActions [TestFixture] public class InvertIfTestsTests : ContextActionTestBase { - [Ignore("Formatting not implemented in test context")] [Test()] public void Test () { diff --git a/ICSharpCode.NRefactory.Tests/CSharp/ContextAction/RemoveBracesTests.cs b/ICSharpCode.NRefactory.Tests/CSharp/ContextAction/RemoveBracesTests.cs index 9929dc567f..f57ef573b8 100644 --- a/ICSharpCode.NRefactory.Tests/CSharp/ContextAction/RemoveBracesTests.cs +++ b/ICSharpCode.NRefactory.Tests/CSharp/ContextAction/RemoveBracesTests.cs @@ -32,7 +32,6 @@ namespace ICSharpCode.NRefactory.CSharp.ContextActions [TestFixture] public class RemoveBracesTests : ContextActionTestBase { - [Ignore("Formatting not implemented in test context")] [Test()] public void TestSimpleBraces () { @@ -42,8 +41,8 @@ namespace ICSharpCode.NRefactory.CSharp.ContextActions "{" + Environment.NewLine + " void Test ()" + Environment.NewLine + " {" + Environment.NewLine + - " if (true) ${" + Environment.NewLine + - " ;" + Environment.NewLine + + " if (true) ${" + Environment.NewLine + + " ;" + Environment.NewLine + " }" + Environment.NewLine + " }" + Environment.NewLine + "}" @@ -54,7 +53,8 @@ namespace ICSharpCode.NRefactory.CSharp.ContextActions "{" + Environment.NewLine + " void Test ()" + Environment.NewLine + " {" + Environment.NewLine + - " ;" + Environment.NewLine + + " if (true) " + Environment.NewLine + + " ;" + Environment.NewLine + " }" + Environment.NewLine + "}", result); }