Browse Source

Added unit tests for context actions.

newNRvisualizers
Mike Krüger 14 years ago
parent
commit
764b8a33f4
  1. 4
      ICSharpCode.NRefactory.CSharp/Refactoring/ContextAction/ConvertForeachToFor.cs
  2. 10
      ICSharpCode.NRefactory.CSharp/Refactoring/ContextAction/InsertAnonymousMethodSignature.cs
  3. 100
      ICSharpCode.NRefactory.Tests/CSharp/ContextAction/AddAnotherAccessorTests.cs
  4. 64
      ICSharpCode.NRefactory.Tests/CSharp/ContextAction/CheckIfParameterIsNullTests.cs
  5. 62
      ICSharpCode.NRefactory.Tests/CSharp/ContextAction/ConvertDecToHexTests.cs
  6. 99
      ICSharpCode.NRefactory.Tests/CSharp/ContextAction/ConvertForeachToForTests.cs
  7. 62
      ICSharpCode.NRefactory.Tests/CSharp/ContextAction/ConvertHexToDecTests.cs
  8. 64
      ICSharpCode.NRefactory.Tests/CSharp/ContextAction/FlipOperatorArgumentsTests.cs
  9. 62
      ICSharpCode.NRefactory.Tests/CSharp/ContextAction/GenerateGetterTests.cs
  10. 72
      ICSharpCode.NRefactory.Tests/CSharp/ContextAction/GenerateSwitchLabelsTests.cs
  11. 65
      ICSharpCode.NRefactory.Tests/CSharp/ContextAction/InsertAnonymousMethodSignatureTests.cs
  12. 85
      ICSharpCode.NRefactory.Tests/CSharp/ContextAction/IntroduceFormatItemTests.cs
  13. 69
      ICSharpCode.NRefactory.Tests/CSharp/ContextAction/InvertIfTests.cs
  14. 62
      ICSharpCode.NRefactory.Tests/CSharp/ContextAction/RemoveBackingStoreTests.cs
  15. 63
      ICSharpCode.NRefactory.Tests/CSharp/ContextAction/RemoveBracesTests.cs
  16. 60
      ICSharpCode.NRefactory.Tests/CSharp/ContextAction/ReplaceEmptyStringTests.cs
  17. 24
      ICSharpCode.NRefactory.Tests/CSharp/ContextAction/SplitDeclarationAndAssignmentTests.cs
  18. 84
      ICSharpCode.NRefactory.Tests/CSharp/ContextAction/SplitStringTests.cs
  19. 46
      ICSharpCode.NRefactory.Tests/CSharp/ContextAction/TestRefactoringContext.cs
  20. 24
      ICSharpCode.NRefactory.Tests/ICSharpCode.NRefactory.Tests.csproj

4
ICSharpCode.NRefactory.CSharp/Refactoring/ContextAction/ConvertForeachToFor.cs

@ -41,8 +41,8 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -41,8 +41,8 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
static string GetCountProperty (IType type)
{
// if (!type.)
// return "Length";
if (type.Kind == TypeKind.Array)
return "Length";
return "Count";
}

10
ICSharpCode.NRefactory.CSharp/Refactoring/ContextAction/InsertAnonymousMethodSignature.cs

@ -52,7 +52,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -52,7 +52,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
var paramType = delegateMethod.Parameters [k].Type;
sb.Append (paramType.ToString ());
sb.Append (context.CreateShortType (paramType));
sb.Append (" ");
sb.Append (delegateMethod.Parameters [k].Name);
}
@ -68,19 +68,19 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -68,19 +68,19 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
delegateType = null;
var anonymousMethodExpression = context.GetNode<AnonymousMethodExpression> ();
if (anonymousMethodExpression == null || !anonymousMethodExpression.DelegateToken.Contains (context.Location.Line, context.Location.Column) || anonymousMethodExpression.HasParameterList)
if (anonymousMethodExpression == null || !anonymousMethodExpression.DelegateToken.Contains (context.Location) || anonymousMethodExpression.HasParameterList)
return null;
IType resolvedType = null;
var parent = anonymousMethodExpression.Parent;
if (parent is AssignmentExpression) {
resolvedType = context.Resolve (((AssignmentExpression)parent).Left).Type;
} else if (parent is VariableDeclarationStatement) {
resolvedType = context.Resolve (((VariableDeclarationStatement)parent).Type).Type;
} else if (parent is VariableInitializer) {
resolvedType = context.Resolve (((VariableDeclarationStatement)parent.Parent).Type).Type;
} else if (parent is InvocationExpression) {
// TODO: handle invocations
}
if (resolvedType == null)
return null;
delegateType = resolvedType;

100
ICSharpCode.NRefactory.Tests/CSharp/ContextAction/AddAnotherAccessorTests.cs

