From c873806b5490816c450333247c5f9980a0f8a393 Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Sun, 27 Jul 2014 23:11:45 +0200 Subject: [PATCH] Refactor "incomplete line" handling in REPL tests --- compiler/testData/repl/multiline.repl | 3 +-- compiler/testData/repl/multiline3.repl | 9 +++----- .../jet/repl/AbstractReplInterpreterTest.kt | 22 +++++++++++++++---- 3 files changed, 22 insertions(+), 12 deletions(-) diff --git a/compiler/testData/repl/multiline.repl b/compiler/testData/repl/multiline.repl index 978e8665188..ba98846dbdf 100644 --- a/compiler/testData/repl/multiline.repl +++ b/compiler/testData/repl/multiline.repl @@ -1,5 +1,4 @@ >>> fun clock() = -incomplete ->>> 12 +... 12 >>> clock() 12 diff --git a/compiler/testData/repl/multiline3.repl b/compiler/testData/repl/multiline3.repl index b39c5414a37..927993c270e 100644 --- a/compiler/testData/repl/multiline3.repl +++ b/compiler/testData/repl/multiline3.repl @@ -1,9 +1,6 @@ >>> fun get7() = -incomplete ->>> 4 + -incomplete ->>> 2 + -incomplete ->>> 1 +... 4 + +... 2 + +... 1 >>> get7() 7 diff --git a/compiler/tests/org/jetbrains/jet/repl/AbstractReplInterpreterTest.kt b/compiler/tests/org/jetbrains/jet/repl/AbstractReplInterpreterTest.kt index 5cf48730728..7867b97a14a 100644 --- a/compiler/tests/org/jetbrains/jet/repl/AbstractReplInterpreterTest.kt +++ b/compiler/tests/org/jetbrains/jet/repl/AbstractReplInterpreterTest.kt @@ -29,8 +29,11 @@ import java.util.regex.Pattern import org.junit.Assert private val START_PATTERN = Pattern.compile(">>>( *)(.*)$") +private val INCOMPLETE_PATTERN = Pattern.compile("\\.\\.\\.( *)(.*)$") private val SUBSTRING_PATTERN = Pattern.compile("substring: (.*)") +private val INCOMPLETE_LINE_MESSAGE = "incomplete line" + public abstract class AbstractReplInterpreterTest : UsefulTestCase() { { System.setProperty("java.awt.headless", "true") @@ -50,17 +53,28 @@ public abstract class AbstractReplInterpreterTest : UsefulTestCase() { while (lines.isNotEmpty()) { val line = lines.poll()!! - val matcher = START_PATTERN.matcher(line) - assert(matcher.matches()) { "Line doesn't match start pattern: $line" } + var matcher = START_PATTERN.matcher(line) + if (!matcher.matches()) { + matcher = INCOMPLETE_PATTERN.matcher(line) + } + assert(matcher.matches()) { "Line doesn't begin with \">>>\" or \"...\": $line" } val code = matcher.group(2)!! if (lines.isNotEmpty()) { - val substringMatcher = SUBSTRING_PATTERN.matcher(lines.peek()!!) + val nextLine = lines.peek()!! + + val substringMatcher = SUBSTRING_PATTERN.matcher(nextLine) if (substringMatcher.matches()) { result.add(OneLine(code, substringMatcher.group(1)!!, MatchType.SUBSTRING)) lines.poll() continue } + + val incompleteMatcher = INCOMPLETE_PATTERN.matcher(nextLine) + if (incompleteMatcher.matches()) { + result.add(OneLine(code, INCOMPLETE_LINE_MESSAGE, MatchType.EQUALS)) + continue + } } val value = StringBuilder() @@ -85,7 +99,7 @@ public abstract class AbstractReplInterpreterTest : UsefulTestCase() { val actual = when (lineResult.getType()) { ReplInterpreter.LineResultType.SUCCESS -> lineResult.getValue()?.toString() ?: "" ReplInterpreter.LineResultType.ERROR -> lineResult.getErrorText() - ReplInterpreter.LineResultType.INCOMPLETE -> "incomplete" + ReplInterpreter.LineResultType.INCOMPLETE -> INCOMPLETE_LINE_MESSAGE } val actualString = StringUtil.convertLineSeparators(actual).replaceFirst("\n$", "")