aboutsummaryrefslogtreecommitdiff
path: root/tests/run/implicitFuns.scala
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2016-12-05 15:16:27 +0100
committerMartin Odersky <odersky@gmail.com>2016-12-17 18:34:27 +0100
commit43d69ccf3e496c7c02c5dcc40efd2a5e83f6f79c (patch)
tree0c1ad0fe88978ba3fb0917ef78ee2cb4a673389c /tests/run/implicitFuns.scala
parentb804d9167a79fc6330ad4a193685da95c6ef9bca (diff)
downloaddotty-43d69ccf3e496c7c02c5dcc40efd2a5e83f6f79c.tar.gz
dotty-43d69ccf3e496c7c02c5dcc40efd2a5e83f6f79c.tar.bz2
dotty-43d69ccf3e496c7c02c5dcc40efd2a5e83f6f79c.zip
Enrich test case
Run a typical dotty compiler scenario with implicit contexts.
Diffstat (limited to 'tests/run/implicitFuns.scala')
-rw-r--r--tests/run/implicitFuns.scala41
1 files changed, 41 insertions, 0 deletions
diff --git a/tests/run/implicitFuns.scala b/tests/run/implicitFuns.scala
index 79f0632d2..ded1b0c29 100644
--- a/tests/run/implicitFuns.scala
+++ b/tests/run/implicitFuns.scala
@@ -51,5 +51,46 @@ object Test {
val c = xx("hh", 22)
val c1: Int = c
+
+ Contextual.main(args)
+ }
+}
+
+object Contextual {
+
+ class Key[+V]
+
+ class Context(bindings: Map[Key[Any], Any]) {
+ def binding[V](key: Key[V]): Option[V] =
+ bindings.get(key).asInstanceOf[Option[V]]
+ def withBinding[V](key: Key[V], value: V): Context =
+ new Context(bindings + ((key, value)))
+ }
+
+ val rootContext = new Context(Map())
+
+ val Source = new Key[String]
+ val Options = new Key[List[String]]
+
+ type Ctx[T] = implicit Context => T
+
+ def ctx: Ctx[Context] = implicitly[Context]
+
+ def compile(s: String): Ctx[Boolean] =
+ runOn(new java.io.File(s))(ctx.withBinding(Source, s)) >= 0
+
+ def runOn(f: java.io.File): Ctx[Int] = {
+ val options = List("-verbose", "-explaintypes")
+ process(f)(ctx.withBinding(Options, options))
+ }
+
+ def process(f: java.io.File): Ctx[Int] =
+ ctx.binding(Source).get.length - ctx.binding(Options).get.length
+
+ def main(args: Array[String]) = {
+ implicit val context: Context = rootContext
+ assert(compile("abc"))
+ assert(compile("ab"))
+ assert(!compile("a"))
}
}