Refactor "incomplete line" handling in REPL tests
This commit is contained in:
@@ -1,5 +1,4 @@
|
|||||||
>>> fun clock() =
|
>>> fun clock() =
|
||||||
incomplete
|
... 12
|
||||||
>>> 12
|
|
||||||
>>> clock()
|
>>> clock()
|
||||||
12
|
12
|
||||||
|
|||||||
@@ -1,9 +1,6 @@
|
|||||||
>>> fun get7() =
|
>>> fun get7() =
|
||||||
incomplete
|
... 4 +
|
||||||
>>> 4 +
|
... 2 +
|
||||||
incomplete
|
... 1
|
||||||
>>> 2 +
|
|
||||||
incomplete
|
|
||||||
>>> 1
|
|
||||||
>>> get7()
|
>>> get7()
|
||||||
7
|
7
|
||||||
|
|||||||
@@ -29,8 +29,11 @@ import java.util.regex.Pattern
|
|||||||
import org.junit.Assert
|
import org.junit.Assert
|
||||||
|
|
||||||
private val START_PATTERN = Pattern.compile(">>>( *)(.*)$")
|
private val START_PATTERN = Pattern.compile(">>>( *)(.*)$")
|
||||||
|
private val INCOMPLETE_PATTERN = Pattern.compile("\\.\\.\\.( *)(.*)$")
|
||||||
private val SUBSTRING_PATTERN = Pattern.compile("substring: (.*)")
|
private val SUBSTRING_PATTERN = Pattern.compile("substring: (.*)")
|
||||||
|
|
||||||
|
private val INCOMPLETE_LINE_MESSAGE = "incomplete line"
|
||||||
|
|
||||||
public abstract class AbstractReplInterpreterTest : UsefulTestCase() {
|
public abstract class AbstractReplInterpreterTest : UsefulTestCase() {
|
||||||
{
|
{
|
||||||
System.setProperty("java.awt.headless", "true")
|
System.setProperty("java.awt.headless", "true")
|
||||||
@@ -50,17 +53,28 @@ public abstract class AbstractReplInterpreterTest : UsefulTestCase() {
|
|||||||
|
|
||||||
while (lines.isNotEmpty()) {
|
while (lines.isNotEmpty()) {
|
||||||
val line = lines.poll()!!
|
val line = lines.poll()!!
|
||||||
val matcher = START_PATTERN.matcher(line)
|
var matcher = START_PATTERN.matcher(line)
|
||||||
assert(matcher.matches()) { "Line doesn't match start pattern: $line" }
|
if (!matcher.matches()) {
|
||||||
|
matcher = INCOMPLETE_PATTERN.matcher(line)
|
||||||
|
}
|
||||||
|
assert(matcher.matches()) { "Line doesn't begin with \">>>\" or \"...\": $line" }
|
||||||
val code = matcher.group(2)!!
|
val code = matcher.group(2)!!
|
||||||
|
|
||||||
if (lines.isNotEmpty()) {
|
if (lines.isNotEmpty()) {
|
||||||
val substringMatcher = SUBSTRING_PATTERN.matcher(lines.peek()!!)
|
val nextLine = lines.peek()!!
|
||||||
|
|
||||||
|
val substringMatcher = SUBSTRING_PATTERN.matcher(nextLine)
|
||||||
if (substringMatcher.matches()) {
|
if (substringMatcher.matches()) {
|
||||||
result.add(OneLine(code, substringMatcher.group(1)!!, MatchType.SUBSTRING))
|
result.add(OneLine(code, substringMatcher.group(1)!!, MatchType.SUBSTRING))
|
||||||
lines.poll()
|
lines.poll()
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val incompleteMatcher = INCOMPLETE_PATTERN.matcher(nextLine)
|
||||||
|
if (incompleteMatcher.matches()) {
|
||||||
|
result.add(OneLine(code, INCOMPLETE_LINE_MESSAGE, MatchType.EQUALS))
|
||||||
|
continue
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val value = StringBuilder()
|
val value = StringBuilder()
|
||||||
@@ -85,7 +99,7 @@ public abstract class AbstractReplInterpreterTest : UsefulTestCase() {
|
|||||||
val actual = when (lineResult.getType()) {
|
val actual = when (lineResult.getType()) {
|
||||||
ReplInterpreter.LineResultType.SUCCESS -> lineResult.getValue()?.toString() ?: ""
|
ReplInterpreter.LineResultType.SUCCESS -> lineResult.getValue()?.toString() ?: ""
|
||||||
ReplInterpreter.LineResultType.ERROR -> lineResult.getErrorText()
|
ReplInterpreter.LineResultType.ERROR -> lineResult.getErrorText()
|
||||||
ReplInterpreter.LineResultType.INCOMPLETE -> "incomplete"
|
ReplInterpreter.LineResultType.INCOMPLETE -> INCOMPLETE_LINE_MESSAGE
|
||||||
}
|
}
|
||||||
val actualString = StringUtil.convertLineSeparators(actual).replaceFirst("\n$", "")
|
val actualString = StringUtil.convertLineSeparators(actual).replaceFirst("\n$", "")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user