271 assertCommand(after, cmd, "| Resetting state.\n"); |
271 assertCommand(after, cmd, "| Resetting state.\n"); |
272 initSnippets(); |
272 initSnippets(); |
273 } |
273 } |
274 |
274 |
275 public void evaluateExpression(boolean after, String type, String expr, String value) { |
275 public void evaluateExpression(boolean after, String type, String expr, String value) { |
276 String output = String.format("\\| *Expression values is: %s\n|" + |
276 String output = String.format("(\\$\\d+) ==> %s", value); |
277 " *.*temporary variable (\\$\\d+) of type %s", value, type); |
|
278 Pattern outputPattern = Pattern.compile(output); |
277 Pattern outputPattern = Pattern.compile(output); |
279 assertCommandCheckOutput(after, expr, s -> { |
278 assertCommandCheckOutput(after, expr, s -> { |
280 Matcher matcher = outputPattern.matcher(s); |
279 Matcher matcher = outputPattern.matcher(s); |
281 assertTrue(matcher.find(), "Output: '" + s + "' does not fit pattern: '" + output + "'"); |
280 assertTrue(matcher.find(), "Output: '" + s + "' does not fit pattern: '" + output + "'"); |
282 String name = matcher.group(1); |
281 String name = matcher.group(1); |
556 this.initialValue = value; |
555 this.initialValue = value; |
557 } |
556 } |
558 |
557 |
559 @Override |
558 @Override |
560 public Consumer<String> checkOutput() { |
559 public Consumer<String> checkOutput() { |
561 String pattern = String.format("\\| *\\w+ variable %s of type %s", name, type); |
560 String arrowPattern = String.format("%s ==> %s", name, value); |
562 if (initialValue != null) { |
561 Predicate<String> arrowCheckOutput = Pattern.compile(arrowPattern).asPredicate(); |
563 pattern += " with initial value " + initialValue; |
562 String howeverPattern = String.format("\\| *\\w+ variable %s, however*.", name); |
564 } |
563 Predicate<String> howeverCheckOutput = Pattern.compile(howeverPattern).asPredicate(); |
565 Predicate<String> checkOutput = Pattern.compile(pattern).asPredicate(); |
564 return output -> { |
566 final String finalPattern = pattern; |
565 if (output.startsWith("| ")) { |
567 return output -> assertTrue(checkOutput.test(output), |
566 assertTrue(howeverCheckOutput.test(output), |
568 "Output: " + output + " does not fit pattern: " + finalPattern); |
567 "Output: " + output + " does not fit pattern: " + howeverPattern); |
|
568 } else { |
|
569 assertTrue(arrowCheckOutput.test(output), |
|
570 "Output: " + output + " does not fit pattern: " + arrowPattern); |
|
571 } |
|
572 }; |
569 } |
573 } |
570 |
574 |
571 @Override |
575 @Override |
572 public int hashCode() { |
576 public int hashCode() { |
573 return name.hashCode(); |
577 return name.hashCode(); |