diff options
Diffstat (limited to 'test/files')
-rw-r--r-- | test/files/jvm/interpreter.check | 6 | ||||
-rw-r--r-- | test/files/jvm/interpreter.scala | 158 | ||||
-rw-r--r-- | test/files/run/bug4710.check | 7 | ||||
-rw-r--r-- | test/files/run/bug4710.scala | 6 | ||||
-rw-r--r-- | test/files/run/constrained-types.scala | 5 | ||||
-rw-r--r-- | test/files/run/repl-bare-expr.check | 36 | ||||
-rw-r--r-- | test/files/run/repl-bare-expr.scala | 16 | ||||
-rw-r--r-- | test/files/run/repl-colon-type.check | 57 | ||||
-rw-r--r-- | test/files/run/repl-colon-type.scala | 23 | ||||
-rw-r--r-- | test/files/run/repl-parens.check | 58 | ||||
-rw-r--r-- | test/files/run/repl-parens.scala | 26 | ||||
-rw-r--r-- | test/files/run/repl-paste-2.check | 3 | ||||
-rw-r--r-- | test/files/run/repl-power.check | 17 | ||||
-rw-r--r-- | test/files/run/repl-power.scala | 10 | ||||
-rw-r--r-- | test/files/run/repl-transcript.check | 3 |
15 files changed, 424 insertions, 7 deletions
diff --git a/test/files/jvm/interpreter.check b/test/files/jvm/interpreter.check index dd0f39551c..42a8ae8855 100644 --- a/test/files/jvm/interpreter.check +++ b/test/files/jvm/interpreter.check @@ -13,7 +13,7 @@ scala> def gcd(x: Int, y: Int): Int = { else if (y == 0) x else gcd(y%x, x) } -gcd: (x: Int,y: Int)Int +gcd: (x: Int, y: Int)Int scala> val five = gcd(15,35) five: Int = 5 @@ -370,5 +370,5 @@ plusOne: (x: Int)Int res0: Int = 6 res1: java.lang.String = after reset <console>:8: error: not found: value plusOne - plusOne(5) // should be undefined now - ^ + plusOne(5) // should be undefined now + ^ diff --git a/test/files/jvm/interpreter.scala b/test/files/jvm/interpreter.scala new file mode 100644 index 0000000000..752a129950 --- /dev/null +++ b/test/files/jvm/interpreter.scala @@ -0,0 +1,158 @@ +import scala.tools.nsc._ +import scala.tools.partest.ReplTest + +object Test extends ReplTest { + def code = <code> +// basics +3+4 +def gcd(x: Int, y: Int): Int = {{ + if (x == 0) y + else if (y == 0) x + else gcd(y%x, x) +}} +val five = gcd(15,35) +var x = 1 +x = 2 +val three = x+1 +type anotherint = Int +val four: anotherint = 4 +val bogus: anotherint = "hello" +trait PointlessTrait +val (x,y) = (2,3) +println("hello") + +// ticket #1513 +val t1513 = Array(null) +// ambiguous toString problem from #547 +val atom = new scala.xml.Atom() +// overriding toString problem from #1404 +class S(override val toString : String) +val fish = new S("fish") +// Test that arrays pretty print nicely. +val arr = Array("What's", "up", "doc?") +// Test that arrays pretty print nicely, even when we give them type Any +val arrInt : Any = Array(1,2,3) +// Test that nested arrays are pretty-printed correctly +val arrArrInt : Any = Array(Array(1, 2), Array(3, 4)) + +// implicit conversions +case class Foo(n: Int) +case class Bar(n: Int) +implicit def foo2bar(foo: Foo) = Bar(foo.n) +val bar: Bar = Foo(3) + +// importing from a previous result +import bar._ +val m = n + +// stressing the imports mechanism +val one = 1 +val one = 1 +val one = 1 +val one = 1 +val one = 1 +val one = 1 +val one = 1 +val one = 1 +val one = 1 +val one = 1 +val one = 1 +val one = 1 +val one = 1 +val one = 1 +val one = 1 +val one = 1 +val one = 1 +val one = 1 +val one = 1 +val one = 1 + + +val x1 = 1 +val x2 = 1 +val x3 = 1 +val x4 = 1 +val x5 = 1 +val x6 = 1 +val x7 = 1 +val x8 = 1 +val x9 = 1 +val x10 = 1 +val x11 = 1 +val x12 = 1 +val x13 = 1 +val x14 = 1 +val x15 = 1 +val x16 = 1 +val x17 = 1 +val x18 = 1 +val x19 = 1 +val x20 = 1 + +val two = one + x5 + +// handling generic wildcard arrays (#2386) +// It's put here because type feedback is an important part of it. +val xs: Array[_] = Array(1, 2) +xs.size +xs.head +xs filter (_ == 2) +xs map (_ => "abc") +xs map (x => x) +xs map (x => (x, x)) + +// interior syntax errors should *not* go into multi-line input mode. +// both of the following should abort immediately: +def x => y => z +[1,2,3] + + +// multi-line XML +<a> +<b + c="c" + d="dd" +/></a> + + +/* + /* + multi-line comment + */ +*/ + + +// multi-line string +""" +hello +there +""" + +(1 + // give up early by typing two blank lines + + +// defining and using quoted names should work (ticket #323) +def `match` = 1 +val x = `match` + +// multiple classes defined on one line +sealed class Exp; class Fact extends Exp; class Term extends Exp +def f(e: Exp) = e match {{ // non-exhaustive warning here + case _:Fact => 3 +}} + +</code>.text + + def appendix() = { + val settings = new Settings + settings.classpath.value = sys.props("java.class.path") + val interp = new Interpreter(settings) + interp.interpret("def plusOne(x: Int) = x + 1") + interp.interpret("plusOne(5)") + interp.reset() + interp.interpret("\"after reset\"") + interp.interpret("plusOne(5) // should be undefined now") + } + + appendix() +} diff --git a/test/files/run/bug4710.check b/test/files/run/bug4710.check new file mode 100644 index 0000000000..aa2f08d452 --- /dev/null +++ b/test/files/run/bug4710.check @@ -0,0 +1,7 @@ +Type in expressions to have them evaluated. +Type :help for more information. + +scala> def method : String = { implicit def f(s: Symbol) = "" ; 'symbol } +method: String + +scala> diff --git a/test/files/run/bug4710.scala b/test/files/run/bug4710.scala new file mode 100644 index 0000000000..5e5b1e86b5 --- /dev/null +++ b/test/files/run/bug4710.scala @@ -0,0 +1,6 @@ +import scala.tools.partest.ReplTest + +object Test extends ReplTest { + def code = """def method : String = { implicit def f(s: Symbol) = "" ; 'symbol }""" +} + diff --git a/test/files/run/constrained-types.scala b/test/files/run/constrained-types.scala index 5f7eb7adde..91bd856d00 100644 --- a/test/files/run/constrained-types.scala +++ b/test/files/run/constrained-types.scala @@ -79,15 +79,12 @@ val x : Int @Where(self > 0 && self < 100) = 3 """ - override def settings: Settings = { - val s = new Settings - + override def transformSettings(s: Settings): Settings = { s.Xexperimental.value = true s.selfInAnnots.value = true s.deprecation.value = true // when running that compiler, give it a scala-library to the classpath s.classpath.value = sys.props("java.class.path") - s } } diff --git a/test/files/run/repl-bare-expr.check b/test/files/run/repl-bare-expr.check new file mode 100644 index 0000000000..04daa48232 --- /dev/null +++ b/test/files/run/repl-bare-expr.check @@ -0,0 +1,36 @@ +Type in expressions to have them evaluated. +Type :help for more information. + +scala> + +scala> 2 ; 3 +res0: Int = 3 + +scala> { 2 ; 3 } +res1: Int = 3 + +scala> 5 ; 10 ; case object Cow ; 20 ; class Moo { override def toString = "Moooooo" } ; 30 ; def bippy = { + 1 + + 2 + + 3 } ; bippy+88+11 +defined module Cow +defined class Moo +bippy: Int +res2: Int = 105 + +scala> + +scala> object Bovine { var x: List[_] = null } ; case class Ruminant(x: Int) ; bippy * bippy * bippy +defined module Bovine +defined class Ruminant +res3: Int = 216 + +scala> Bovine.x = List(Ruminant(5), Cow, new Moo) +Bovine.x: List[Any] = List(Ruminant(5), Cow, Moooooo) + +scala> Bovine.x +res4: List[Any] = List(Ruminant(5), Cow, Moooooo) + +scala> + +scala> diff --git a/test/files/run/repl-bare-expr.scala b/test/files/run/repl-bare-expr.scala new file mode 100644 index 0000000000..df9849fa6d --- /dev/null +++ b/test/files/run/repl-bare-expr.scala @@ -0,0 +1,16 @@ +import scala.tools.partest.ReplTest + +object Test extends ReplTest { + def code = """ +2 ; 3 +{ 2 ; 3 } +5 ; 10 ; case object Cow ; 20 ; class Moo { override def toString = "Moooooo" } ; 30 ; def bippy = { + 1 + + 2 + + 3 } ; bippy+88+11 + +object Bovine { var x: List[_] = null } ; case class Ruminant(x: Int) ; bippy * bippy * bippy +Bovine.x = List(Ruminant(5), Cow, new Moo) +Bovine.x + """ +}
\ No newline at end of file diff --git a/test/files/run/repl-colon-type.check b/test/files/run/repl-colon-type.check new file mode 100644 index 0000000000..66c2fcc77f --- /dev/null +++ b/test/files/run/repl-colon-type.check @@ -0,0 +1,57 @@ +Type in expressions to have them evaluated. +Type :help for more information. + +scala> + +scala> :type List[1, 2, 3] +<console>:2: error: identifier expected but integer literal found. + List[1, 2, 3] + ^ + + +scala> :type List(1, 2, 3) +List[Int] + +scala> :type def foo[T](x: T) = List(x) +[T](x: T)List[T] + +scala> :type val bar = List(Set(1)) +List[scala.collection.immutable.Set[Int]] + +scala> :type lazy val bar = Set(Set(1)) +scala.collection.immutable.Set[scala.collection.immutable.Set[Int]] + +scala> :type def f[T >: Null, U <: String](x: T, y: U) = Set(x, y) +[T >: Null, U <: String](x: T, y: U)scala.collection.immutable.Set[Any] + +scala> :type def x = 1 ; def bar[T >: Null <: AnyRef](xyz: T) = 5 +[T >: Null <: AnyRef](xyz: T)Int + +scala> + +scala> :type 5 +Int + +scala> :type val f = 5 +Int + +scala> :type lazy val f = 5 +Int + +scala> :type protected lazy val f = 5 +Int + +scala> :type def f = 5 +Int + +scala> :type def f() = 5 +()Int + +scala> + +scala> :type def g[T](xs: Set[_ <: T]) = Some(xs.head) +[T](xs: Set[_ <: T])Some[T] + +scala> + +scala> diff --git a/test/files/run/repl-colon-type.scala b/test/files/run/repl-colon-type.scala new file mode 100644 index 0000000000..39ab580d2a --- /dev/null +++ b/test/files/run/repl-colon-type.scala @@ -0,0 +1,23 @@ +import scala.tools.partest.ReplTest + +object Test extends ReplTest { + def code = """ + |:type List[1, 2, 3] + |:type List(1, 2, 3) + |:type def foo[T](x: T) = List(x) + |:type val bar = List(Set(1)) + |:type lazy val bar = Set(Set(1)) + |:type def f[T >: Null, U <: String](x: T, y: U) = Set(x, y) + |:type def x = 1 ; def bar[T >: Null <: AnyRef](xyz: T) = 5 + | + |:type 5 + |:type val f = 5 + |:type lazy val f = 5 + |:type protected lazy val f = 5 + |:type def f = 5 + |:type def f() = 5 + | + |:type def g[T](xs: Set[_ <: T]) = Some(xs.head) + """.stripMargin +} + diff --git a/test/files/run/repl-parens.check b/test/files/run/repl-parens.check new file mode 100644 index 0000000000..f41c2e74bd --- /dev/null +++ b/test/files/run/repl-parens.check @@ -0,0 +1,58 @@ +Type in expressions to have them evaluated. +Type :help for more information. + +scala> (2) +res0: Int = 2 + +scala> (2 + 2) +res1: Int = 4 + +scala> ((2 + 2)) +res2: Int = 4 + +scala> ((2 + 2)) +res3: Int = 4 + +scala> ( (2 + 2)) +res4: Int = 4 + +scala> ( (2 + 2 ) ) +res5: Int = 4 + +scala> 5 ; ( (2 + 2 ) ) ; ((5)) +res6: Int = 5 + +scala> (((2 + 2)), ((2 + 2))) +res7: (Int, Int) = (4,4) + +scala> (((2 + 2)), ((2 + 2)), 2) +res8: (Int, Int, Int) = (4,4,2) + +scala> ((((2 + 2)), ((2 + 2)), 2).productIterator ++ Iterator(3) mkString) +res9: String = 4423 + +scala> + +scala> 55 ; ((2 + 2)) ; (1, 2, 3) +res10: (Int, Int, Int) = (1,2,3) + +scala> + +scala> () => 5 +res11: () => Int = <function0> + +scala> 55 ; () => 5 +res12: () => Int = <function0> + +scala> () => { class X ; new X } +res13: () => java.lang.Object with ScalaObject = <function0> + +scala> + +scala> def foo(x: Int)(y: Int)(z: Int) = x+y+z +foo: (x: Int)(y: Int)(z: Int)Int + +scala> foo(5)(10)(15)+foo(5)(10)(15) +res14: Int = 60 + +scala> diff --git a/test/files/run/repl-parens.scala b/test/files/run/repl-parens.scala new file mode 100644 index 0000000000..081db3606a --- /dev/null +++ b/test/files/run/repl-parens.scala @@ -0,0 +1,26 @@ +import scala.tools.partest.ReplTest + +object Test extends ReplTest { + def code = """ +(2) +(2 + 2) +((2 + 2)) + ((2 + 2)) + ( (2 + 2)) + ( (2 + 2 ) ) +5 ; ( (2 + 2 ) ) ; ((5)) +(((2 + 2)), ((2 + 2))) +(((2 + 2)), ((2 + 2)), 2) +((((2 + 2)), ((2 + 2)), 2).productIterator ++ Iterator(3) mkString) + +55 ; ((2 + 2)) ; (1, 2, 3) + +() => 5 +55 ; () => 5 +() => { class X ; new X } + +def foo(x: Int)(y: Int)(z: Int) = x+y+z +foo(5)(10)(15)+foo(5)(10)(15) + + """.trim +}
\ No newline at end of file diff --git a/test/files/run/repl-paste-2.check b/test/files/run/repl-paste-2.check index 435592567d..18bd6d2434 100644 --- a/test/files/run/repl-paste-2.check +++ b/test/files/run/repl-paste-2.check @@ -4,6 +4,9 @@ Type :help for more information. scala> scala> scala> 0123 + +// Detected repl transcript paste: ctrl-D to finish. + res4: Int = 0123 scala> 123 diff --git a/test/files/run/repl-power.check b/test/files/run/repl-power.check new file mode 100644 index 0000000000..9561c04eca --- /dev/null +++ b/test/files/run/repl-power.check @@ -0,0 +1,17 @@ +Type in expressions to have them evaluated. +Type :help for more information. + +scala> :power +** Power User mode enabled - BEEP BOOP WHIR ** +** scala.tools.nsc._ has been imported ** +** global._ and definitions._ also imported ** +** New vals! Try repl, intp, global, power ** +** New cmds! :help to discover them ** +** New defs! Type power.<tab> to reveal ** + +scala> // guarding against "error: reference to global is ambiguous" + +scala> global.emptyValDef // "it is imported twice in the same scope by ..." +res0: global.emptyValDef.type = private val _ = _ + +scala> diff --git a/test/files/run/repl-power.scala b/test/files/run/repl-power.scala new file mode 100644 index 0000000000..9f70ac4b68 --- /dev/null +++ b/test/files/run/repl-power.scala @@ -0,0 +1,10 @@ +import scala.tools.partest.ReplTest + +object Test extends ReplTest { + def code = """ +:power +// guarding against "error: reference to global is ambiguous" +global.emptyValDef // "it is imported twice in the same scope by ..." + """.trim +} + diff --git a/test/files/run/repl-transcript.check b/test/files/run/repl-transcript.check index 03162451b6..6d22353882 100644 --- a/test/files/run/repl-transcript.check +++ b/test/files/run/repl-transcript.check @@ -4,6 +4,9 @@ Type :help for more information. scala> scala> scala> class Bippity + +// Detected repl transcript paste: ctrl-D to finish. + defined class Bippity scala> def f = new Bippity |