@ -0,0 +1,100 @@ @@ -0,0 +1,100 @@
//
// AddAnotherAccessorTests.cs
//
// Author:
// Mike Krüger <mkrueger@xamarin.com>
//
// Copyright (c) 2012 Xamarin Inc.
//
// 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 ICSharpCode.NRefactory.CSharp.Refactoring;
namespace ICSharpCode.NRefactory.CSharp.ContextActions
{
[TestFixture]
public class AddAnotherAccessorTests : ContextActionTestBase
{
[Ignore("Format action is not implemented.")]
[Test()]
public void TestAddSet ()
{
string result = RunContextAction (
new AddAnotherAccessor (),
"class TestClass" + Environment.NewLine +
"{" + Environment.NewLine +
" int field;" + Environment.NewLine +
" public int $Field {" + Environment.NewLine +
" get {" + Environment.NewLine +
" return field;" + Environment.NewLine +
" }" + Environment.NewLine +
" }" + Environment.NewLine +
"}"
);
Assert.AreEqual (
"class TestClass" + Environment.NewLine +
"{" + Environment.NewLine +
" int field;" + Environment.NewLine +
" public int Field {" + Environment.NewLine +
" get {" + Environment.NewLine +
" return field;" + Environment.NewLine +
" }" + Environment.NewLine +
" set {" + Environment.NewLine +
" field = value;" + Environment.NewLine +
" }" + Environment.NewLine +
" }" + Environment.NewLine +
"}", result);
}
[Ignore("Format action is not implemented.")]
[Test()]
public void TestAddGet ()
{
string result = RunContextAction (
new AddAnotherAccessor (),
"class TestClass" + Environment.NewLine +
"{" + Environment.NewLine +
" int field;" + Environment.NewLine +
" public int $Field {" + Environment.NewLine +
" set {" + Environment.NewLine +
" field = value;" + Environment.NewLine +
" }" + Environment.NewLine +
" }" + Environment.NewLine +
"}"
);
Assert.AreEqual (
"class TestClass" + Environment.NewLine +
"{" + Environment.NewLine +
" int field;" + Environment.NewLine +
" public int Field {" + Environment.NewLine +
" get {" + Environment.NewLine +
" return field;" + Environment.NewLine +
" }" + Environment.NewLine +
" set {" + Environment.NewLine +
" field = value;" + Environment.NewLine +
" }" + Environment.NewLine +
" }" + Environment.NewLine +
"}", result);
}
}
}

64
ICSharpCode.NRefactory.Tests/CSharp/ContextAction/CheckIfParameterIsNullTests.cs

@ -0,0 +1,64 @@ @@ -0,0 +1,64 @@
//
// CheckIfParameterIsNullTests.cs
//
// Author:
// Mike Krüger <mkrueger@xamarin.com>
//
// Copyright (c) 2012 Xamarin Inc.
//
// 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 ICSharpCode.NRefactory.CSharp.Refactoring;
namespace ICSharpCode.NRefactory.CSharp.ContextActions
{
[TestFixture]
public class CheckIfParameterIsNullTests : ContextActionTestBase
{
[Test()]
public void Test ()
{
string result = RunContextAction (
new CheckIfParameterIsNull (),
"using System;" + Environment.NewLine +
"class TestClass" + Environment.NewLine +
"{" + Environment.NewLine +
" void Test (string $param)" + Environment.NewLine +
" {" + Environment.NewLine +
" Console.WriteLine (param);" + Environment.NewLine +
" }" + Environment.NewLine +
"}"
);
Assert.AreEqual (
"using System;" + Environment.NewLine +
"class TestClass" + Environment.NewLine +
"{" + Environment.NewLine +
" void Test (string param)" + Environment.NewLine +
" {" + Environment.NewLine +
" if (param == null)" + Environment.NewLine +
" throw new ArgumentNullException (\"param\");" + Environment.NewLine +
" Console.WriteLine (param);" + Environment.NewLine +
" }" + Environment.NewLine +
"}", result);
}
}
}

62
ICSharpCode.NRefactory.Tests/CSharp/ContextAction/ConvertDecToHexTests.cs

@ -0,0 +1,62 @@ @@ -0,0 +1,62 @@
//
// ConvertDecToHexTests.cs
//
// Author:
// Mike Krüger <mkrueger@xamarin.com>
//
// Copyright (c) 2012 Xamarin Inc.
//
// 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 ICSharpCode.NRefactory.CSharp.Refactoring;
namespace ICSharpCode.NRefactory.CSharp.ContextActions
{
[TestFixture]
public class ConvertDecToHexTests : ContextActionTestBase
{
[Test()]
public void Test ()
{
string result = RunContextAction (
new ConvertDecToHex (),
"using System;" + Environment.NewLine +
"class TestClass" + Environment.NewLine +
"{" + Environment.NewLine +
" void Test ()" + Environment.NewLine +
" {" + Environment.NewLine +
" int i = $16;" + Environment.NewLine +
" }" + Environment.NewLine +
"}"
);
Assert.AreEqual (
"using System;" + Environment.NewLine +
"class TestClass" + Environment.NewLine +
"{" + Environment.NewLine +
" void Test ()" + Environment.NewLine +
" {" + Environment.NewLine +
" int i = 0x10;" + Environment.NewLine +
" }" + Environment.NewLine +
"}", result);
}
}
}

