From 0859a04a52c4ef5163859c712d5f70af582f3387 Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Sun, 31 Dec 2006 13:49:39 +0000 Subject: [PATCH] Move C# expression finder tests to SharpDevelop.Tests (the expression finder now is in SharpDevelop.Dom). Fixed a bug in the VB expression finder. git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/2.1@2239 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61 --- .../Test/CSharpBinding.Tests.csproj | 60 -------------- .../Project/Debugger.Core.csproj | 2 +- .../Base/Test/CSharpExpressionFinderTests.cs} | 7 +- .../ICSharpCode.SharpDevelop.Tests.csproj | 2 + src/Main/Base/Test/VBExpressionFinderTests.cs | 78 +++++++++++++++++++ .../Project/Src/VBNet/ExpressionFinder.cs | 6 +- src/SharpDevelop.Tests.sln | 6 +- 7 files changed, 91 insertions(+), 70 deletions(-) delete mode 100644 src/AddIns/BackendBindings/CSharpBinding/Test/CSharpBinding.Tests.csproj rename src/{AddIns/BackendBindings/CSharpBinding/Test/ExpressionFinder.cs => Main/Base/Test/CSharpExpressionFinderTests.cs} (97%) create mode 100644 src/Main/Base/Test/VBExpressionFinderTests.cs diff --git a/src/AddIns/BackendBindings/CSharpBinding/Test/CSharpBinding.Tests.csproj b/src/AddIns/BackendBindings/CSharpBinding/Test/CSharpBinding.Tests.csproj deleted file mode 100644 index b23231b595..0000000000 --- a/src/AddIns/BackendBindings/CSharpBinding/Test/CSharpBinding.Tests.csproj +++ /dev/null @@ -1,60 +0,0 @@ - - - Library - CSharpBinding.Tests - CSharpBinding.Tests - Debug - AnyCPU - {4D0DFCB0-F6FB-469D-AA6F-C7F1D5FD5DE7} - ..\..\..\..\..\bin\UnitTests\ - False - False - False - AnyCPU - 4 - false - - - False - DEBUG;TRACE - true - Full - True - - - True - TRACE - false - None - False - - - - - - - ..\..\..\..\Tools\NUnit\nunit.framework.dll - False - - - - - - - - {1F1AC7CD-D154-45BB-8EAF-804CA8055F5A} - CSharpBinding - True - - - {2748AD25-9C63-4E12-877B-4DCE96FBED54} - ICSharpCode.SharpDevelop - True - - - {924EE450-603D-49C1-A8E5-4AFAA31CE6F3} - ICSharpCode.SharpDevelop.Dom - - - - \ No newline at end of file diff --git a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Debugger.Core.csproj b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Debugger.Core.csproj index 08b7fdf96e..733ff8f3d0 100644 --- a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Debugger.Core.csproj +++ b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Debugger.Core.csproj @@ -393,4 +393,4 @@ - + \ No newline at end of file diff --git a/src/AddIns/BackendBindings/CSharpBinding/Test/ExpressionFinder.cs b/src/Main/Base/Test/CSharpExpressionFinderTests.cs similarity index 97% rename from src/AddIns/BackendBindings/CSharpBinding/Test/ExpressionFinder.cs rename to src/Main/Base/Test/CSharpExpressionFinderTests.cs index fdab743431..0f8f95e1d6 100644 --- a/src/AddIns/BackendBindings/CSharpBinding/Test/ExpressionFinder.cs +++ b/src/Main/Base/Test/CSharpExpressionFinderTests.cs @@ -1,4 +1,4 @@ -// +// // // // @@ -9,15 +9,14 @@ using System; using System.Reflection; using System.Collections.Generic; using NUnit.Framework; -using CSharpBinding.Parser; using ICSharpCode.SharpDevelop; using ICSharpCode.SharpDevelop.Dom; using ICSharpCode.SharpDevelop.Dom.CSharp; -namespace CSharpBinding.Tests +namespace ICSharpCode.SharpDevelop.Tests { [TestFixture] - public class ExpressionFinderTests + public class CSharpExpressionFinderTests { const string document = @"using System; class Main : BaseType diff --git a/src/Main/Base/Test/ICSharpCode.SharpDevelop.Tests.csproj b/src/Main/Base/Test/ICSharpCode.SharpDevelop.Tests.csproj index ca4a5665f0..c3134764bf 100644 --- a/src/Main/Base/Test/ICSharpCode.SharpDevelop.Tests.csproj +++ b/src/Main/Base/Test/ICSharpCode.SharpDevelop.Tests.csproj @@ -49,6 +49,7 @@ + @@ -58,6 +59,7 @@ + diff --git a/src/Main/Base/Test/VBExpressionFinderTests.cs b/src/Main/Base/Test/VBExpressionFinderTests.cs new file mode 100644 index 0000000000..caaec5a87f --- /dev/null +++ b/src/Main/Base/Test/VBExpressionFinderTests.cs @@ -0,0 +1,78 @@ +// +// +// +// +// $Revision$ +// + +using System; +using System.Reflection; +using System.Collections.Generic; +using NUnit.Framework; +using ICSharpCode.SharpDevelop; +using ICSharpCode.SharpDevelop.Dom; +using ICSharpCode.SharpDevelop.Dom.VBNet; + +namespace ICSharpCode.SharpDevelop.Tests +{ + [TestFixture] + public class VBExpressionFinderTests + { + const string program1 = @" +Class MainClass ' a comment + Dim under_score_field As Integer + Sub SomeMethod() + simple += 1 + For Each loopVarName In collection + Next + End Sub +End Class +"; + + VBExpressionFinder ef; + + [SetUp] + public void Init() + { + HostCallback.GetParseInformation = ParserService.GetParseInformation; + HostCallback.GetCurrentProjectContent = delegate { + return ParserService.CurrentProjectContent; + }; + + ef = new VBExpressionFinder(); + } + + void FindFull(string program, string location, string expectedExpression, ExpressionContext expectedContext) + { + int pos = program.IndexOf(location); + if (pos < 0) Assert.Fail("location not found in program"); + ExpressionResult er = ef.FindFullExpression(program, pos); + Assert.AreEqual(expectedExpression, er.Expression); + Assert.AreEqual(expectedContext.ToString(), er.Context.ToString()); + } + + [Test] + public void Simple() + { + FindFull(program1, "mple += 1", "simple", ExpressionContext.Default); + } + + [Test] + public void SimpleBeginningOfExpression() + { + FindFull(program1, "simple += 1", "simple", ExpressionContext.Default); + } + + [Test] + public void Underscore() + { + FindFull(program1, "der_score_field", "under_score_field", ExpressionContext.Default); + } + + [Test] + public void IdentifierBeforeKeyword() + { + FindFull(program1, "arName", "loopVarName", ExpressionContext.Default); + } + } +} diff --git a/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/VBNet/ExpressionFinder.cs b/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/VBNet/ExpressionFinder.cs index dcbd32a08f..004c72257e 100644 --- a/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/VBNet/ExpressionFinder.cs +++ b/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/VBNet/ExpressionFinder.cs @@ -73,7 +73,7 @@ namespace ICSharpCode.SharpDevelop.Dom.VBNet // append characters after expression for (int i = offset + 1; i < inText.Length; ++i) { char c = inText[i]; - if (Char.IsLetterOrDigit(c)) { + if (Char.IsLetterOrDigit(c) || c == '_') { if (Char.IsWhiteSpace(inText, i - 1)) break; b.Append(c); @@ -89,6 +89,10 @@ namespace ICSharpCode.SharpDevelop.Dom.VBNet break; } } + // remove space from end: + if (b.Length > 0 && b[b.Length - 1] == ' ') { + b.Length -= 1; + } return CreateResult(b.ToString()); } diff --git a/src/SharpDevelop.Tests.sln b/src/SharpDevelop.Tests.sln index 233ac3f945..02e5a38e9a 100644 --- a/src/SharpDevelop.Tests.sln +++ b/src/SharpDevelop.Tests.sln @@ -1,6 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 9.00 -# SharpDevelop 2.1.0.2027 +# Visual Studio 2005 +# SharpDevelop 2.1.0.2192 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "AddIns", "AddIns", "{14A277EE-7DF1-4529-B639-7D1EF334C1C5}" ProjectSection(SolutionItems) = postProject EndProjectSection @@ -53,8 +54,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NRefactoryToBooConverter.Te EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NRefactoryToBooConverter", "AddIns\BackendBindings\Boo\NRefactoryToBooConverter\Project\NRefactoryToBooConverter.csproj", "{DBCF20A1-BA13-4582-BFA9-74DE4D987B73}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CSharpBinding.Tests", "AddIns\BackendBindings\CSharpBinding\Test\CSharpBinding.Tests.csproj", "{4D0DFCB0-F6FB-469D-AA6F-C7F1D5FD5DE7}" -EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CSharpBinding", "AddIns\BackendBindings\CSharpBinding\Project\CSharpBinding.csproj", "{1F1AC7CD-D154-45BB-8EAF-804CA8055F5A}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Libraries", "Libraries", "{9421EDF4-9769-4BE9-B5A6-C87DE221D73C}" @@ -281,7 +280,6 @@ Global EndGlobalSection GlobalSection(NestedProjects) = preSolution {1F1AC7CD-D154-45BB-8EAF-804CA8055F5A} = {14A277EE-7DF1-4529-B639-7D1EF334C1C5} - {4D0DFCB0-F6FB-469D-AA6F-C7F1D5FD5DE7} = {14A277EE-7DF1-4529-B639-7D1EF334C1C5} {DBCF20A1-BA13-4582-BFA9-74DE4D987B73} = {14A277EE-7DF1-4529-B639-7D1EF334C1C5} {C9DE556D-325C-4544-B29F-16A9EB7C9830} = {14A277EE-7DF1-4529-B639-7D1EF334C1C5} {6604365C-C702-4C10-9BA8-637F1E3D4D0D} = {14A277EE-7DF1-4529-B639-7D1EF334C1C5}