Skip to content

Apache Lucene open-source search software

LUCENE-3911: always use the same unicode block in the realistic case, sometimes use regexpish for lots of punctuation, fix off-by-one in randomRegexpIshString

Robert Muir8f53e6eaa7b0
diff --git a/lucene/test-framework/src/java/org/apache/lucene/analysis/BaseTokenStreamTestCase.java b/lucene/test-framework/src/java/org/apache/lucene/analysis/BaseTokenStreamTestCase.java
index 55ac3b987e5..51cfabf49a7 100644
--- a/lucene/test-framework/src/java/org/apache/lucene/analysis/BaseTokenStreamTestCase.java
+++ b/lucene/test-framework/src/java/org/apache/lucene/analysis/BaseTokenStreamTestCase.java
@@ -611,9 +611,13 @@ public abstract class BaseTokenStreamTestCase extends LuceneTestCase {
if (evilness < 10) {
sb.append(_TestUtil.randomSimpleString(random, wordLength));
} else if (evilness < 15) {
- sb.append(_TestUtil.randomRealisticUnicodeString(random, wordLength));
+ assert sb.length() == 0; // we should always get wordLength back!
+ sb.append(_TestUtil.randomRealisticUnicodeString(random, wordLength, wordLength));
} else if (evilness == 16) {
sb.append(_TestUtil.randomHtmlishString(random, wordLength));
+ } else if (evilness == 17) {
+ // gives a lot of punctuation
+ sb.append(_TestUtil.randomRegexpishString(random, wordLength));
} else {
sb.append(_TestUtil.randomUnicodeString(random, wordLength));
}
diff --git a/lucene/test-framework/src/java/org/apache/lucene/util/_TestUtil.java b/lucene/test-framework/src/java/org/apache/lucene/util/_TestUtil.java
index b1eaabb2ada..b514e0aba0d 100644
--- a/lucene/test-framework/src/java/org/apache/lucene/util/_TestUtil.java
+++ b/lucene/test-framework/src/java/org/apache/lucene/util/_TestUtil.java
@@ -264,7 +264,15 @@ public class _TestUtil {
* If you call this enough times, you might get a valid regex!
*/
public static String randomRegexpishString(Random r) {
- final int end = r.nextInt(20);
+ return randomRegexpishString(r, 20);
+ }
+
+ /**
+ * Returns a String thats "regexpish" (contains lots of operators typically found in regular expressions)
+ * If you call this enough times, you might get a valid regex!
+ */
+ public static String randomRegexpishString(Random r, int maxLength) {
+ final int end = nextInt(r, 0, maxLength);
if (end == 0) {
// allow 0 length
return "";