99
ICSharpCode.NRefactory.Tests/CSharp/ContextAction/ConvertForeachToForTests.cs

@ -0,0 +1,99 @@ @@ -0,0 +1,99 @@
//
// ConvertForeachToForTests.cs
//
// Author:
// Mike Krüger <mkrueger@xamarin.com>
//
// Copyright (c) 2012 Xamarin Inc.
//
// 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 ICSharpCode.NRefactory.CSharp.Refactoring;
namespace ICSharpCode.NRefactory.CSharp.ContextActions
{
[TestFixture]
public class ConvertForeachToForTests : ContextActionTestBase
{
[Test()]
public void TestArray ()
{
string result = RunContextAction (
new ConvertForeachToFor (),
"using System;" + Environment.NewLine +
"class TestClass" + Environment.NewLine +
"{" + Environment.NewLine +
" void Test (string[] args)" + Environment.NewLine +
" {" + Environment.NewLine +
" $foreach (var v in args) {" + Environment.NewLine +
" Console.WriteLine (v);" + Environment.NewLine +
" }" + Environment.NewLine +
" }" + Environment.NewLine +
"}"
);
Assert.AreEqual (
"using System;" + Environment.NewLine +
"class TestClass" + Environment.NewLine +
"{" + Environment.NewLine +
" void Test (string[] args)" + Environment.NewLine +
" {" + Environment.NewLine +
" for (int i = 0; i < args.Length; i++) {" + Environment.NewLine +
" var v = args [i];" + Environment.NewLine +
" Console.WriteLine (v);" + Environment.NewLine +
" }" + Environment.NewLine +
" }" + Environment.NewLine +
"}", result);
}
[Test()]
public void TestEnumeration ()
{
string result = RunContextAction (
new ConvertForeachToFor (),
"using System;" + Environment.NewLine +
"using System.Collections.Generic;" + Environment.NewLine +
"class TestClass" + Environment.NewLine +
"{" + Environment.NewLine +
" void Test (List<string> args)" + Environment.NewLine +
" {" + Environment.NewLine +
" $foreach (var v in args) {" + Environment.NewLine +
" Console.WriteLine (v);" + Environment.NewLine +
" }" + Environment.NewLine +
" }" + Environment.NewLine +
"}"
);
Assert.AreEqual (
"using System;" + Environment.NewLine +
"using System.Collections.Generic;" + Environment.NewLine +
"class TestClass" + Environment.NewLine +
"{" + Environment.NewLine +
" void Test (List<string> args)" + Environment.NewLine +
" {" + Environment.NewLine +
" for (int i = 0; i < args.Count; i++) {" + Environment.NewLine +
" var v = args [i];" + Environment.NewLine +
" Console.WriteLine (v);" + Environment.NewLine +
" }" + Environment.NewLine +
" }" + Environment.NewLine +
"}", result);
}
}
}

62
ICSharpCode.NRefactory.Tests/CSharp/ContextAction/ConvertHexToDecTests.cs

@ -0,0 +1,62 @@ @@ -0,0 +1,62 @@
//
// ConvertHexToDecTests.cs
//
// Author:
// Mike Krüger <mkrueger@xamarin.com>
//
// Copyright (c) 2012 Xamarin Inc.
//
// 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 ICSharpCode.NRefactory.CSharp.Refactoring;
namespace ICSharpCode.NRefactory.CSharp.ContextActions
{
[TestFixture]
public class ConvertHexToDecTests : ContextActionTestBase
{
[Test()]
public void Test ()
{
string result = RunContextAction (
new ConvertHexToDec (),
"using System;" + Environment.NewLine +
"class TestClass" + Environment.NewLine +
"{" + Environment.NewLine +
" void Test ()" + Environment.NewLine +
" {" + Environment.NewLine +
" int i = $0x10;" + Environment.NewLine +
" }" + Environment.NewLine +
"}"
);
Assert.AreEqual (
"using System;" + Environment.NewLine +
"class TestClass" + Environment.NewLine +
"{" + Environment.NewLine +
" void Test ()" + Environment.NewLine +
" {" + Environment.NewLine +
" int i = 16;" + Environment.NewLine +
" }" + Environment.NewLine +
"}", result);
}
}
}

64
ICSharpCode.NRefactory.Tests/CSharp/ContextAction/FlipOperatorArgumentsTests.cs

@ -0,0 +1,64 @@ @@ -0,0 +1,64 @@
//
// FlipOperatorArgumentsTests.cs
//
// Author:
// Mike Krüger <mkrueger@xamarin.com>
//
// Copyright (c) 2012 Xamarin Inc.
//
// 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 ICSharpCode.NRefactory.CSharp.Refactoring;
namespace ICSharpCode.NRefactory.CSharp.ContextActions
{
[TestFixture]
public class FlipOperatorArgumentsTests : ContextActionTestBase
{
[Test()]
public void Test ()
{
string result = RunContextAction (
new FlipOperatorArguments (),
"using System;" + Environment.NewLine +
"class TestClass" + Environment.NewLine +
"{" + Environment.NewLine +
" void Test ()" + Environment.NewLine +
" {" + Environment.NewLine +
" if (a $!= b)" + Environment.NewLine +
" ;" + Environment.NewLine +
" }" + Environment.NewLine +
"}"
);
Assert.AreEqual (
"using System;" + Environment.NewLine +
"class TestClass" + Environment.NewLine +
"{" + Environment.NewLine +
" void Test ()" + Environment.NewLine +
" {" + Environment.NewLine +
" if (b != a)" + Environment.NewLine +
" ;" + Environment.NewLine +
" }" + Environment.NewLine +
"}", result);
}
}
}

62
ICSharpCode.NRefactory.Tests/CSharp/ContextAction/GenerateGetterTests.cs

@ -0,0 +1,62 @@ @@ -0,0 +1,62 @@
//
// GenerateGetterTests.cs
//
// Author:
// Mike Krüger <mkrueger@xamarin.com>
//
// Copyright (c) 2012 Xamarin Inc.
//
// 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 ICSharpCode.NRefactory.CSharp.Refactoring;
namespace ICSharpCode.NRefactory.CSharp.ContextActions
{
[TestFixture]
public class GenerateGetterTests : ContextActionTestBase
{
[Ignore("Insert with cursor is not implemented.")]
[Test()]
public void Test ()
{
string result = RunContextAction (
new GenerateGetter (),
"using System;" + Environment.NewLine +
"class TestClass" + Environment.NewLine +
"{" + Environment.NewLine +
" int $myField;" + Environment.NewLine +
"}"
);
Assert.AreEqual (
"using System;" + Environment.NewLine +
"class TestClass" + Environment.NewLine +
"{" + Environment.NewLine +
" int myField;" + Environment.NewLine +
" public int MyField {" + Environment.NewLine +
" get {" + Environment.NewLine +
" return myFileld;" + Environment.NewLine +
" }" + Environment.NewLine +
" }" + Environment.NewLine +
"}", result);
}
}
}

72
ICSharpCode.NRefactory.Tests/CSharp/ContextAction/GenerateSwitchLabelsTests.cs

@ -0,0 +1,72 @@ @@ -0,0 +1,72 @@
//
// GenerateSwitchLabelsTests.cs
//
// Author:
// Mike Krüger <mkrueger@xamarin.com>
//
// Copyright (c) 2012 Xamarin Inc.
//
// 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 ICSharpCode.NRefactory.CSharp.Refactoring;
namespace ICSharpCode.NRefactory.CSharp.ContextActions
{
[TestFixture]
public class GenerateSwitchLabelsTests : ContextActionTestBase
{
[Test()]
public void Test ()
{
string result = RunContextAction (
new GenerateSwitchLabels (),
"using System;" + Environment.NewLine +
"class TestClass" + Environment.NewLine +
"{" + Environment.NewLine +
" void Test (ConsoleModifiers mods)" + Environment.NewLine +
" {" + Environment.NewLine +
" $switch (mods) {" + Environment.NewLine +
" }" + Environment.NewLine +
" }" + Environment.NewLine +
"}"
);
Assert.AreEqual (
"using System;" + Environment.NewLine +
"class TestClass" + Environment.NewLine +
"{" + Environment.NewLine +
" void Test (ConsoleModifiers mods)" + Environment.NewLine +
" {" + Environment.NewLine +
" switch (mods) {" + Environment.NewLine +
" case ConsoleModifiers.Alt:" + Environment.NewLine +
" break;" + Environment.NewLine +
" case ConsoleModifiers.Shift:" + Environment.NewLine +
" break;" + Environment.NewLine +
" case ConsoleModifiers.Control:" + Environment.NewLine +
" break;" + Environment.NewLine +
" default:" + Environment.NewLine +
" throw new ArgumentOutOfRangeException ();" + Environment.NewLine +
" }" + Environment.NewLine +
" }" + Environment.NewLine +
"}", result);
}
}
}

65
ICSharpCode.NRefactory.Tests/CSharp/ContextAction/InsertAnonymousMethodSignatureTests.cs

@ -0,0 +1,65 @@ @@ -0,0 +1,65 @@
//
// InsertAnonymousMethodSignatureTests.cs
//
// Author:
// Mike Krüger <mkrueger@xamarin.com>
//
// Copyright (c) 2012 Xamarin Inc.
//
// 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 ICSharpCode.NRefactory.CSharp.Refactoring;
namespace ICSharpCode.NRefactory.CSharp.ContextActions
{
[TestFixture]
public class InsertAnonymousMethodSignatureTests : ContextActionTestBase
{
[Test()]
public void Test ()
{
string result = RunContextAction (
new InsertAnonymousMethodSignature (),
"using System;" + Environment.NewLine +
"class TestClass" + Environment.NewLine +
"{" + Environment.NewLine +
" void Test ()" + Environment.NewLine +
" {" + Environment.NewLine +
" EventHandler handler = $delegate {" + Environment.NewLine +
" };" + Environment.NewLine +
" }" + Environment.NewLine +
"}"
);
Assert.AreEqual (
"using System;" + Environment.NewLine +
"class TestClass" + Environment.NewLine +
"{" + Environment.NewLine +
" void Test ()" + Environment.NewLine +
" {" + Environment.NewLine +
" EventHandler handler = delegate(object sender, EventArgs e) {" + Environment.NewLine +
" };" + Environment.NewLine +
" }" + Environment.NewLine +
"}", result);
}
}
}

85
ICSharpCode.NRefactory.Tests/CSharp/ContextAction/IntroduceFormatItemTests.cs

@ -0,0 +1,85 @@ @@ -0,0 +1,85 @@
//
// IntroduceFormatItemTests.cs
//
// Author:
// Mike Krüger <mkrueger@xamarin.com>
//
// Copyright (c) 2012 Xamarin Inc.
//
// 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 ICSharpCode.NRefactory.CSharp.Refactoring;
namespace ICSharpCode.NRefactory.CSharp.ContextActions
{
[TestFixture]
public class IntroduceFormatItemTests : ContextActionTestBase
{
[Test()]
public void TestFirst ()
{
string result = RunContextAction (
new IntroduceFormatItem (),
"class TestClass" + Environment.NewLine +
"{" + Environment.NewLine +
" void Test ()" + Environment.NewLine +
" {" + Environment.NewLine +
" string str = \"Hello <-World->!\";" + Environment.NewLine +
" }" + Environment.NewLine +
"}"
);
Assert.AreEqual (
"class TestClass" + Environment.NewLine +
"{" + Environment.NewLine +
" void Test ()" + Environment.NewLine +
" {" + Environment.NewLine +
" string str = string.Format (\"Hello {0}!\", \"World\");" + Environment.NewLine +
" }" + Environment.NewLine +
"}", result);
}
[Test()]
public void TestSecond ()
{
string result = RunContextAction (
new IntroduceFormatItem (),
"class TestClass" + Environment.NewLine +
"{" + Environment.NewLine +
" void Test ()" + Environment.NewLine +
" {" + Environment.NewLine +
" string str = string.Format (\"<-Hello-> {0}!\", \"World\");" + Environment.NewLine +
" }" + Environment.NewLine +
"}"
);
Assert.AreEqual (
"class TestClass" + Environment.NewLine +
"{" + Environment.NewLine +
" void Test ()" + Environment.NewLine +
" {" + Environment.NewLine +
" string str = string.Format (\"{1} {0}!\", \"World\", \"Hello\");" + Environment.NewLine +
" }" + Environment.NewLine +
"}", result);
}
}
}

69
ICSharpCode.NRefactory.Tests/CSharp/ContextAction/InvertIfTests.cs

@ -0,0 +1,69 @@ @@ -0,0 +1,69 @@
//
// InvertIfTests.cs
//
// Author:
// Mike Krüger <mkrueger@xamarin.com>
//
// Copyright (c) 2012 Xamarin Inc.
//
// 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 ICSharpCode.NRefactory.CSharp.Refactoring;
namespace ICSharpCode.NRefactory.CSharp.ContextActions
{
[TestFixture]
public class InvertIfTestsTests : ContextActionTestBase
{
[Ignore("Formatting not implemented in test context")]
[Test()]
public void Test ()
{
string result = RunContextAction (
new InvertIf (),
"class TestClass" + Environment.NewLine +
"{" + Environment.NewLine +
" void Test ()" + Environment.NewLine +
" {" + Environment.NewLine +
" $if (true) {" + Environment.NewLine +
" Case1 ();" + Environment.NewLine +
" } else {" + Environment.NewLine +
" Case2 ();" + Environment.NewLine +
" }" + Environment.NewLine +
" }" + Environment.NewLine +
"}"
);
Assert.AreEqual (
"class TestClass" + Environment.NewLine +
"{" + Environment.NewLine +
" void Test ()" + Environment.NewLine +
" {" + Environment.NewLine +
" if (false) {" + Environment.NewLine +
" Case2 ();" + Environment.NewLine +
" } else {" + Environment.NewLine +
" Case1 ();" + Environment.NewLine +
" }" + Environment.NewLine +
" }" + Environment.NewLine +
"}", result);
}
}
}

62
ICSharpCode.NRefactory.Tests/CSharp/ContextAction/RemoveBackingStoreTests.cs

