summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorLukas Rytz <lukas.rytz@typesafe.com>2015-09-21 15:55:32 +0200
committerLukas Rytz <lukas.rytz@typesafe.com>2015-09-21 15:55:32 +0200
commit5e8627088ac572bd910e99b04145dd5d2751551f (patch)
treef81d61a08dd53c54ddafd85a5d35cbfdce1f75d0 /test
parent7eadd684678611dc0f6710f9fdd14ff52bf8fb78 (diff)
parentd8d8ba71236bc18d0b4c74f9ebead2973dc6e435 (diff)
downloadscala-5e8627088ac572bd910e99b04145dd5d2751551f.tar.gz
scala-5e8627088ac572bd910e99b04145dd5d2751551f.tar.bz2
scala-5e8627088ac572bd910e99b04145dd5d2751551f.zip
Merge pull request #4725 from retronym/topic/completely-2.11
Topic/completely 2.11
Diffstat (limited to 'test')
-rw-r--r--test/files/jvm/throws-annot-from-java.check8
-rw-r--r--test/files/presentation/callcc-interpreter.check11
-rw-r--r--test/files/run/class-symbol-contravariant.check8
-rw-r--r--test/files/run/constant-type.check8
-rw-r--r--test/files/run/repl-paste-2.check2
-rw-r--r--test/files/run/repl-power.check8
-rw-r--r--test/files/run/repl-transcript.check2
-rw-r--r--test/files/run/t6146b.check8
-rw-r--r--test/files/run/t6439.check8
-rw-r--r--test/files/run/t7747-repl.check8
-rw-r--r--test/files/run/tpeCache-tyconCache.check8
-rw-r--r--test/junit/scala/tools/nsc/interpreter/CompletionTest.scala161
12 files changed, 197 insertions, 43 deletions
diff --git a/test/files/jvm/throws-annot-from-java.check b/test/files/jvm/throws-annot-from-java.check
index ace264a4f5..bf639260e7 100644
--- a/test/files/jvm/throws-annot-from-java.check
+++ b/test/files/jvm/throws-annot-from-java.check
@@ -1,10 +1,8 @@
scala> :power
-** Power User mode enabled - BEEP WHIR GYVE **
-** :phase has been set to 'typer'. **
-** scala.tools.nsc._ has been imported **
-** global._, definitions._ also imported **
-** Try :help, :vals, power.<tab> **
+Power mode enabled. :phase is at typer.
+import scala.tools.nsc._, intp.global._, definitions._
+Try :help or completions for vals._ and power._
scala> :paste
// Entering paste mode (ctrl-D to finish)
diff --git a/test/files/presentation/callcc-interpreter.check b/test/files/presentation/callcc-interpreter.check
index 4bf68b3d4e..94a3d64d68 100644
--- a/test/files/presentation/callcc-interpreter.check
+++ b/test/files/presentation/callcc-interpreter.check
@@ -3,7 +3,7 @@ reload: CallccInterpreter.scala
askTypeCompletion at CallccInterpreter.scala(51,34)
================================================================================
[response] askTypeCompletion at (51,34)
-retrieved 57 members
+retrieved 66 members
abstract trait Term extends AnyRef
abstract trait Value extends AnyRef
case class Add extends callccInterpreter.Term with Product with Serializable
@@ -50,6 +50,15 @@ final def synchronized[T0](x$1: T0): T0
final def wait(): Unit
final def wait(x$1: Long): Unit
final def wait(x$1: Long,x$2: Int): Unit
+object Add
+object App
+object Ccc
+object Con
+object Fun
+object Lam
+object M
+object Num
+object Var
private[this] val term0: callccInterpreter.App
private[this] val term1: callccInterpreter.App
private[this] val term2: callccInterpreter.Add
diff --git a/test/files/run/class-symbol-contravariant.check b/test/files/run/class-symbol-contravariant.check
index 1d95273b50..5166fce96a 100644
--- a/test/files/run/class-symbol-contravariant.check
+++ b/test/files/run/class-symbol-contravariant.check
@@ -1,10 +1,8 @@
scala> :power
-** Power User mode enabled - BEEP WHIR GYVE **
-** :phase has been set to 'typer'. **
-** scala.tools.nsc._ has been imported **
-** global._, definitions._ also imported **
-** Try :help, :vals, power.<tab> **
+Power mode enabled. :phase is at typer.
+import scala.tools.nsc._, intp.global._, definitions._
+Try :help or completions for vals._ and power._
scala> val u = rootMirror.universe
u: $r.intp.global.type = <global>
diff --git a/test/files/run/constant-type.check b/test/files/run/constant-type.check
index b92f1481a3..9df1353354 100644
--- a/test/files/run/constant-type.check
+++ b/test/files/run/constant-type.check
@@ -1,10 +1,8 @@
scala> :power
-** Power User mode enabled - BEEP WHIR GYVE **
-** :phase has been set to 'typer'. **
-** scala.tools.nsc._ has been imported **
-** global._, definitions._ also imported **
-** Try :help, :vals, power.<tab> **
+Power mode enabled. :phase is at typer.
+import scala.tools.nsc._, intp.global._, definitions._
+Try :help or completions for vals._ and power._
scala> val s = transformedType(StringClass.toType).asInstanceOf[Type]
s: $r.intp.global.Type = String
diff --git a/test/files/run/repl-paste-2.check b/test/files/run/repl-paste-2.check
index dbf5363c0f..4c589df41a 100644
--- a/test/files/run/repl-paste-2.check
+++ b/test/files/run/repl-paste-2.check
@@ -1,7 +1,7 @@
scala> scala> 999l
-// Detected repl transcript paste: ctrl-D to finish.
+// Detected repl transcript. Paste more, or ctrl-D to finish.
res4: Int = 0123
diff --git a/test/files/run/repl-power.check b/test/files/run/repl-power.check
index 4e030bd9fa..0d4a30b8e3 100644
--- a/test/files/run/repl-power.check
+++ b/test/files/run/repl-power.check
@@ -1,10 +1,8 @@
scala> :power
-** Power User mode enabled - BEEP WHIR GYVE **
-** :phase has been set to 'typer'. **
-** scala.tools.nsc._ has been imported **
-** global._, definitions._ also imported **
-** Try :help, :vals, power.<tab> **
+Power mode enabled. :phase is at typer.
+import scala.tools.nsc._, intp.global._, definitions._
+Try :help or completions for vals._ and power._
scala> // guarding against "error: reference to global is ambiguous"
diff --git a/test/files/run/repl-transcript.check b/test/files/run/repl-transcript.check
index 762a96b9cc..d0b455cbf6 100644
--- a/test/files/run/repl-transcript.check
+++ b/test/files/run/repl-transcript.check
@@ -1,7 +1,7 @@
scala> scala> class Bippity
-// Detected repl transcript paste: ctrl-D to finish.
+// Detected repl transcript. Paste more, or ctrl-D to finish.
defined class Bippity
diff --git a/test/files/run/t6146b.check b/test/files/run/t6146b.check
index 0e0c216cd7..11149c50fd 100644
--- a/test/files/run/t6146b.check
+++ b/test/files/run/t6146b.check
@@ -4,11 +4,9 @@ It would fail on the following inputs: S2(), S3()
^
scala> :power
-** Power User mode enabled - BEEP WHIR GYVE **
-** :phase has been set to 'typer'. **
-** scala.tools.nsc._ has been imported **
-** global._, definitions._ also imported **
-** Try :help, :vals, power.<tab> **
+Power mode enabled. :phase is at typer.
+import scala.tools.nsc._, intp.global._, definitions._
+Try :help or completions for vals._ and power._
scala> val u = rootMirror.universe; import u._, language._
u: $r.intp.global.type = <global>
diff --git a/test/files/run/t6439.check b/test/files/run/t6439.check
index eee2da1b12..dd7ba9f81d 100644
--- a/test/files/run/t6439.check
+++ b/test/files/run/t6439.check
@@ -48,11 +48,9 @@ scala> type F = Int // no warn
defined type alias F
scala> :power
-** Power User mode enabled - BEEP WHIR GYVE **
-** :phase has been set to 'typer'. **
-** scala.tools.nsc._ has been imported **
-** global._, definitions._ also imported **
-** Try :help, :vals, power.<tab> **
+Power mode enabled. :phase is at typer.
+import scala.tools.nsc._, intp.global._, definitions._
+Try :help or completions for vals._ and power._
scala> object lookup {
import intp._
diff --git a/test/files/run/t7747-repl.check b/test/files/run/t7747-repl.check
index 487daf4878..d698ea668d 100644
--- a/test/files/run/t7747-repl.check
+++ b/test/files/run/t7747-repl.check
@@ -295,11 +295,9 @@ scala> b(a)
res4: String = Found Sum
scala> :power
-** Power User mode enabled - BEEP WHIR GYVE **
-** :phase has been set to 'typer'. **
-** scala.tools.nsc._ has been imported **
-** global._, definitions._ also imported **
-** Try :help, :vals, power.<tab> **
+Power mode enabled. :phase is at typer.
+import scala.tools.nsc._, intp.global._, definitions._
+Try :help or completions for vals._ and power._
scala> intp.lastRequest
res5: $r.intp.Request = Request(line=def $ires3 = intp.global, 1 trees)
diff --git a/test/files/run/tpeCache-tyconCache.check b/test/files/run/tpeCache-tyconCache.check
index ac13d32f91..b26f1ab8a1 100644
--- a/test/files/run/tpeCache-tyconCache.check
+++ b/test/files/run/tpeCache-tyconCache.check
@@ -1,10 +1,8 @@
scala> :power
-** Power User mode enabled - BEEP WHIR GYVE **
-** :phase has been set to 'typer'. **
-** scala.tools.nsc._ has been imported **
-** global._, definitions._ also imported **
-** Try :help, :vals, power.<tab> **
+Power mode enabled. :phase is at typer.
+import scala.tools.nsc._, intp.global._, definitions._
+Try :help or completions for vals._ and power._
scala>
diff --git a/test/junit/scala/tools/nsc/interpreter/CompletionTest.scala b/test/junit/scala/tools/nsc/interpreter/CompletionTest.scala
new file mode 100644
index 0000000000..514f30571e
--- /dev/null
+++ b/test/junit/scala/tools/nsc/interpreter/CompletionTest.scala
@@ -0,0 +1,161 @@
+package scala.tools.nsc.interpreter
+
+import java.io.{StringWriter, PrintWriter}
+
+import org.junit.Assert.assertEquals
+import org.junit.Test
+
+import scala.tools.nsc.Settings
+
+class CompletionTest {
+ val EmptyString = "" // def string results include the empty string so that JLine won't insert "def ..." at the cursor
+
+ def newIMain(): IMain = {
+ val settings = new Settings()
+ settings.Xnojline.value = true
+ settings.usejavacp.value = true
+
+ val writer = new StringWriter
+ val out = new PrintWriter(writer)
+ new IMain(settings, out)
+ }
+ @Test
+ def t4438_arrayCompletion(): Unit = {
+ val intp = newIMain()
+ val completer = new PresentationCompilerCompleter(intp)
+ assert(completer.complete("Array(1, 2, 3) rev").candidates.contains("reverseMap"))
+ }
+
+ @Test
+ def completions(): Unit = {
+ val intp = newIMain()
+ val completer = new PresentationCompilerCompleter(intp)
+ checkExact(completer, "object O { def x_y_z = 1 }; import O._; x_y")("x_y_z")
+ checkExact(completer, "object O { private def x_y_z = 1 }; import O._; x_y")()
+ checkExact(completer, "object O { private def x_y_z = 1; x_y", "}")("x_y_z")
+ checkExact(completer, "object x_y_z; import x_y")("x_y_z")
+
+ checkExact(completer, "object x_y_z { def a_b_c }; import x_y_z.a_b")("a_b_c")
+
+ checkExact(completer, "object X { private[this] def definition = 0; def")("definition")
+
+ // stable terms are offered in type completion as they might be used as a prefix
+ checkExact(completer, """object O { def x_y_z = 0; val x_z_y = ""; type T = x_""")("x_z_y")
+ checkExact(completer, """def method { def x_y_z = 0; val x_z_y = ""; type T = x_""")("x_z_y")
+
+ // We exclude inherited members of the synthetic interpreter wrapper classes
+ checkExact(completer, """asInstanceO""")()
+ checkExact(completer, """class C { asInstanceO""")("asInstanceOf")
+
+ // Output is sorted
+ assertEquals(List("prefix_aaa", "prefix_nnn", "prefix_zzz"), completer.complete( """class C { def prefix_nnn = 0; def prefix_zzz = 0; def prefix_aaa = 0; prefix_""").candidates)
+ }
+
+ @Test
+ def symbolically(): Unit = {
+ val intp = newIMain()
+ val completer = new PresentationCompilerCompleter(intp)
+ checkExact(completer, """class C { def +++(a: Any) = 0; def ---(a: Any) = 0; this.++""")("+++")
+ }
+
+ @Test
+ def camelCompletions(): Unit = {
+ val intp = newIMain()
+ val completer = new PresentationCompilerCompleter(intp)
+ checkExact(completer, "object O { def theCatSatOnTheMat = 1 }; import O._; tCSO")("theCatSatOnTheMat")
+ checkExact(completer, "object O { def getBlerganator = 1 }; import O._; blerga")("getBlerganator")
+ checkExact(completer, "object O { def xxxxYyyyyZzzz = 1; def xxxxYyZeee = 1 }; import O._; xYZ")("", "xxxxYyyyyZzzz", "xxxxYyZeee")
+ checkExact(completer, "object O { def xxxxYyyyyZzzz = 1; def xxxxYyyyyZeee = 1 }; import O._; xYZ")("xxxxYyyyyZzzz", "xxxxYyyyyZeee")
+ checkExact(completer, "object O { class AbstractMetaFactoryFactory }; new O.AMFF")("AbstractMetaFactoryFactory")
+ }
+
+ @Test
+ def lenientCamelCompletions(): Unit = {
+ val intp = newIMain()
+ val completer = new PresentationCompilerCompleter(intp)
+ checkExact(completer, "object O { def theCatSatOnTheMat = 1 }; import O._; tcso")("theCatSatOnTheMat")
+ checkExact(completer, "object O { def theCatSatOnTheMat = 1 }; import O._; sotm")("theCatSatOnTheMat")
+ checkExact(completer, "object O { def theCatSatOnTheMat = 1 }; import O._; TCSOTM")()
+ }
+
+ @Test
+ def previousLineCompletions(): Unit = {
+ val intp = newIMain()
+ intp.interpret("class C { val x_y_z = 42 }")
+ intp.interpret("object O { type T = Int }")
+
+ val completer = new PresentationCompilerCompleter(intp)
+
+ checkExact(completer, "new C().x_y")("x_y_z")
+ checkExact(completer, "(1 : O.T).toCha")("toChar")
+
+ intp.interpret("case class X_y_z()")
+ val completer1 = new PresentationCompilerCompleter(intp)
+ checkExact(completer1, "new X_y_")("X_y_z")
+ checkExact(completer1, "X_y_")("X_y_z")
+ checkExact(completer1, "X_y_z.app")("apply")
+ }
+
+ @Test
+ def previousResultInvocation(): Unit = {
+ val intp = newIMain()
+ intp.interpret("1 + 1")
+
+ val completer = new PresentationCompilerCompleter(intp)
+
+ checkExact(completer, ".toCha")("toChar")
+ }
+
+ @Test
+ def defString(): Unit = {
+ val intp = newIMain()
+ val completer = new PresentationCompilerCompleter(intp)
+
+ // Double Tab on a fully typed selection shows the def string
+ checkExact(completer, "(p: {def a_b_c: Int}) => p.a_b_c")()
+ checkExact(completer, "(p: {def a_b_c: Int}) => p.a_b_c")(EmptyString, "def a_b_c: Int")
+
+ // likewise for an ident
+ checkExact(completer, "(p: {def x_y_z: Int}) => {import p._; x_y_z")()
+ checkExact(completer, "(p: {def x_y_z: Int}) => {import p._; x_y_z")(EmptyString, "def x_y_z: Int")
+
+ // If the first completion only gives one alternative
+ checkExact(completer, "(p: {def x_y_z: Int; def x_y_z(a: String): Int }) => p.x_y")("x_y_z")
+ // ... it is automatically inserted into the buffer. Hitting <TAB> again is triggers the help
+ checkExact(completer, "(p: {def x_y_z: Int; def x_y_z(a: String): Int }) => p.x_y_z")(EmptyString, "def x_y_z(a: String): Int", "def x_y_z: Int")
+
+ checkExact(completer, "(p: {def x_y_z: Int; def x_z_y(a: String): Int }) => p.x_")("x_y_z", "x_z_y")
+ // By contrast, in this case the user had to type "y_z" manually, so no def string printing just yet
+ checkExact(completer, "(p: {def x_y_z: Int; def x_z_y(a: String): Int }) => p.x_y_z")()
+ // Another <TAB>, Okay, time to print.
+ checkExact(completer, "(p: {def x_y_z: Int; def x_z_y(a: String): Int }) => p.x_y_z")(EmptyString, "def x_y_z: Int")
+
+ // The def string reconstructs the source-level modifiers (rather than showing the desugarings of vals),
+ // and performs as-seen-from with respect to the prefix
+ checkExact(completer, "trait T[A]{ lazy val x_y_z: A }; class C extends T[Int] { x_y_z")()
+ checkExact(completer, "trait T[A]{ lazy val x_y_z: A }; class C extends T[Int] { x_y_z")(EmptyString, "lazy val x_y_z: Int")
+
+ checkExact(completer, "trait T[A] { def foo: A }; (t: T[Int]) => t.foo")()
+ checkExact(completer, "trait T[A] { def foo: A }; (t: T[Int]) => t.foo")(EmptyString, "def foo: Int")
+ }
+
+ @Test
+ def treePrint(): Unit = {
+ val intp = newIMain()
+ val completer = new PresentationCompilerCompleter(intp)
+ checkExact(completer, " 1.toHexString //print")(EmptyString, "scala.Predef.intWrapper(1).toHexString // : String")
+ }
+
+ @Test
+ def firstCompletionWithNoPrefixHidesUniversalMethodsAndExtensionMethods(): Unit = {
+ val intp = newIMain()
+ val completer = new PresentationCompilerCompleter(intp)
+ checkExact(completer, "class C(val a: Int, val b: Int) { this.")("a", "b")
+ assert(Set("asInstanceOf", "==").diff(completer.complete("class C(val a: Int, val b: Int) { this.").candidates.toSet).isEmpty)
+ checkExact(completer, "case class D(a: Int, b: Int) { this.a")("a", "asInstanceOf")
+ }
+
+ def checkExact(completer: PresentationCompilerCompleter, before: String, after: String = "")(expected: String*): Unit = {
+ assertEquals(expected.toSet, completer.complete(before, after).candidates.toSet)
+ }
+}