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

@ -325,6 +325,8 @@ Bug Fixes
* LUCENE-4662: Add missing elided articles and prepositions to FrenchAnalyzer's * LUCENE-4662: Add missing elided articles and prepositions to FrenchAnalyzer's
DEFAULT_ARTICLES list passed to ElisionFilter. (David Leunen via Steve Rowe) 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 Changes in Runtime Behavior
* LUCENE-4586: Change default ResultMode of FacetRequest to PER_NODE_IN_TREE. * LUCENE-4586: Change default ResultMode of FacetRequest to PER_NODE_IN_TREE.

View File

@ -218,7 +218,7 @@ public final class CharsRef implements Comparable<CharsRef>, CharSequence, Clone
if (start < 0 || end > length || start > end) { if (start < 0 || end > length || start > end) {
throw new IndexOutOfBoundsException(); 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 */ /** @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-3590: fix off-by-one in subsequence, and fully obey interface
// LUCENE-4671: fix subSequence
public void testCharSequenceSubSequence() { 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 // slice
assertEquals("a", c.subSequence(0, 1).toString()); 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 // empty subsequence
assertEquals("", c.subSequence(0, 0).toString()); assertEquals("", c.subSequence(0, 0).toString());