diff options
author | Mike Krüger <mkrueger@novell.com> | 2009-08-31 16:14:53 +0400 |
---|---|---|
committer | Mike Krüger <mkrueger@novell.com> | 2009-08-31 16:14:53 +0400 |
commit | f8a20c783c314d816828ccbdb3c762a3e890e736 (patch) | |
tree | 59b15345a44f50ecce5e48fe662a0fe9e355fde0 /main/tests | |
parent | 811259f9fe614286d9d7a0faef6207d6dd323b8c (diff) |
* Makefile.am:
* UnitTests.csproj:
* MonoDevelop.Refactoring/DeclareLocalTests.cs:
* MonoDevelop.CSharpBinding/TestViewContent.cs:
* MonoDevelop.Refactoring/ExtractMethodTests.cs:
* MonoDevelop.Refactoring/IntegrateTemporaryVariableTests.cs:
* MonoDevelop.Refactoring/IntroduceConstantRefactoringTests.cs:
* MonoDevelop.Refactoring/IntroduceFormatItemRefactoringTests.cs:
Added some refactoring unit tests.
svn path=/trunk/monodevelop/; revision=140961
Diffstat (limited to 'main/tests')
9 files changed, 324 insertions, 7 deletions
diff --git a/main/tests/UnitTests/ChangeLog b/main/tests/UnitTests/ChangeLog index 0aad385aa8..db7ba45142 100644 --- a/main/tests/UnitTests/ChangeLog +++ b/main/tests/UnitTests/ChangeLog @@ -2,6 +2,18 @@ * Makefile.am: * UnitTests.csproj: + * MonoDevelop.Refactoring/DeclareLocalTests.cs: + * MonoDevelop.CSharpBinding/TestViewContent.cs: + * MonoDevelop.Refactoring/ExtractMethodTests.cs: + * MonoDevelop.Refactoring/IntegrateTemporaryVariableTests.cs: + * MonoDevelop.Refactoring/IntroduceConstantRefactoringTests.cs: + * MonoDevelop.Refactoring/IntroduceFormatItemRefactoringTests.cs: + Added some refactoring unit tests. + +2009-08-31 Mike Krüger <mkrueger@novell.com> + + * Makefile.am: + * UnitTests.csproj: * MonoDevelop.Refactoring/ExtractMethodTests.cs: * MonoDevelop.Refactoring/CreateBackingStoreTests.cs: * MonoDevelop.Refactoring/RemoveBackingStoreTests.cs: Worked diff --git a/main/tests/UnitTests/Makefile.am b/main/tests/UnitTests/Makefile.am index d6c3832e32..cea91c8515 100644 --- a/main/tests/UnitTests/Makefile.am +++ b/main/tests/UnitTests/Makefile.am @@ -74,7 +74,11 @@ FILES = \ MonoDevelop.Projects/TextFormatterTests.cs \ MonoDevelop.Projects/WorkspaceTests.cs \ MonoDevelop.Refactoring/CreateBackingStoreTests.cs \ + MonoDevelop.Refactoring/DeclareLocalTests.cs \ MonoDevelop.Refactoring/ExtractMethodTests.cs \ + MonoDevelop.Refactoring/IntegrateTemporaryVariableTests.cs \ + MonoDevelop.Refactoring/IntroduceConstantRefactoringTests.cs \ + MonoDevelop.Refactoring/IntroduceFormatItemRefactoringTests.cs \ MonoDevelop.Refactoring/RemoveBackingStoreTests.cs \ MonoDevelop.Xml.StateEngine/AspNetParsingTests.cs \ MonoDevelop.Xml.StateEngine/HtmlParsingTests.cs \ diff --git a/main/tests/UnitTests/MonoDevelop.CSharpBinding/TestViewContent.cs b/main/tests/UnitTests/MonoDevelop.CSharpBinding/TestViewContent.cs index b7e65fa43a..065347f9bc 100644 --- a/main/tests/UnitTests/MonoDevelop.CSharpBinding/TestViewContent.cs +++ b/main/tests/UnitTests/MonoDevelop.CSharpBinding/TestViewContent.cs @@ -115,13 +115,13 @@ namespace MonoDevelop.CSharpBinding.Tests }
public string SelectedText { get { return ""; } set { } } - int cursorPosition = 0; +
public int CursorPosition {
get {
- return cursorPosition;
+ return data.Caret.Offset;
}
set {
- cursorPosition = value;
+ data.Caret.Offset = value;
}
} diff --git a/main/tests/UnitTests/MonoDevelop.Refactoring/DeclareLocalTests.cs b/main/tests/UnitTests/MonoDevelop.Refactoring/DeclareLocalTests.cs new file mode 100644 index 0000000000..22418299cc --- /dev/null +++ b/main/tests/UnitTests/MonoDevelop.Refactoring/DeclareLocalTests.cs @@ -0,0 +1,67 @@ +// +// DeclareLocalTests.cs +// +// Author: +// Mike Krüger <mkrueger@novell.com> +// +// Copyright (c) 2009 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.Refactoring; +using MonoDevelop.Refactoring.DeclareLocal; +using System.Collections.Generic; + +namespace MonoDevelop.Refactoring.Tests +{ + [TestFixture()] + public class DeclareLocalTests : UnitTests.TestBase + { + void TestDeclareLocal (string inputString, string outputString) + { + DeclareLocalCodeGenerator refactoring = new DeclareLocalCodeGenerator (); + RefactoringOptions options = ExtractMethodTests.CreateRefactoringOptions (inputString); + List<Change> changes = refactoring.PerformChanges (options, null); + string output = ExtractMethodTests.GetOutput (options, changes); + Assert.IsTrue (ExtractMethodTests.CompareSource (output, outputString), "Expected:" + Environment.NewLine + outputString + Environment.NewLine + "was:" + Environment.NewLine + output); + } + + [Test()] + public void CreateBackingStoreTest () + { + TestDeclareLocal (@"class TestClass +{ + void Test () + { + $345 + } +} +", @"class TestClass +{ + void Test () + { + int aInt32 = 345; + } +} +"); + } + } +} diff --git a/main/tests/UnitTests/MonoDevelop.Refactoring/ExtractMethodTests.cs b/main/tests/UnitTests/MonoDevelop.Refactoring/ExtractMethodTests.cs index a8d225df26..d5bf947a9f 100644 --- a/main/tests/UnitTests/MonoDevelop.Refactoring/ExtractMethodTests.cs +++ b/main/tests/UnitTests/MonoDevelop.Refactoring/ExtractMethodTests.cs @@ -97,10 +97,10 @@ namespace MonoDevelop.Refactoring.Tests doc.ParsedDocument = new NRefactoryParser ().Parse (null, sev.ContentName, parsedText); foreach (var e in doc.ParsedDocument.Errors) Console.WriteLine (e); - - if (selectionStart >= 0) { + if (cursorPosition >= 0) + doc.TextEditor.CursorPosition = cursorPosition; + if (selectionStart >= 0) doc.TextEditor.Select (selectionStart, selectionEnd); - } NRefactoryResolver resolver = new NRefactoryResolver (dom, doc.ParsedDocument.CompilationUnit, @@ -108,13 +108,18 @@ namespace MonoDevelop.Refactoring.Tests "a.cs"); ResolveResult resolveResult = endPos >= 0 ? resolver.Resolve (new NewCSharpExpressionFinder (dom).FindFullExpression (editorText, cursorPosition + 1), new DomLocation (doc.TextEditor.CursorLine, doc .TextEditor.CursorColumn)) : null; - Console.WriteLine ("RR:" + resolveResult); RefactoringOptions result = new RefactoringOptions { Document = doc, Dom = dom, ResolveResult = resolveResult, SelectedItem = null }; + if (resolveResult is MemberResolveResult) + result.SelectedItem = ((MemberResolveResult)resolveResult).ResolvedMember; + if (resolveResult is LocalVariableResolveResult) + result.SelectedItem = ((LocalVariableResolveResult)resolveResult).LocalVariable; + if (resolveResult is ParameterResolveResult) + result.SelectedItem = ((ParameterResolveResult)resolveResult).Parameter; result.TestFileProvider = new FileProvider (result); return result; } @@ -292,3 +297,4 @@ namespace MonoDevelop.Refactoring.Tests } } +
\ No newline at end of file diff --git a/main/tests/UnitTests/MonoDevelop.Refactoring/IntegrateTemporaryVariableTests.cs b/main/tests/UnitTests/MonoDevelop.Refactoring/IntegrateTemporaryVariableTests.cs new file mode 100644 index 0000000000..a097ad3dcc --- /dev/null +++ b/main/tests/UnitTests/MonoDevelop.Refactoring/IntegrateTemporaryVariableTests.cs @@ -0,0 +1,67 @@ +// +// IntegrateTemporaryVariableTests.cs +// +// Author: +// Mike Krüger <mkrueger@novell.com> +// +// Copyright (c) 2009 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.Refactoring; +using System.Collections.Generic; +using MonoDevelop.Refactoring.IntegrateTemporaryVariable; + +namespace MonoDevelop.Refactoring.Tests +{ + [TestFixture()] + public class IntegrateTemporaryVariableTests : UnitTests.TestBase + { + void TestIntegrateTemporaryVariable (string inputString, string outputString) + { + IntegrateTemporaryVariableRefactoring refactoring = new IntegrateTemporaryVariableRefactoring (); + RefactoringOptions options = ExtractMethodTests.CreateRefactoringOptions (inputString); + List<Change> changes = refactoring.PerformChanges (options, null); + string output = ExtractMethodTests.GetOutput (options, changes); + Assert.IsTrue (ExtractMethodTests.CompareSource (output, outputString), "Expected:" + Environment.NewLine + outputString + Environment.NewLine + "was:" + Environment.NewLine + output); + } + + [Test()] + public void IntegrateTemporaryVariableTest () + { + TestIntegrateTemporaryVariable (@"class TestClass +{ + void Test () + { + int $tmp = 5 + 6; + Console.WriteLine (tmp); + } +} +", @"class TestClass +{ + void Test () + { + Console.WriteLine (5 + 6); + } +}"); + } + } +} diff --git a/main/tests/UnitTests/MonoDevelop.Refactoring/IntroduceConstantRefactoringTests.cs b/main/tests/UnitTests/MonoDevelop.Refactoring/IntroduceConstantRefactoringTests.cs new file mode 100644 index 0000000000..553e2f4141 --- /dev/null +++ b/main/tests/UnitTests/MonoDevelop.Refactoring/IntroduceConstantRefactoringTests.cs @@ -0,0 +1,71 @@ +// +// IntroduceConstantRefactoringTests.cs +// +// Author: +// Mike Krüger <mkrueger@novell.com> +// +// Copyright (c) 2009 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.Refactoring; +using System.Collections.Generic; +using MonoDevelop.Refactoring.IntroduceConstant; + +namespace MonoDevelop.Refactoring.Tests +{ + [TestFixture()] + public class IntroduceConstantRefactoringTests : UnitTests.TestBase + { + void TestIntroduceConstantRefactoring (string inputString, string outputString) + { + IntroduceConstantRefactoring refactoring = new IntroduceConstantRefactoring (); + RefactoringOptions options = ExtractMethodTests.CreateRefactoringOptions (inputString); + IntroduceConstantRefactoring.Parameters param = new IntroduceConstantRefactoring.Parameters () { + Name = "magic" + }; + List<Change> changes = refactoring.PerformChanges (options, param); + string output = ExtractMethodTests.GetOutput (options, changes); + Assert.IsTrue (ExtractMethodTests.CompareSource (output, outputString), "Expected:" + Environment.NewLine + outputString + Environment.NewLine + "was:" + Environment.NewLine + output); + } + + [Test()] + public void IntroduceConstantRefactoringTest () + { + TestIntroduceConstantRefactoring (@"class TestClass +{ + void Test () + { + Console.WriteLine ($5564); + } +} +", @"class TestClass +{ + const int magic = 5564; + + void Test () + { + Console.WriteLine (magic); + } +}"); + } + } +} diff --git a/main/tests/UnitTests/MonoDevelop.Refactoring/IntroduceFormatItemRefactoringTests.cs b/main/tests/UnitTests/MonoDevelop.Refactoring/IntroduceFormatItemRefactoringTests.cs new file mode 100644 index 0000000000..5c26bbefeb --- /dev/null +++ b/main/tests/UnitTests/MonoDevelop.Refactoring/IntroduceFormatItemRefactoringTests.cs @@ -0,0 +1,86 @@ +// +// IntroduceFormatItemRefactoring.cs +// +// Author: +// Mike Krüger <mkrueger@novell.com> +// +// Copyright (c) 2009 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.Refactoring; +using System.Collections.Generic; +using MonoDevelop.Refactoring.IntroduceFormat; + +namespace MonoDevelop.Refactoring.Tests +{ + [TestFixture()] + public class IntroduceFormatItemRefactoringTests : UnitTests.TestBase + { + void TestIntroduceFormatItemRefactoring (string inputString, string outputString) + { + IntroduceFormatItemRefactoring refactoring = new IntroduceFormatItemRefactoring (); + RefactoringOptions options = ExtractMethodTests.CreateRefactoringOptions (inputString); + List<Change> changes = refactoring.PerformChanges (options, null); + string output = ExtractMethodTests.GetOutput (options, changes); + Assert.IsTrue (ExtractMethodTests.CompareSource (output, outputString), "Expected:" + Environment.NewLine + outputString + Environment.NewLine + "was:" + Environment.NewLine + output); + } + + [Test()] + public void IntroduceFormatItemRefactoringSimpleTest () + { + TestIntroduceFormatItemRefactoring (@"class TestClass +{ + void Test () + { + Console.WriteLine (""Hello <-World->!""); + } +} +", @"class TestClass +{ + void Test () + { + Console.WriteLine (string.Format (""Hello {0}!"", ""World"")); + } +}"); + } + + [Test()] + public void IntroduceFormatItemRefactoringComplexTest () + { + TestIntroduceFormatItemRefactoring (@"class TestClass +{ + void Test () + { + Console.WriteLine (string.Format (""Hello {0}!. Here is a <-test->! "", ""World"")); + } +} +", @"class TestClass +{ + void Test () + { + Console.WriteLine (string.Format (""Hello {0}!. Here is a {1}! "", ""World"", ""test"")); + } +}"); + } + + } +} diff --git a/main/tests/UnitTests/UnitTests.csproj b/main/tests/UnitTests/UnitTests.csproj index 1a0eeefc5c..7d9b8cfbf3 100644 --- a/main/tests/UnitTests/UnitTests.csproj +++ b/main/tests/UnitTests/UnitTests.csproj @@ -195,6 +195,10 @@ <Compile Include="MonoDevelop.Refactoring\ExtractMethodTests.cs" /> <Compile Include="MonoDevelop.Refactoring\CreateBackingStoreTests.cs" /> <Compile Include="MonoDevelop.Refactoring\RemoveBackingStoreTests.cs" /> + <Compile Include="MonoDevelop.Refactoring\DeclareLocalTests.cs" /> + <Compile Include="MonoDevelop.Refactoring\IntegrateTemporaryVariableTests.cs" /> + <Compile Include="MonoDevelop.Refactoring\IntroduceConstantRefactoringTests.cs" /> + <Compile Include="MonoDevelop.Refactoring\IntroduceFormatItemRefactoringTests.cs" /> </ItemGroup> <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> <ProjectExtensions> |