|
|
|
@ -128,16 +128,76 @@ public class Property extends ASTElement |
|
|
|
* whether or not a check was actually applied (i.e. if the result specification is of the |
|
|
|
* form "RESULT: ?") then false is returned; otherwise true. |
|
|
|
* @param result The actual result |
|
|
|
* @param constValues The values of any undefined constants (null or "" if none) |
|
|
|
* @param constValues The values of any undefined constants (null if none) |
|
|
|
* @return Whether or not the check was performed |
|
|
|
*/ |
|
|
|
public boolean checkAgainstExpectedResult(Object result, String constValues) throws PrismException |
|
|
|
public boolean checkAgainstExpectedResult(Object result, Values constValues) throws PrismException |
|
|
|
{ |
|
|
|
String strExpected = getExpectedResultString(constValues); |
|
|
|
return checkAgainstExpectedResultString(strExpected, result); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Get the expected result by extracting from the appropriate RESULT annotation. |
|
|
|
* This is done by finding the first RESULT whose constant values (if any) all match those |
|
|
|
* provided in {@code constValues}. A PrismException is thrown if no matching RESULT is found. |
|
|
|
* @param constValues The values of any undefined constants (null if none) |
|
|
|
*/ |
|
|
|
private String getExpectedResultString(Values constValues) throws PrismException |
|
|
|
{ |
|
|
|
HashMap<String,String> strExpectedMap = new HashMap<String, String>(); |
|
|
|
String strExpected = null; |
|
|
|
|
|
|
|
if (constValues == null) |
|
|
|
constValues = ""; |
|
|
|
// Extract expected result(s) from comment |
|
|
|
if (comment != null) { |
|
|
|
// Look for "RESULT: val" or "RESULT (x=1,y=2): val" |
|
|
|
Pattern p = Pattern.compile("RESULT[ \t]*(\\(([^\\)]+)\\))?[ \t]*:[ \t]*([^ \t\n\r]+)"); |
|
|
|
Matcher matcher = p.matcher(comment); |
|
|
|
// Look at each RESULT specification found |
|
|
|
while (matcher.find()) { |
|
|
|
String constValsSubstring = matcher.group(2) == null ? "" : matcher.group(2); |
|
|
|
boolean match = true; |
|
|
|
// Look at each constant in the list |
|
|
|
String ss[] = constValsSubstring.split(","); |
|
|
|
for (String s : ss) { |
|
|
|
s = s.trim(); |
|
|
|
if (s.length() == 0) |
|
|
|
continue; |
|
|
|
String pair[] = s.split("="); |
|
|
|
if (pair.length != 2) |
|
|
|
throw new PrismException("Badly formed RESULT specification \"" + matcher.group() + "\""); |
|
|
|
// Make sure constant/value is in constValues list and matches |
|
|
|
String constName = pair[0].trim(); |
|
|
|
String constVal = pair[1].trim(); |
|
|
|
Object constValToMatch = constValues.getValueOf(constName); |
|
|
|
// Just check for exact string match for now |
|
|
|
if (constValToMatch == null || !constValToMatch.toString().equals(constVal)) |
|
|
|
match = false; |
|
|
|
} |
|
|
|
// Found it... |
|
|
|
if (match) { |
|
|
|
strExpected = matcher.group(3); |
|
|
|
continue; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
if (strExpected == null) { |
|
|
|
throw new PrismException("Did not find a RESULT specification (for " + constValues + ") to test against"); |
|
|
|
} |
|
|
|
|
|
|
|
return strExpected; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Get the expected result by extracting from the appropriate RESULT annotation. |
|
|
|
* This is done by an exact string match against the provided string of constant values. |
|
|
|
* A PrismException is thrown if no matching RESULT is found. |
|
|
|
* This method actually looks at all RESULTs and complains if there multiple matches. |
|
|
|
* @param constValues The values of any undefined constants (null or "" if none) |
|
|
|
*/ |
|
|
|
private String getExpectedResultString(String constValues) throws PrismException |
|
|
|
{ |
|
|
|
HashMap<String, String> strExpectedMap = new HashMap<String, String>(); |
|
|
|
String strExpected = null; |
|
|
|
|
|
|
|
// Extract expected result(s) from comment |
|
|
|
if (comment != null) { |
|
|
|
@ -166,7 +226,7 @@ public class Property extends ASTElement |
|
|
|
throw new PrismException("Did not find a RESULT specification (for " + constValues + ") to test against"); |
|
|
|
} |
|
|
|
|
|
|
|
return checkAgainstExpectedResultString(strExpected, result); |
|
|
|
return strExpected; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
@ -305,7 +365,7 @@ public class Property extends ASTElement |
|
|
|
// Note: don't print comment |
|
|
|
String s = ""; |
|
|
|
//if (comment != null) |
|
|
|
//s += PrismParser.slashCommentBlock(comment); |
|
|
|
//s += PrismParser.slashCommentBlock(comment); |
|
|
|
if (name != null) |
|
|
|
s += "\"" + name + "\": "; |
|
|
|
s += expr; |
|
|
|
|