SOLR-7958: Move TestUtil#randomWhitespace to the only Solr test that is using it

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1697262 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Uwe Schindler 2015-08-23 21:41:03 +00:00
parent e31c84e061
commit 6a44b00201
3 changed files with 60 additions and 68 deletions

View File

@ -109,6 +109,11 @@ Tests
* LUCENE-6752: Add Math#random() to forbiddenapis. (Uwe Schindler,
Mikhail Khludnev, Andrei Beliakov)
* LUCENE-6760, SOLR-7958: Move TestUtil#randomWhitespace to the only
Solr test that is using it. The method is not useful for Lucene tests
(and easily breaks, e.g., in Java 9 caused by Unicode version updates).
(Uwe Schindler)
Changes in Backwards Compatibility Policy
* LUCENE-6742: The Lovins & Finnish implementation of SnowballFilter

View File

@ -35,7 +35,6 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Random;
@ -1177,24 +1176,6 @@ public final class TestUtil {
}
}
/**
* Returns a random string in the specified length range consisting
* entirely of whitespace characters
* @see #WHITESPACE_CHARACTERS
*/
public static String randomWhitespace(Random r, int minLength, int maxLength) {
final int end = nextInt(r, minLength, maxLength);
StringBuilder out = new StringBuilder();
for (int i = 0; i < end; i++) {
int offset = nextInt(r, 0, WHITESPACE_CHARACTERS.length-1);
char c = WHITESPACE_CHARACTERS[offset];
// sanity check
assert Character.isWhitespace(c) : String.format(Locale.ENGLISH, "Not really whitespace? WHITESPACE_CHARACTERS[%d] is '\\u%04X'", offset, (int) c);
out.append(c);
}
return out.toString();
}
public static String randomAnalysisString(Random random, int maxLength, boolean simple) {
assert maxLength >= 0;
@ -1294,36 +1275,4 @@ public final class TestUtil {
}
return ram;
}
/** List of characters that match {@link Character#isWhitespace} */
public static final char[] WHITESPACE_CHARACTERS = new char[] {
// :TODO: is this list exhaustive?
'\u0009',
'\n',
'\u000B',
'\u000C',
'\r',
'\u001C',
'\u001D',
'\u001E',
'\u001F',
'\u0020',
// '\u0085', failed sanity check?
'\u1680',
// '\u180E', no longer whitespace in Unicode 7.0 (Java 9)!
'\u2000',
'\u2001',
'\u2002',
'\u2003',
'\u2004',
'\u2005',
'\u2006',
'\u2008',
'\u2009',
'\u200A',
'\u2028',
'\u2029',
'\u205F',
'\u3000',
};
}

View File

@ -20,28 +20,16 @@ package org.apache.solr.search;
import org.apache.lucene.util.TestUtil;
import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.response.transform.*;
import org.junit.BeforeClass;
import org.junit.Test;
import java.util.Locale;
import java.util.Random;
public class ReturnFieldsTest extends SolrTestCaseJ4 {
// :TODO: datatypes produced by the functions used may change
/**
* values of the fl param that mean all real fields
*/
private static String[] ALL_REAL_FIELDS = new String[] { "", "*" };
/**
* values of the fl param that mean all real fields and score
*/
private static String[] SCORE_AND_REAL_FIELDS = new String[] {
"score", "score,*", "*,score"
};
@BeforeClass
public static void beforeClass() throws Exception {
System.setProperty("enable.update.log", "false"); // schema12 doesn't support _version_
@ -341,14 +329,14 @@ public class ReturnFieldsTest extends SolrTestCaseJ4 {
final boolean aliasId = r.nextBoolean();
final boolean aliasFoo = r.nextBoolean();
final String id = TestUtil.randomWhitespace(r, 0, 3) +
final String id = randomWhitespace(r, 0, 3) +
(aliasId ? "aliasId:" : "") +
"id" +
TestUtil.randomWhitespace(r, 1, 3);
final String foo_i = TestUtil.randomWhitespace(r, 0, 3) +
randomWhitespace(r, 1, 3);
final String foo_i = randomWhitespace(r, 0, 3) +
(aliasFoo ? "aliasFoo:" : "") +
"foo_i" +
TestUtil.randomWhitespace(r, 0, 3);
randomWhitespace(r, 0, 3);
final String fl = id + (r.nextBoolean() ? "" : ",") + foo_i;
ReturnFields rf = new SolrReturnFields(req("fl", fl));
@ -366,4 +354,54 @@ public class ReturnFieldsTest extends SolrTestCaseJ4 {
}
}
/** List of characters that match {@link Character#isWhitespace} */
private static final char[] WHITESPACE_CHARACTERS = new char[] {
// :TODO: is this list exhaustive?
'\u0009',
'\n',
'\u000B',
'\u000C',
'\r',
'\u001C',
'\u001D',
'\u001E',
'\u001F',
'\u0020',
// '\u0085', failed sanity check?
'\u1680',
// '\u180E', no longer whitespace in Unicode 7.0 (Java 9)!
'\u2000',
'\u2001',
'\u2002',
'\u2003',
'\u2004',
'\u2005',
'\u2006',
'\u2008',
'\u2009',
'\u200A',
'\u2028',
'\u2029',
'\u205F',
'\u3000',
};
/**
* Returns a random string in the specified length range consisting
* entirely of whitespace characters
* @see #WHITESPACE_CHARACTERS
*/
public static String randomWhitespace(Random r, int minLength, int maxLength) {
final int end = TestUtil.nextInt(r, minLength, maxLength);
StringBuilder out = new StringBuilder();
for (int i = 0; i < end; i++) {
int offset = TestUtil.nextInt(r, 0, WHITESPACE_CHARACTERS.length-1);
char c = WHITESPACE_CHARACTERS[offset];
// sanity check
assert Character.isWhitespace(c) : String.format(Locale.ENGLISH, "Not really whitespace? WHITESPACE_CHARACTERS[%d] is '\\u%04X'", offset, (int) c);
out.append(c);
}
return out.toString();
}
}