From 776e1b4a983d9e7e5be344741d1b8d5b577a3ab3 Mon Sep 17 00:00:00 2001 From: Robert Muir Date: Mon, 16 Apr 2012 02:56:43 +0000 Subject: [PATCH] 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 --- .../analysis/core/TestBugInSomething.java | 64 +++++++++++++++++++ .../analysis/core/TestRandomChains.java | 51 ++++++++++++--- 2 files changed, 106 insertions(+), 9 deletions(-) create mode 100644 modules/analysis/common/src/test/org/apache/lucene/analysis/core/TestBugInSomething.java diff --git a/modules/analysis/common/src/test/org/apache/lucene/analysis/core/TestBugInSomething.java b/modules/analysis/common/src/test/org/apache/lucene/analysis/core/TestBugInSomething.java new file mode 100644 index 00000000000..5cd5c65508b --- /dev/null +++ b/modules/analysis/common/src/test/org/apache/lucene/analysis/core/TestBugInSomething.java @@ -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"); + } +} diff --git a/modules/analysis/common/src/test/org/apache/lucene/analysis/core/TestRandomChains.java b/modules/analysis/common/src/test/org/apache/lucene/analysis/core/TestRandomChains.java index e1804868c95..fdd5aadb123 100644 --- a/modules/analysis/common/src/test/org/apache/lucene/analysis/core/TestRandomChains.java +++ b/modules/analysis/common/src/test/org/apache/lucene/analysis/core/TestRandomChains.java @@ -756,44 +756,77 @@ public class TestRandomChains extends BaseTokenStreamTestCase { } } - static final class CheckThatYouDidntReadAnythingReaderWrapper extends CharFilter { - boolean readSomething = false; + // wants charfilter to be a filterreader... + // do *NOT* refactor me to be a charfilter: LUCENE-3990 + static class CheckThatYouDidntReadAnythingReaderWrapper extends CharStream { + boolean readSomething; + CharStream 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 public int read(char[] cbuf, int off, int len) throws IOException { readSomething = true; - return super.read(cbuf, off, len); + return in.read(cbuf, off, len); } @Override public int read() throws IOException { readSomething = true; - return super.read(); + return in.read(); } @Override public int read(CharBuffer target) throws IOException { 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 public int read(char[] cbuf) throws IOException { 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 public long skip(long n) throws IOException { readSomething = true; - return super.skip(n); + return in.skip(n); } } - + static class TokenizerSpec { Tokenizer tokenizer; String toString;