Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fix ArgumentOutOfRangeException when searching for references on arra…

…y indexer.
  • Loading branch information...
commit dcc21eeb99bcb5661192d23fd76f588e4e9552d0 1 parent 540b66c
@mrward mrward authored
View
5 src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/LanguageProperties.cs
@@ -532,11 +532,10 @@ public IndexBeforeTextFinder(string searchText)
public override TextFinderMatch Find(string inputText, int startPosition)
{
int pos = inputText.IndexOf(searchText, startPosition);
- if (pos >= 0) {
+ if (pos > 0) {
return new TextFinderMatch(pos, searchText.Length, pos - 1);
- } else {
- return TextFinderMatch.Empty;
}
+ return TextFinderMatch.Empty;
}
}
#endregion
View
2  ...op.Dom/Tests/ICSharpCode.SharpDevelop.Dom.Tests/ICSharpCode.SharpDevelop.Dom.Tests.csproj
@@ -52,8 +52,10 @@
<Compile Include="CodeSnippetConverterTests.cs" />
<Compile Include="CSharpAmbienceTests.cs" />
<Compile Include="ImplementInterfaceTests.cs" />
+ <Compile Include="IndexBeforeTextFinderTests.cs" />
<Compile Include="NRefactoryAstConverterTests.cs" />
<Compile Include="NRefactoryRefactoringProviderTests.cs" />
+ <Compile Include="NUnitHelpers\IndexBeforeTextFinderHelper.cs" />
<Compile Include="NUnitHelpers\SyntaxHelpers.cs" />
<Compile Include="NUnitHelpers\Constraints.cs" />
<Compile Include="ProjectContentClassManagementTest.cs" />
View
70 ...e.SharpDevelop.Dom/Tests/ICSharpCode.SharpDevelop.Dom.Tests/IndexBeforeTextFinderTests.cs
@@ -0,0 +1,70 @@
+// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
+// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
+
+using System;
+using ICSharpCode.SharpDevelop.Dom;
+using ICSharpCode.SharpDevelop.Dom.Refactoring;
+using ICSharpCode.SharpDevelop.Dom.Tests.NUnitHelpers;
+using NUnit.Framework;
+
+namespace ICSharpCode.SharpDevelop.Dom.Tests
+{
+ [TestFixture]
+ public class IndexBeforeTextFinderTests
+ {
+ TextFinder textFinder;
+ IndexBeforeTextFinderHelper helper;
+
+ void CreateIndexBeforeTextFinderWithSearchTextOf(string searchText)
+ {
+ helper = new IndexBeforeTextFinderHelper();
+ textFinder = helper.CreateIndexBeforeTextFinder(searchText);
+ }
+
+ void AssertTextFindMatchesAreEqual(TextFinderMatch expectedMatch, TextFinderMatch actualMatch)
+ {
+ string expectedMatchAsString = GetTextFinderMatchAsString(expectedMatch);
+ string actualMatchAsString = GetTextFinderMatchAsString(actualMatch);
+ Assert.AreEqual(expectedMatchAsString, actualMatchAsString);
+ }
+
+ string GetTextFinderMatchAsString(TextFinderMatch match)
+ {
+ return String.Format(
+ "Position: {0}, Length: {1}, ResolvePosition: {2}",
+ match.Position,
+ match.Length,
+ match.ResolvePosition);
+ }
+
+ [Test]
+ public void Find_SearchingForSquareBracketCharacterAndInputTextHasNoSquareBracketCharacter_ReturnsEmptyTextFinderMatch()
+ {
+ CreateIndexBeforeTextFinderWithSearchTextOf("[");
+ TextFinderMatch match = textFinder.Find("abc", 0);
+
+ AssertTextFindMatchesAreEqual(TextFinderMatch.Empty, match);
+ }
+
+ [Test]
+ public void Find_SearchingForSquareBracketCharacterAndInputTextHasSquareBracketAtPositionOne_ReturnsTextFinderMatchForPositionOne()
+ {
+ CreateIndexBeforeTextFinderWithSearchTextOf("[");
+ TextFinderMatch match = textFinder.Find("a[0]", 0);
+
+ TextFinderMatch expectedMatch =
+ new TextFinderMatch(position: 1, length: 1, resolvePosition: 0);
+
+ AssertTextFindMatchesAreEqual(expectedMatch, match);
+ }
+
+ [Test]
+ public void Find_SearchingForSquareBracketCharacterAndInputTextHasSquareBracketCharacterAtPositionZero_ReturnsEmptyTextFinderMatch()
+ {
+ CreateIndexBeforeTextFinderWithSearchTextOf("[");
+ TextFinderMatch match = textFinder.Find("[assembly: AssemblyCulture(\"\")]", 0);
+
+ AssertTextFindMatchesAreEqual(TextFinderMatch.Empty, match);
+ }
+ }
+}
View
21 ....Dom/Tests/ICSharpCode.SharpDevelop.Dom.Tests/NUnitHelpers/IndexBeforeTextFinderHelper.cs
@@ -0,0 +1,21 @@
+// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
+// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
+
+using System;
+using ICSharpCode.SharpDevelop.Dom.Refactoring;
+
+namespace ICSharpCode.SharpDevelop.Dom.Tests.NUnitHelpers
+{
+ public class IndexBeforeTextFinderHelper : LanguageProperties
+ {
+ public IndexBeforeTextFinderHelper()
+ : base(StringComparer.Ordinal)
+ {
+ }
+
+ public TextFinder CreateIndexBeforeTextFinder(string searchText)
+ {
+ return new IndexBeforeTextFinder(searchText);
+ }
+ }
+}

0 comments on commit dcc21ee

Please sign in to comment.
Something went wrong with that request. Please try again.