mirror of https://github.com/apache/lucene.git
tests: add regex capability to JSON test format
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1501933 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
f45358ebc1
commit
8607f3b76e
|
@ -66,8 +66,7 @@ public class TestManagedSchemaFieldResource extends RestTestBase {
|
|||
public void testAddFieldMismatchedName() throws Exception {
|
||||
assertJPut("/schema/fields/newfield",
|
||||
json( "{'name':'something_else','type':'text','stored':'false'}" ),
|
||||
"/error/msg==\"Field name in the request body \\'something_else\\'"
|
||||
+ " doesn\\'t match field name in the request URL \\'newfield\\'\"");
|
||||
"/error/msg=='///regex:newfield///'");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -21,6 +21,8 @@ import org.noggit.ObjectBuilder;
|
|||
import org.apache.solr.common.util.StrUtils;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
|
||||
public class JSONTestUtil {
|
||||
|
@ -179,6 +181,13 @@ class CollectionTester {
|
|||
// generic fallback
|
||||
if (!expected.equals(val)) {
|
||||
|
||||
if (expected instanceof String) {
|
||||
String str = (String)expected;
|
||||
if (str.length() > 6 && str.startsWith("///") && str.endsWith("///")) {
|
||||
return handleSpecialString(str);
|
||||
}
|
||||
}
|
||||
|
||||
// make an exception for some numerics
|
||||
if ((expected instanceof Integer && val instanceof Long || expected instanceof Long && val instanceof Integer)
|
||||
&& ((Number)expected).longValue() == ((Number)val).longValue()) {
|
||||
|
@ -197,6 +206,29 @@ class CollectionTester {
|
|||
return true;
|
||||
}
|
||||
|
||||
private boolean handleSpecialString(String str) {
|
||||
String code = str.substring(3,str.length()-3);
|
||||
if ("ignore".equals(code)) {
|
||||
return true;
|
||||
} else if (code.startsWith("regex:")) {
|
||||
String regex = code.substring("regex:".length());
|
||||
if (!(val instanceof String)) {
|
||||
setErr("mismatch: '" + expected + "'!='" + val + "', value is not a string");
|
||||
return false;
|
||||
}
|
||||
Pattern pattern = Pattern.compile(regex);
|
||||
Matcher matcher = pattern.matcher((String)val);
|
||||
if (matcher.find()) {
|
||||
return true;
|
||||
}
|
||||
setErr("mismatch: '" + expected + "'!='" + val + "', regex does not match");
|
||||
return false;
|
||||
}
|
||||
|
||||
setErr("mismatch: '" + expected + "'!='" + val + "'");
|
||||
return false;
|
||||
}
|
||||
|
||||
boolean matchList() {
|
||||
List expectedList = (List)expected;
|
||||
List v = asList();
|
||||
|
|
Loading…
Reference in New Issue