mirror of https://github.com/apache/lucene.git
LUCENE-3969: add new random test for MappingCharFilter (sometimes fails, due to same final offset bug)
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/branches/lucene3969@1311765 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
f97ac2d0cb
commit
6563a58a2a
|
@ -19,6 +19,8 @@ package org.apache.lucene.analysis.charfilter;
|
||||||
|
|
||||||
import java.io.Reader;
|
import java.io.Reader;
|
||||||
import java.io.StringReader;
|
import java.io.StringReader;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import org.apache.lucene.analysis.Analyzer;
|
import org.apache.lucene.analysis.Analyzer;
|
||||||
import org.apache.lucene.analysis.BaseTokenStreamTestCase;
|
import org.apache.lucene.analysis.BaseTokenStreamTestCase;
|
||||||
|
@ -27,6 +29,7 @@ import org.apache.lucene.analysis.CharStream;
|
||||||
import org.apache.lucene.analysis.MockTokenizer;
|
import org.apache.lucene.analysis.MockTokenizer;
|
||||||
import org.apache.lucene.analysis.TokenStream;
|
import org.apache.lucene.analysis.TokenStream;
|
||||||
import org.apache.lucene.analysis.Tokenizer;
|
import org.apache.lucene.analysis.Tokenizer;
|
||||||
|
import org.apache.lucene.util._TestUtil;
|
||||||
|
|
||||||
public class TestMappingCharFilter extends BaseTokenStreamTestCase {
|
public class TestMappingCharFilter extends BaseTokenStreamTestCase {
|
||||||
|
|
||||||
|
@ -214,4 +217,43 @@ public class TestMappingCharFilter extends BaseTokenStreamTestCase {
|
||||||
String text = "gzw f quaxot";
|
String text = "gzw f quaxot";
|
||||||
checkAnalysisConsistency(random, analyzer, false, text);
|
checkAnalysisConsistency(random, analyzer, false, text);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// nocommit: this is intended to fail until we fix bugs
|
||||||
|
public void testRandomMaps() throws Exception {
|
||||||
|
for (int i = 0; i < 100; i++) {
|
||||||
|
final NormalizeCharMap map = randomMap();
|
||||||
|
Analyzer analyzer = new Analyzer() {
|
||||||
|
@Override
|
||||||
|
protected TokenStreamComponents createComponents(String fieldName, Reader reader) {
|
||||||
|
Tokenizer tokenizer = new MockTokenizer(reader, MockTokenizer.WHITESPACE, false);
|
||||||
|
return new TokenStreamComponents(tokenizer, tokenizer);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Reader initReader(Reader reader) {
|
||||||
|
return new MappingCharFilter(map, CharReader.get(reader));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
int numRounds = RANDOM_MULTIPLIER * 100;
|
||||||
|
checkRandomData(random, analyzer, numRounds);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private NormalizeCharMap randomMap() {
|
||||||
|
NormalizeCharMap map = new NormalizeCharMap();
|
||||||
|
// we can't add duplicate keys, or NormalizeCharMap gets angry
|
||||||
|
Set<String> keys = new HashSet<String>();
|
||||||
|
int num = random.nextInt(5);
|
||||||
|
//System.out.println("NormalizeCharMap=");
|
||||||
|
for (int i = 0; i < num; i++) {
|
||||||
|
String key = _TestUtil.randomSimpleString(random);
|
||||||
|
if (!keys.contains(key)) {
|
||||||
|
String value = _TestUtil.randomSimpleString(random);
|
||||||
|
map.add(key, value);
|
||||||
|
keys.add(key);
|
||||||
|
//System.out.println("mapping: '" + key + "' => '" + value + "'");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return map;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue