diff options
Diffstat (limited to 'test/files/run')
-rw-r--r-- | test/files/run/t5733.check | 2 | ||||
-rw-r--r-- | test/files/run/t5733.scala | 53 | ||||
-rw-r--r-- | test/files/run/t6320.check | 17 | ||||
-rw-r--r-- | test/files/run/t6320.scala | 9 |
4 files changed, 81 insertions, 0 deletions
diff --git a/test/files/run/t5733.check b/test/files/run/t5733.check new file mode 100644 index 0000000000..e697046a94 --- /dev/null +++ b/test/files/run/t5733.check @@ -0,0 +1,2 @@ +Running ABTest asserts +Done diff --git a/test/files/run/t5733.scala b/test/files/run/t5733.scala new file mode 100644 index 0000000000..360264e4ed --- /dev/null +++ b/test/files/run/t5733.scala @@ -0,0 +1,53 @@ +import scala.language.dynamics + +object A extends Dynamic { + var a = "a" + + def selectDynamic(method:String): String = a + + def updateDynamic(method:String)(v:String) { a = v } +} + +class B extends Dynamic { + var b = "b" + + def selectDynamic(method:String): String = b + + def updateDynamic(method:String)(v:String) { b = v } +} + +object Test extends App { + assert( A.foo == "a" ) + assert( A.bar == "a" ) + A.aaa = "aaa" + assert( A.bar == "aaa" ) + + val b = new B + assert( b.foo == "b" ) + assert( b.bar == "b" ) + b.bbb = "bbb" + assert( b.bar == "bbb" ) + + { + println("Running ABTest asserts") + A.a = "a" + (new ABTest).test() + } + + println("Done") +} + +class ABTest { + def test() { + assert( A.foo == "a" ) + assert( A.bar == "a" ) + A.aaa = "aaa" + assert( A.bar == "aaa" ) + + val b = new B + assert( b.foo == "b" ) + assert( b.bar == "b" ) + b.bbb = "bbb" + assert( b.bar == "bbb" ) + } +} diff --git a/test/files/run/t6320.check b/test/files/run/t6320.check new file mode 100644 index 0000000000..e56bacd223 --- /dev/null +++ b/test/files/run/t6320.check @@ -0,0 +1,17 @@ +Type in expressions to have them evaluated. +Type :help for more information. + +scala> + +scala> import scala.language.dynamics +import scala.language.dynamics + +scala> class Dyn(m: Map[String, Any]) extends Dynamic { def selectDynamic[T](s: String): T = m(s).asInstanceOf[T] } +defined class Dyn + +scala> new Dyn(Map("foo" -> 10)).foo[Int] +res0: Int = 10 + +scala> + +scala> diff --git a/test/files/run/t6320.scala b/test/files/run/t6320.scala new file mode 100644 index 0000000000..26085a3d7d --- /dev/null +++ b/test/files/run/t6320.scala @@ -0,0 +1,9 @@ +import scala.tools.partest.ReplTest + +object Test extends ReplTest { + def code = """ +import scala.language.dynamics +class Dyn(m: Map[String, Any]) extends Dynamic { def selectDynamic[T](s: String): T = m(s).asInstanceOf[T] } +new Dyn(Map("foo" -> 10)).foo[Int] + """ +} |