diff --git a/lucene/test-framework/src/java/org/apache/lucene/analysis/MockCharFilter.java b/lucene/test-framework/src/java/org/apache/lucene/analysis/MockCharFilter.java index 0db21515147..452a8267d96 100644 --- a/lucene/test-framework/src/java/org/apache/lucene/analysis/MockCharFilter.java +++ b/lucene/test-framework/src/java/org/apache/lucene/analysis/MockCharFilter.java @@ -22,18 +22,23 @@ import java.io.Reader; import java.util.SortedMap; import java.util.TreeMap; -// the purpose of this charfilter is to send offsets out of bounds -// if the analyzer doesn't use correctOffset or does incorrect offset math. -class MockCharFilter extends CharStream { - final Reader in; +/** the purpose of this charfilter is to send offsets out of bounds + if the analyzer doesn't use correctOffset or does incorrect offset math. */ +public class MockCharFilter extends CharStream { + final CharStream in; final int remainder; // for testing only public MockCharFilter(Reader in, int remainder) { - this.in = in; + this.in = CharReader.get(in); this.remainder = remainder; assert remainder >= 0 && remainder < 10 : "invalid parameter"; } + + // for testing only, uses a remainder of 0 + public MockCharFilter(Reader in) { + this(in, 0); + } @Override public void close() throws IOException { @@ -89,7 +94,7 @@ class MockCharFilter extends CharStream { SortedMap subMap = corrections.subMap(0, currentOff+1); int ret = subMap.isEmpty() ? currentOff : currentOff + subMap.get(subMap.lastKey()); assert ret >= 0 : "currentOff=" + currentOff + ",diff=" + (ret-currentOff); - return ret; + return in.correctOffset(ret); // chain the call } protected void addOffCorrectMap(int off, int cumulativeDiff) { diff --git a/lucene/test-framework/src/java/org/apache/lucene/analysis/MockTokenizer.java b/lucene/test-framework/src/java/org/apache/lucene/analysis/MockTokenizer.java index 6a26b8cb248..849479851a9 100644 --- a/lucene/test-framework/src/java/org/apache/lucene/analysis/MockTokenizer.java +++ b/lucene/test-framework/src/java/org/apache/lucene/analysis/MockTokenizer.java @@ -95,6 +95,11 @@ public class MockTokenizer extends Tokenizer { this(input, runAutomaton, lowerCase, DEFAULT_MAX_TOKEN_LENGTH); } + /** Calls {@link #MockTokenizer(Reader, CharacterRunAutomaton, boolean) MockTokenizer(Reader, WHITESPACE, true)} */ + public MockTokenizer(Reader input) { + this(input, WHITESPACE, true); + } + @Override public final boolean incrementToken() throws IOException { assert !enableChecks || (streamState == State.RESET || streamState == State.INCREMENT)