@ -0,0 +1,62 @@ @@ -0,0 +1,62 @@
//
// RemoveBackingStoreTests.cs
//
// Author:
// Mike Krüger <mkrueger@xamarin.com>
//
// Copyright (c) 2012 Xamarin Inc.
//
// 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 ICSharpCode.NRefactory.CSharp.Refactoring;
namespace ICSharpCode.NRefactory.CSharp.ContextActions
{
[TestFixture]
public class RemoveBackingStoreTests : ContextActionTestBase
{
[Test()]
public void Test ()
{
string result = RunContextAction (
new RemoveBackingStore (),
"class TestClass" + Environment.NewLine +
"{" + Environment.NewLine +
" int field;" + Environment.NewLine +
" public int $Field {" + Environment.NewLine +
" get { return field; }" + Environment.NewLine +
" set { field = value; }" + Environment.NewLine +
" }" + Environment.NewLine +
"}"
);
Assert.AreEqual (
"class TestClass" + Environment.NewLine +
"{" + Environment.NewLine +
" " + Environment.NewLine +
" public int Field {" + Environment.NewLine +
" get;" + Environment.NewLine +
" set;" + Environment.NewLine +
" }" + Environment.NewLine +
"}", result);
}
}
}

63
ICSharpCode.NRefactory.Tests/CSharp/ContextAction/RemoveBracesTests.cs

@ -0,0 +1,63 @@ @@ -0,0 +1,63 @@
//
// RemoveBracesTests.cs
//
// Author:
// Mike Krüger <mkrueger@xamarin.com>
//
// Copyright (c) 2012 Xamarin Inc.
//
// 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 ICSharpCode.NRefactory.CSharp.Refactoring;
namespace ICSharpCode.NRefactory.CSharp.ContextActions
{
[TestFixture]
public class RemoveBracesTests : ContextActionTestBase
{
[Ignore("Formatting not implemented in test context")]
[Test()]
public void TestSimpleBraces ()
{
string result = RunContextAction (
new RemoveBraces (),
"class TestClass" + Environment.NewLine +
"{" + Environment.NewLine +
" void Test ()" + Environment.NewLine +
" {" + Environment.NewLine +
" if (true) ${" + Environment.NewLine +
" ;" + Environment.NewLine +
" }" + Environment.NewLine +
" }" + Environment.NewLine +
"}"
);
Assert.AreEqual (
"class TestClass" + Environment.NewLine +
"{" + Environment.NewLine +
" void Test ()" + Environment.NewLine +
" {" + Environment.NewLine +
" ;" + Environment.NewLine +
" }" + Environment.NewLine +
"}", result);
}
}
}

60
ICSharpCode.NRefactory.Tests/CSharp/ContextAction/ReplaceEmptyStringTests.cs

@ -0,0 +1,60 @@ @@ -0,0 +1,60 @@
//
// ReplaceEmptyStringTests.cs
//
// Author:
// Mike Krüger <mkrueger@xamarin.com>
//
// Copyright (c) 2012 Xamarin Inc.
//
// 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 ICSharpCode.NRefactory.CSharp.Refactoring;
namespace ICSharpCode.NRefactory.CSharp.ContextActions
{
[TestFixture]
public class ReplaceEmptyStringTests : ContextActionTestBase
{
[Test()]
public void TestSimpleString()
{
string result = RunContextAction (
new ReplaceEmptyString (),
"class TestClass" + Environment.NewLine +
"{" + Environment.NewLine +
" void Test ()" + Environment.NewLine +
" {" + Environment.NewLine +
" string str = $\"\";" + Environment.NewLine +
" }" + Environment.NewLine +
"}"
);
Assert.AreEqual (
"class TestClass" + Environment.NewLine +
"{" + Environment.NewLine +
" void Test ()" + Environment.NewLine +
" {" + Environment.NewLine +
" string str = string.Empty;" + Environment.NewLine +
" }" + Environment.NewLine +
"}", result);
}
}
}

24
ICSharpCode.NRefactory.Tests/CSharp/ContextAction/SplitDeclarationAndAssignmentTests.cs

@ -80,6 +80,30 @@ namespace ICSharpCode.NRefactory.CSharp.ContextActions @@ -80,6 +80,30 @@ namespace ICSharpCode.NRefactory.CSharp.ContextActions
" }" + Environment.NewLine +
"}", result);
}
[Test()]
public void TestForStatement ()
{
string result = RunContextAction (
new SplitDeclarationAndAssignment (),
"class TestClass" + Environment.NewLine +
"{" + Environment.NewLine +
" void Test ()" + Environment.NewLine +
" {" + Environment.NewLine +
" for (int $i = 1; i < 10; i++) {}" + Environment.NewLine +
" }" + Environment.NewLine +
"}"
);
Assert.AreEqual (
"class TestClass" + Environment.NewLine +
"{" + Environment.NewLine +
" void Test ()" + Environment.NewLine +
" {" + Environment.NewLine +
" int i;" + Environment.NewLine +
" for (i = 1; i < 10; i++) {}" + Environment.NewLine +
" }" + Environment.NewLine +
"}", result);
}
}
}

