Browse Source

updated VBExpressionFinder: now uses new API

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/vbnet@6062 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
pull/1/head
Siegfried Pammer 16 years ago
parent
commit
4d30bfa51d
  1. 47
      src/Main/Base/Test/VBExpressionFinderTests.cs
  2. 3
      src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/VBNet/VBNetExpressionFinder.cs

47
src/Main/Base/Test/VBExpressionFinderTests.cs

@ -15,14 +15,18 @@ using ICSharpCode.SharpDevelop.Dom.VBNet;
namespace ICSharpCode.SharpDevelop.Tests namespace ICSharpCode.SharpDevelop.Tests
{ {
[TestFixture, Ignore] [TestFixture]
public class VBExpressionFinderTests public class VBExpressionFinderTests
{ {
const string program1 = @" const string program1 = @"
Imports System
Imports System.Linq
Class MainClass ' a comment Class MainClass ' a comment
Dim under_score_field As Integer Dim under_score_field As Integer
Sub SomeMethod() Sub SomeMethod()
simple += 1 simple += 1
Dim text = ""Text""
For Each loopVarName In collection For Each loopVarName In collection
Next Next
End Sub End Sub
@ -74,11 +78,46 @@ End Class
FindFull(program1, "arName", "loopVarName", ExpressionContext.Default); FindFull(program1, "arName", "loopVarName", ExpressionContext.Default);
} }
[Test]
public void LocalVariableDecl()
{
FindFull(program1, "ext", "text", ExpressionContext.Default);
}
[Test]
public void Imports1()
{
FindFull(program1, "ystem", "System", ExpressionContext.Global);
}
[Test]
public void Imports2()
{
FindFull(program1, "Lin", "System.Linq", ExpressionContext.Global);
}
[Test]
public void ClassName()
{
FindFull(program1, "ainClas", "MainClass", ExpressionContext.Global);
}
[Test]
public void SubName()
{
FindFull(program1, "omeMe", "SomeMethod", ExpressionContext.Default);
}
#region Old Tests #region Old Tests
void OldTest(string expr, int offset) void OldTest(string expr, int offset)
{ {
string fulltext = "Test\n " + expr + ".AnotherField \n TestEnde"; string body = @"Class Test
Assert.AreEqual(expr, ef.FindFullExpression(fulltext, 6 + offset).Expression); Sub A
{0}.AnotherField
End Sub
End Class";
Assert.AreEqual(expr, ef.FindFullExpression(string.Format(body, expr), @"Class Test
Sub A
".Length + offset).Expression);
} }
[Test] [Test]
@ -95,7 +134,7 @@ End Class
OldTest(".abc.def", 7); OldTest(".abc.def", 7);
} }
[Test] [Test, Ignore("FindFullExpression not yet implemented")]
public void MethodCall() public void MethodCall()
{ {
OldTest("abc.Method().Method()", 16); OldTest("abc.Method().Method()", 16);

3
src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/VBNet/VBNetExpressionFinder.cs

@ -61,7 +61,7 @@ namespace ICSharpCode.SharpDevelop.Dom.VBNet
do { do {
t = lexer.NextToken(); t = lexer.NextToken();
p.InformToken(t); p.InformToken(t);
} while (t.Location < targetPosition); } while (t.Location <= targetPosition);
Block block = p.CurrentBlock; Block block = p.CurrentBlock;
@ -70,6 +70,7 @@ namespace ICSharpCode.SharpDevelop.Dom.VBNet
tokenOffset = text.Length; tokenOffset = text.Length;
else else
tokenOffset = LocationToOffset(t.Location); tokenOffset = LocationToOffset(t.Location);
int lastExpressionStartOffset = LocationToOffset(block.lastExpressionStart); int lastExpressionStartOffset = LocationToOffset(block.lastExpressionStart);
if (lastExpressionStartOffset >= 0) { if (lastExpressionStartOffset >= 0) {
if (offset < tokenOffset) { if (offset < tokenOffset) {

Loading…
Cancel
Save