Skip to content

Commit 8a58598

Browse files
committed
simplify input extraction in repl tests
1 parent dec9280 commit 8a58598

File tree

1 file changed

+4
-20
lines changed

1 file changed

+4
-20
lines changed

compiler/test/dotty/tools/repl/ReplTest.scala

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -58,20 +58,6 @@ class ReplTest(withStaging: Boolean = false, out: ByteArrayOutputStream = new By
5858
def testFile(f: JFile): Unit = {
5959
val prompt = "scala>"
6060

61-
def extractInputs(lines: BufferedIterator[String]): List[String] = {
62-
val input = lines.next()
63-
64-
if (!input.startsWith(prompt)) extractInputs(lines)
65-
else if (lines.hasNext) {
66-
// read lines and strip trailing whitespace:
67-
while (lines.hasNext && !lines.head.startsWith(prompt))
68-
lines.next()
69-
70-
input :: { if (lines.hasNext) extractInputs(lines) else Nil }
71-
}
72-
else Nil
73-
}
74-
7561
def evaluate(state: State, input: String) =
7662
try {
7763
val nstate = run(input.drop(prompt.length))(state)
@@ -95,12 +81,10 @@ class ReplTest(withStaging: Boolean = false, out: ByteArrayOutputStream = new By
9581
val actualOutput = {
9682
resetToInitial()
9783

98-
val inputRes = Using(Source.fromFile(f, "UTF-8")) { source =>
99-
val lines = source.getLines.buffered
100-
assert(lines.head.startsWith(prompt),
101-
s"""Each file has to start with the prompt: "$prompt"""")
102-
extractInputs(lines)
103-
}.get
84+
val lines = Using(Source.fromFile(f, "UTF-8"))(_.getLines.toList).get
85+
assert(lines.head.startsWith(prompt),
86+
s"""Each file has to start with the prompt: "$prompt"""")
87+
val inputRes = lines.filter(_.startsWith(prompt))
10488

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

0 commit comments

Comments
 (0)