Skip to content

Commit

Permalink
simplify input extraction in repl tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rethab committed May 25, 2020
1 parent dec9280 commit 8a58598
Showing 1 changed file with 4 additions and 20 deletions.
24 changes: 4 additions & 20 deletions compiler/test/dotty/tools/repl/ReplTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -58,20 +58,6 @@ class ReplTest(withStaging: Boolean = false, out: ByteArrayOutputStream = new By
def testFile(f: JFile): Unit = {
val prompt = "scala>"

def extractInputs(lines: BufferedIterator[String]): List[String] = {
val input = lines.next()

if (!input.startsWith(prompt)) extractInputs(lines)
else if (lines.hasNext) {
// read lines and strip trailing whitespace:
while (lines.hasNext && !lines.head.startsWith(prompt))
lines.next()

input :: { if (lines.hasNext) extractInputs(lines) else Nil }
}
else Nil
}

def evaluate(state: State, input: String) =
try {
val nstate = run(input.drop(prompt.length))(state)
Expand All @@ -95,12 +81,10 @@ class ReplTest(withStaging: Boolean = false, out: ByteArrayOutputStream = new By
val actualOutput = {
resetToInitial()

val inputRes = Using(Source.fromFile(f, "UTF-8")) { source =>
val lines = source.getLines.buffered
assert(lines.head.startsWith(prompt),
s"""Each file has to start with the prompt: "$prompt"""")
extractInputs(lines)
}.get
val lines = Using(Source.fromFile(f, "UTF-8"))(_.getLines.toList).get
assert(lines.head.startsWith(prompt),
s"""Each file has to start with the prompt: "$prompt"""")
val inputRes = lines.filter(_.startsWith(prompt))

val buf = new ArrayBuffer[String]
inputRes.foldLeft(initialState) { (state, input) =>
Expand Down

0 comments on commit 8a58598

Please sign in to comment.