84
ICSharpCode.NRefactory.Tests/CSharp/ContextAction/SplitStringTests.cs

@ -0,0 +1,84 @@ @@ -0,0 +1,84 @@
//
// SplitStringTests.cs
//
// Author:
// Mike Krüger <mkrueger@xamarin.com>
//
// Copyright (c) 2012 Xamarin Inc.
//
// 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 ICSharpCode.NRefactory.CSharp.Refactoring;
namespace ICSharpCode.NRefactory.CSharp.ContextActions
{
[TestFixture]
public class SplitStringTests : ContextActionTestBase
{
[Test()]
public void TestSimpleString ()
{
string result = RunContextAction (
new SplitString (),
"class TestClass" + Environment.NewLine +
"{" + Environment.NewLine +
" void Test ()" + Environment.NewLine +
" {" + Environment.NewLine +
" System.Console.WriteLine (\"Hello$World\");" + Environment.NewLine +
" }" + Environment.NewLine +
"}"
);
Assert.AreEqual (
"class TestClass" + Environment.NewLine +
"{" + Environment.NewLine +
" void Test ()" + Environment.NewLine +
" {" + Environment.NewLine +
" System.Console.WriteLine (\"Hello\" + \"World\");" + Environment.NewLine +
" }" + Environment.NewLine +
"}", result);
}
[Test()]
public void TestVerbatimString ()
{
string result = RunContextAction (
new SplitString (),
"class TestClass" + Environment.NewLine +
"{" + Environment.NewLine +
" void Test ()" + Environment.NewLine +
" {" + Environment.NewLine +
" System.Console.WriteLine (@\"Hello$World\");" + Environment.NewLine +
" }" + Environment.NewLine +
"}"
);
Assert.AreEqual (
"class TestClass" + Environment.NewLine +
"{" + Environment.NewLine +
" void Test ()" + Environment.NewLine +
" {" + Environment.NewLine +
" System.Console.WriteLine (@\"Hello\" + @\"World\");" + Environment.NewLine +
" }" + Environment.NewLine +
"}", result);
}
}
}

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

