LUCENE-4671: Fix CharsRef.subSequence method

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1431019 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Robert Muir 2013-01-09 19:31:23 +00:00
parent e23480ff25
commit 2351663f3a
3 changed files with 21 additions and 2 deletions

View File

@ -324,6 +324,8 @@ Bug Fixes
* LUCENE-4662: Add missing elided articles and prepositions to FrenchAnalyzer's
DEFAULT_ARTICLES list passed to ElisionFilter. (David Leunen via Steve Rowe)
* LUCENE-4671: Fix CharsRef.subSequence method. (Tim Smith via Robert Muir)
Changes in Runtime Behavior

View File

@ -218,7 +218,7 @@ public final class CharsRef implements Comparable<CharsRef>, CharSequence, Clone
if (start < 0 || end > length || start > end) {
throw new IndexOutOfBoundsException();
}
return new CharsRef(chars, offset + start, offset + end);
return new CharsRef(chars, offset + start, end - start);
}
/** @deprecated This comparator is only a transition mechanism */

View File

@ -116,11 +116,28 @@ public class TestCharsRef extends LuceneTestCase {
}
// LUCENE-3590: fix off-by-one in subsequence, and fully obey interface
// LUCENE-4671: fix subSequence
public void testCharSequenceSubSequence() {
CharSequence c = new CharsRef("abc");
CharSequence sequences[] = {
new CharsRef("abc"),
new CharsRef("0abc".toCharArray(), 1, 3),
new CharsRef("abc0".toCharArray(), 0, 3),
new CharsRef("0abc0".toCharArray(), 1, 3)
};
for (CharSequence c : sequences) {
doTestSequence(c);
}
}
private void doTestSequence(CharSequence c) {
// slice
assertEquals("a", c.subSequence(0, 1).toString());
// mid subsequence
assertEquals("b", c.subSequence(1, 2).toString());
// end subsequence
assertEquals("bc", c.subSequence(1, 3).toString());
// empty subsequence
assertEquals("", c.subSequence(0, 0).toString());