mirror of https://github.com/apache/lucene.git
tests: let json parser handle single quoted strings
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1666167 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
0df44e9eff
commit
0ff3ea426f
|
@ -750,7 +750,7 @@ public abstract class SolrTestCaseJ4 extends LuceneTestCase {
|
|||
try {
|
||||
String m = (null == message) ? "" : message + " ";
|
||||
String response = h.query(req);
|
||||
|
||||
|
||||
if (req.getParams().getBool("facet", false)) {
|
||||
// add a test to ensure that faceting did not throw an exception
|
||||
// internally, where it would be added to facet_counts/exception
|
||||
|
@ -814,9 +814,9 @@ public abstract class SolrTestCaseJ4 extends LuceneTestCase {
|
|||
}
|
||||
/**
|
||||
* Validates a query matches some JSON test expressions and closes the
|
||||
* query. The text expression is of the form path:JSON. To facilitate
|
||||
* easy embedding in Java strings, the JSON tests can have double quotes
|
||||
* replaced with single quotes.
|
||||
* query. The text expression is of the form path:JSON. The Noggit JSON
|
||||
* parser used accepts single quoted strings and bare strings to allow
|
||||
* easy embedding in Java Strings.
|
||||
* <p>
|
||||
* Please use this with care: this makes it easy to match complete
|
||||
* structures, but doing so can result in fragile tests if you are
|
||||
|
@ -1129,22 +1129,15 @@ public abstract class SolrTestCaseJ4 extends LuceneTestCase {
|
|||
return Arrays.asList(docs);
|
||||
}
|
||||
|
||||
/** Converts "test JSON" and returns standard JSON.
|
||||
* Currently this only consists of changing unescaped single quotes to double quotes,
|
||||
* and escaped single quotes to single quotes.
|
||||
*
|
||||
* The primary purpose is to be able to easily embed JSON strings in a JAVA string
|
||||
* with the best readability.
|
||||
/** Converts "test JSON" strings into JSON parseable by our JSON parser.
|
||||
* For example, this method changed single quoted strings into double quoted strings before
|
||||
* the parser could natively handle them.
|
||||
*
|
||||
* This transformation is automatically applied to JSON test srings (like assertJQ).
|
||||
*/
|
||||
public static String json(String testJSON) {
|
||||
testJSON = nonEscapedSingleQuotePattern.matcher(testJSON).replaceAll("\"");
|
||||
testJSON = escapedSingleQuotePattern.matcher(testJSON).replaceAll("'");
|
||||
return testJSON;
|
||||
}
|
||||
private static Pattern nonEscapedSingleQuotePattern = Pattern.compile("(?<!\\\\)\'");
|
||||
private static Pattern escapedSingleQuotePattern = Pattern.compile("\\\\\'");
|
||||
|
||||
|
||||
/** Creates JSON from a SolrInputDocument. Doesn't currently handle boosts.
|
||||
|
|
Loading…
Reference in New Issue