Browse Source

Fixed SD2-1312 - DivideByZeroException when searching an empty file. The ForwardTextIterator's MoveAhead method no longer tries to move forward when the text buffer is empty.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/2.1@2382 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Matt Ward 19 years ago
parent
commit
61ab46c6ff
  1. 4
      src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Engine/TextIterator/ForwardTextIterator.cs
  2. 47
      src/Main/Base/Test/ForwardIteratorWithEmptyTextBufferTestFixture.cs
  3. 1
      src/Main/Base/Test/ICSharpCode.SharpDevelop.Tests.csproj

4
src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Engine/TextIterator/ForwardTextIterator.cs

@ -85,6 +85,10 @@ namespace SearchAndReplace @@ -85,6 +85,10 @@ namespace SearchAndReplace
switch (state) {
case TextIteratorState.Resetted:
if (textBuffer.Length == 0) {
state = TextIteratorState.Done;
return false;
}
Position = endOffset;
state = TextIteratorState.Iterating;
return true;

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

@ -0,0 +1,47 @@ @@ -0,0 +1,47 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
using System;
using ICSharpCode.SharpDevelop.Tests.Utils;
using ICSharpCode.TextEditor.Document;
using SearchAndReplace;
using NUnit.Framework;
namespace ICSharpCode.SharpDevelop.Tests
{
/// <summary>
/// The fix for SD2-857 highlighted another bug (SD2-1312) in the
/// ForwardTextIterator where it does not handle the case where
/// the ITextBufferStrategy has a length of zero.
/// </summary>
[TestFixture]
public class ForwardIteratorWithEmptyTextBufferTestFixture
{
ForwardTextIterator forwardTextIterator;
[SetUp]
public void SetUp()
{
// Create the document to be iterated through.
MockDocument doc = new MockDocument();
StringTextBufferStrategy textBufferStrategy = new StringTextBufferStrategy();
doc.TextBufferStrategy = textBufferStrategy;
ProvidedDocumentInformation docInfo = new ProvidedDocumentInformation(doc,
@"C:\Temp\test.txt",
0);
// Create the forward iterator.
forwardTextIterator = new ForwardTextIterator(docInfo);
}
[Test]
public void CannotMoveAhead()
{
Assert.IsFalse(forwardTextIterator.MoveAhead(1));
}
}
}

1
src/Main/Base/Test/ICSharpCode.SharpDevelop.Tests.csproj

@ -53,6 +53,7 @@ @@ -53,6 +53,7 @@
<Compile Include="CSharpExpressionFinderTests.cs" />
<Compile Include="ExceptionClassOverridesTestFixture.cs" />
<Compile Include="FindNextWithCursorAtEndTestFixture.cs" />
<Compile Include="ForwardIteratorWithEmptyTextBufferTestFixture.cs" />
<Compile Include="ForwardTextIteratorPositionIsEndOffsetTestFixture.cs" />
<Compile Include="NRefactoryResolverTests.cs" />
<Compile Include="CollectionClassOverridesTestFixture.cs" />

Loading…
Cancel
Save