LUCENE-3990: don't extend charfilter here, delegate all methods

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1326468 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Robert Muir 2012-04-16 02:56:43 +00:00
parent 8ad99c1a1b
commit 776e1b4a98
2 changed files with 106 additions and 9 deletions

View File

@ -0,0 +1,64 @@
package org.apache.lucene.analysis.core;
import java.io.Reader;
import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.BaseTokenStreamTestCase;
import org.apache.lucene.analysis.MockCharFilter;
import org.apache.lucene.analysis.MockTokenFilter;
import org.apache.lucene.analysis.MockTokenizer;
import org.apache.lucene.analysis.TokenFilter;
import org.apache.lucene.analysis.Tokenizer;
import org.apache.lucene.analysis.charfilter.MappingCharFilter;
import org.apache.lucene.analysis.charfilter.NormalizeCharMap;
import org.apache.lucene.analysis.commongrams.CommonGramsFilter;
import org.apache.lucene.analysis.util.CharArraySet;
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
public class TestBugInSomething extends BaseTokenStreamTestCase {
public void test() throws Exception {
final CharArraySet cas = new CharArraySet(TEST_VERSION_CURRENT, 3, false);
cas.add("jjp");
cas.add("wlmwoknt");
cas.add("tcgyreo");
final NormalizeCharMap map = new NormalizeCharMap();
map.add("mtqlpi", "");
map.add("mwoknt", "jjp");
map.add("tcgyreo", "zpfpajyws");
map.add("", "eethksv");
Analyzer a = new Analyzer() {
@Override
protected TokenStreamComponents createComponents(String fieldName, Reader reader) {
Tokenizer t = new MockTokenizer(new TestRandomChains.CheckThatYouDidntReadAnythingReaderWrapper(reader), MockTokenFilter.ENGLISH_STOPSET, false, -65);
TokenFilter f = new CommonGramsFilter(TEST_VERSION_CURRENT, t, cas);
return new TokenStreamComponents(t, f);
}
@Override
protected Reader initReader(Reader reader) {
reader = new MockCharFilter(reader, 0);
reader = new MappingCharFilter(map, reader);
return reader;
}
};
checkAnalysisConsistency(random(), a, false, "wmgddzunizdomqyj");
}
}

View File

@ -756,41 +756,74 @@ public class TestRandomChains extends BaseTokenStreamTestCase {
} }
} }
static final class CheckThatYouDidntReadAnythingReaderWrapper extends CharFilter { // wants charfilter to be a filterreader...
boolean readSomething = false; // do *NOT* refactor me to be a charfilter: LUCENE-3990
static class CheckThatYouDidntReadAnythingReaderWrapper extends CharStream {
boolean readSomething;
CharStream in;
CheckThatYouDidntReadAnythingReaderWrapper(Reader in) { CheckThatYouDidntReadAnythingReaderWrapper(Reader in) {
super(CharReader.get(in)); this.in = CharReader.get(in);
}
@Override
public int correctOffset(int currentOff) {
return in.correctOffset(currentOff);
}
@Override
public void close() throws IOException {
in.close();
} }
@Override @Override
public int read(char[] cbuf, int off, int len) throws IOException { public int read(char[] cbuf, int off, int len) throws IOException {
readSomething = true; readSomething = true;
return super.read(cbuf, off, len); return in.read(cbuf, off, len);
} }
@Override @Override
public int read() throws IOException { public int read() throws IOException {
readSomething = true; readSomething = true;
return super.read(); return in.read();
} }
@Override @Override
public int read(CharBuffer target) throws IOException { public int read(CharBuffer target) throws IOException {
readSomething = true; readSomething = true;
return super.read(target); return in.read(target);
}
@Override
public void mark(int readAheadLimit) throws IOException {
in.mark(readAheadLimit);
}
@Override
public boolean markSupported() {
return in.markSupported();
} }
@Override @Override
public int read(char[] cbuf) throws IOException { public int read(char[] cbuf) throws IOException {
readSomething = true; readSomething = true;
return super.read(cbuf); return in.read(cbuf);
}
@Override
public boolean ready() throws IOException {
return in.ready();
}
@Override
public void reset() throws IOException {
in.reset();
} }
@Override @Override
public long skip(long n) throws IOException { public long skip(long n) throws IOException {
readSomething = true; readSomething = true;
return super.skip(n); return in.skip(n);
} }
} }