@ -42,7 +42,6 @@ namespace ICSharpCode.NRefactory.CSharp.ContextActions @@ -42,7 +42,6 @@ namespace ICSharpCode.NRefactory.CSharp.ContextActions
{
internal IDocument doc;
CSharpParsedFile parsedFile;
ICompilation compilation;
CSharpAstResolver resolver;
public override bool HasCSharp3Support {
@ -68,8 +67,9 @@ namespace ICSharpCode.NRefactory.CSharp.ContextActions @@ -68,8 +67,9 @@ namespace ICSharpCode.NRefactory.CSharp.ContextActions
public override void ReplaceReferences (IMember member, MemberDeclaration replaceWidth)
{
throw new NotImplementedException ();
// throw new NotImplementedException ();
}
class MyScript : Script
{
TestRefactoringContext trc;
@ -81,7 +81,7 @@ namespace ICSharpCode.NRefactory.CSharp.ContextActions @@ -81,7 +81,7 @@ namespace ICSharpCode.NRefactory.CSharp.ContextActions
public override void Dispose ()
{
trc.doc = new ReadOnlyDocument (TestBase.ApplyChanges (trc.doc.Text, new List<TextReplaceAction> (Actions.Cast<TextReplaceAction>())));
trc.doc = new ReadOnlyDocument (TestBase.ApplyChanges (trc.doc.Text, new List<TextReplaceAction> (Actions.Where (act => act is TextReplaceAction).Cast<TextReplaceAction>())));
}
public override void InsertWithCursor (string operation, AstNode node, InsertPosition defaultPosition)
@ -97,7 +97,7 @@ namespace ICSharpCode.NRefactory.CSharp.ContextActions @@ -97,7 +97,7 @@ namespace ICSharpCode.NRefactory.CSharp.ContextActions
#region Text stuff
public override string EolMarker { get { return Environment.NewLine; } }
public override bool IsSomethingSelected { get { return SelectionStart >= 0; } }
public override bool IsSomethingSelected { get { return SelectionStart > 0; } }
public override string SelectedText { get { return IsSomethingSelected ? doc.GetText (SelectionStart, SelectionLength) : ""; } }
@ -139,6 +139,16 @@ namespace ICSharpCode.NRefactory.CSharp.ContextActions @@ -139,6 +139,16 @@ namespace ICSharpCode.NRefactory.CSharp.ContextActions
int idx = content.IndexOf ("$");
if (idx >= 0)
content = content.Substring (0, idx) + content.Substring (idx + 1);
int idx1 = content.IndexOf ("<-");
int idx2 = content.IndexOf ("->");
if (0 <= idx1 && idx1 < idx2) {
content = content.Substring (0, idx2) + content.Substring (idx2 + 2);
content = content.Substring (0, idx1) + content.Substring (idx1 + 2);
selectionStart = idx1;
idx = selectionEnd = idx2 - 2;
}
doc = new ReadOnlyDocument (content);
var parser = new CSharpParser ();
Unit = parser.Parse (content, "program.cs");
@ -151,8 +161,8 @@ namespace ICSharpCode.NRefactory.CSharp.ContextActions @@ -151,8 +161,8 @@ namespace ICSharpCode.NRefactory.CSharp.ContextActions
pc = pc.UpdateProjectContent(null, parsedFile);
pc = pc.AddAssemblyReferences(new[] { CecilLoaderTests.Mscorlib, CecilLoaderTests.SystemCore });
compilation = pc.CreateCompilation();
resolver = new CSharpAstResolver(compilation, Unit, parsedFile);
Compilation = pc.CreateCompilation();
resolver = new CSharpAstResolver(Compilation, Unit, parsedFile);
if (idx >= 0)
Location = doc.GetLocation (idx);
}
@ -176,7 +186,7 @@ namespace ICSharpCode.NRefactory.CSharp.ContextActions @@ -176,7 +186,7 @@ namespace ICSharpCode.NRefactory.CSharp.ContextActions
public override NodeSelectionAction CreateNodeSelectionAction (AstNode node)
{
throw new NotImplementedException ();
return new TestNodeSelectAction (node);
}
public override FormatTextAction CreateFormatTextAction (Func<RefactoringContext, AstNode> callback)
@ -186,7 +196,27 @@ namespace ICSharpCode.NRefactory.CSharp.ContextActions @@ -186,7 +196,27 @@ namespace ICSharpCode.NRefactory.CSharp.ContextActions
public override CreateLinkAction CreateLinkAction (IEnumerable<AstNode> linkedNodes)
{
throw new NotImplementedException ();
return new TestNodeLinkAction (linkedNodes);
}
class TestNodeLinkAction : CreateLinkAction
{
public TestNodeLinkAction (IEnumerable<AstNode> linkedNodes) : base (linkedNodes)
{
}
public override void Perform (Script script)
{
}
}
class TestNodeSelectAction : NodeSelectionAction
{
public TestNodeSelectAction (AstNode astNode) : base (astNode)
{
}
public override void Perform (Script script)
{
}
}
public class TestNodeOutputAction : NodeOutputAction

24
ICSharpCode.NRefactory.Tests/ICSharpCode.NRefactory.Tests.csproj

@ -208,6 +208,21 @@ @@ -208,6 +208,21 @@
<Compile Include="CSharp\CodeCompletion\VariableDeclarationStatementTests.cs" />
<Compile Include="CSharp\CodeCompletion\NameContextTests.cs" />
<Compile Include="CSharp\ContextAction\SplitDeclarationAndAssignmentTests.cs" />
<Compile Include="CSharp\ContextAction\SplitStringTests.cs" />
<Compile Include="CSharp\ContextAction\ReplaceEmptyStringTests.cs" />
<Compile Include="CSharp\ContextAction\RemoveBracesTests.cs" />
<Compile Include="CSharp\ContextAction\RemoveBackingStoreTests.cs" />
<Compile Include="CSharp\ContextAction\InvertIfTests.cs" />
<Compile Include="CSharp\ContextAction\IntroduceFormatItemTests.cs" />
<Compile Include="CSharp\ContextAction\InsertAnonymousMethodSignatureTests.cs" />
<Compile Include="CSharp\ContextAction\GenerateSwitchLabelsTests.cs" />
<Compile Include="CSharp\ContextAction\GenerateGetterTests.cs" />
<Compile Include="CSharp\ContextAction\FlipOperatorArgumentsTests.cs" />
<Compile Include="CSharp\ContextAction\ConvertHexToDecTests.cs" />
<Compile Include="CSharp\ContextAction\ConvertDecToHexTests.cs" />
<Compile Include="CSharp\ContextAction\CheckIfParameterIsNullTests.cs" />
<Compile Include="CSharp\ContextAction\ConvertForeachToForTests.cs" />
<Compile Include="CSharp\ContextAction\AddAnotherAccessorTests.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\ICSharpCode.NRefactory.CSharp\ICSharpCode.NRefactory.CSharp.csproj">
@ -227,4 +242,13 @@ @@ -227,4 +242,13 @@
<Folder Include="CSharp\ContextAction\" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ProjectExtensions>
<MonoDevelop>
<Properties>
<Policies>
<TextStylePolicy TabWidth="4" EolMarker="Unix" inheritsSet="Mono" inheritsScope="text/plain" scope="text/plain" />
</Policies>
</Properties>
</MonoDevelop>
</ProjectExtensions>
</Project>
Loading…
Cancel
Save