summaryrefslogtreecommitdiff
path: root/src/repl/scala/tools
diff options
context:
space:
mode:
authorSom Snytt <som.snytt@gmail.com>2015-02-25 20:33:20 -0800
committerSom Snytt <som.snytt@gmail.com>2015-03-03 08:10:45 -0800
commita180f5f24f2094112a01cdb02e0e8f218db68d70 (patch)
treeb0a2541bf71bce34177f26c72b414902d21ccda3 /src/repl/scala/tools
parent3a32ae3651f69237bde32598674bc135ad9e4064 (diff)
downloadscala-a180f5f24f2094112a01cdb02e0e8f218db68d70.tar.gz
scala-a180f5f24f2094112a01cdb02e0e8f218db68d70.tar.bz2
scala-a180f5f24f2094112a01cdb02e0e8f218db68d70.zip
SI-9170 More flexible SessionTest
SessionTest session text can include line continuations and pasted text. Pasted script (which looks like a double prompt) probably doesn't work. This commit includes @retronym's SI-9170 one-liner.
Diffstat (limited to 'src/repl/scala/tools')
-rw-r--r--src/repl/scala/tools/nsc/interpreter/ILoop.scala23
1 files changed, 14 insertions, 9 deletions
diff --git a/src/repl/scala/tools/nsc/interpreter/ILoop.scala b/src/repl/scala/tools/nsc/interpreter/ILoop.scala
index 4d71e0e09e..4221126caa 100644
--- a/src/repl/scala/tools/nsc/interpreter/ILoop.scala
+++ b/src/repl/scala/tools/nsc/interpreter/ILoop.scala
@@ -937,25 +937,30 @@ object ILoop {
// Designed primarily for use by test code: take a String with a
// bunch of code, and prints out a transcript of what it would look
// like if you'd just typed it into the repl.
- def runForTranscript(code: String, settings: Settings): String = {
+ def runForTranscript(code: String, settings: Settings, inSession: Boolean = false): String = {
import java.io.{ BufferedReader, StringReader, OutputStreamWriter }
stringFromStream { ostream =>
Console.withOut(ostream) {
val output = new JPrintWriter(new OutputStreamWriter(ostream), true) {
- override def write(str: String) = {
- // completely skip continuation lines
- if (str forall (ch => ch.isWhitespace || ch == '|')) ()
+ // skip margin prefix for continuation lines, unless preserving session text for test
+ override def write(str: String) =
+ if (!inSession && (str forall (ch => ch.isWhitespace || ch == '|'))) () // repl.paste.ContinueString
else super.write(str)
- }
}
val input = new BufferedReader(new StringReader(code.trim + "\n")) {
override def readLine(): String = {
- val s = super.readLine()
- // helping out by printing the line being interpreted.
- if (s != null)
+ mark(1) // default buffer is 8k
+ val c = read()
+ if (c == -1 || c == 4) {
+ null
+ } else {
+ reset()
+ val s = super.readLine()
+ // helping out by printing the line being interpreted.
output.println(s)
- s
+ s
+ }
}
}
val repl = new ILoop(input, output)