Browse Source

Fixed SD2-1623 - Boo: Find references does not return any results

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/3.0@5277 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
pull/1/head
Daniel Grunwald 16 years ago
parent
commit
d5c6e2aad2
  1. 24
      src/AddIns/BackendBindings/Boo/BooBinding/Project/Src/CodeCompletion/ExpressionFinder.cs
  2. 4
      src/AddIns/BackendBindings/Boo/BooBinding/Test/BooBinding.Tests.csproj
  3. 68
      src/AddIns/BackendBindings/Boo/BooBinding/Test/ExpressionFinderTests.cs

24
src/AddIns/BackendBindings/Boo/BooBinding/Project/Src/CodeCompletion/ExpressionFinder.cs

@ -14,14 +14,14 @@ using ICSharpCode.SharpDevelop.Dom; @@ -14,14 +14,14 @@ using ICSharpCode.SharpDevelop.Dom;
namespace Grunwald.BooBinding.CodeCompletion
{
// TODO: We could need some unit tests for this.
public class ExpressionFinder : IExpressionFinder
{
string fileName;
public ExpressionFinder()
{
}
public ExpressionFinder(string fileName)
{
this.fileName = fileName;
}
#region RemoveLastPart
@ -79,6 +79,14 @@ namespace Grunwald.BooBinding.CodeCompletion @@ -79,6 +79,14 @@ namespace Grunwald.BooBinding.CodeCompletion
const string _openingBrackets = "{[(";
public ExpressionResult FindExpression(string inText, int offset)
{
ExpressionResult r = FindExpressionInternal(inText, offset);
if (string.IsNullOrEmpty(r.Expression))
r.Expression = null;
return r;
}
ExpressionResult FindExpressionInternal(string inText, int offset)
{
offset--; // earlier all ExpressionFinder calls had an inexplicable "cursor - 1".
// The IExpressionFinder API now uses normal cursor offsets, so we need to adjust the offset
@ -154,7 +162,8 @@ namespace Grunwald.BooBinding.CodeCompletion @@ -154,7 +162,8 @@ namespace Grunwald.BooBinding.CodeCompletion
ExpressionResult GetExpression(string inText, int start, int end)
{
if (start == end) return ExpressionResult.Empty;
if (start == end)
return new ExpressionResult(string.Empty);
StringBuilder b = new StringBuilder();
bool wasSpace = true;
int i = start;
@ -234,7 +243,7 @@ namespace Grunwald.BooBinding.CodeCompletion @@ -234,7 +243,7 @@ namespace Grunwald.BooBinding.CodeCompletion
#region Find Full Expression
public ExpressionResult FindFullExpression(string inText, int offset)
{
ExpressionResult result = FindExpression(inText, offset);
ExpressionResult result = FindExpressionInternal(inText, offset);
if (result.Expression == null)
return result;
StringBuilder b = new StringBuilder(result.Expression);
@ -261,7 +270,10 @@ namespace Grunwald.BooBinding.CodeCompletion @@ -261,7 +270,10 @@ namespace Grunwald.BooBinding.CodeCompletion
} else {
if (bracketStack.Count == 0) {
b.Append(inText, offset, i - offset);
result.Expression = b.ToString();
if (b.Length == 0)
result.Expression = null;
else
result.Expression = b.ToString();
return result;
} else if (c == '\0') {
// end of document

4
src/AddIns/BackendBindings/Boo/BooBinding/Test/BooBinding.Tests.csproj

@ -1,4 +1,5 @@ @@ -1,4 +1,5 @@
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5">
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5">
<PropertyGroup>
<OutputType>Library</OutputType>
<RootNamespace>Grunwald.BooBinding.Tests</RootNamespace>
@ -47,6 +48,7 @@ @@ -47,6 +48,7 @@
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="ExpressionFinderTests.cs" />
<Compile Include="ResolverTests.cs" />
</ItemGroup>
<ItemGroup>

68
src/AddIns/BackendBindings/Boo/BooBinding/Test/ExpressionFinderTests.cs

@ -0,0 +1,68 @@ @@ -0,0 +1,68 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Daniel Grunwald"/>
// <version>$Revision$</version>
// </file>
using System;
using Grunwald.BooBinding.CodeCompletion;
using ICSharpCode.SharpDevelop.Dom;
using NUnit.Framework;
namespace Grunwald.BooBinding.Tests
{
[TestFixture]
public class ExpressionFinderTests
{
const string code = "class A:\n\tpublic simple = 1\n// comment\ndef main():\n\tpass";
ExpressionFinder ef = new ExpressionFinder();
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);
if (expectedContext != null) {
Assert.AreEqual(expectedContext, er.Context);
}
}
[Test]
public void Simple()
{
FindFull(code, "mple = 1", "simple", ExpressionContext.Default);
}
[Test]
public void SimpleBeginningOfExpression()
{
FindFull(code, "simple = 1", "simple", ExpressionContext.Default);
}
[Test]
public void NoMatchForComment1()
{
FindFull(code, "// comment", null, null);
}
[Test]
public void NoMatchForComment2()
{
FindFull(code, "/ comment", null, null);
}
[Test]
public void NoMatchForComment3()
{
FindFull(code, " comment", null, null);
}
[Test]
public void NoMatchForComment4()
{
FindFull(code, "comment", null, null);
}
}
}
Loading…
Cancel
Save