summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/benchmarking/AVL-insert-random.scala67
-rw-r--r--test/benchmarking/AVL-insert.scala67
-rw-r--r--test/files/jvm/serialization.check4
-rw-r--r--test/files/jvm/serialization.scala7
-rw-r--r--test/files/neg/main1.check20
-rw-r--r--test/files/neg/nested-fn-print.check20
-rw-r--r--test/files/neg/nested-fn-print.scala11
-rw-r--r--test/files/neg/t0003.check2
-rw-r--r--test/files/neg/t4749.check28
-rw-r--r--test/files/neg/t4749.flags1
-rw-r--r--test/files/neg/t4749.scala44
-rw-r--r--test/files/neg/t692.check7
-rw-r--r--test/files/presentation/callcc-interpreter.check2
-rw-r--r--test/files/presentation/ide-bug-1000531.check2
-rw-r--r--test/files/run/si4147.scala36
-rw-r--r--test/files/run/xml-attribute.scala25
-rw-r--r--test/files/scalacheck/si4147.scala67
-rw-r--r--test/scaladoc/scala/html/HtmlFactoryTest.scala34
18 files changed, 385 insertions, 59 deletions
diff --git a/test/benchmarking/AVL-insert-random.scala b/test/benchmarking/AVL-insert-random.scala
new file mode 100644
index 0000000000..7299e330f5
--- /dev/null
+++ b/test/benchmarking/AVL-insert-random.scala
@@ -0,0 +1,67 @@
+package scala.collection
+
+
+
+
+
+class Dummy(val a: Int) extends math.Ordered[Dummy] {
+ def compare(other: Dummy) = this.a - other.a
+ override def toString = a.toString
+}
+
+
+object RandomGlobal {
+ val sz = 500000
+ val data = util.Random.shuffle((0 until sz) map { new Dummy(_) }) toArray;
+}
+
+
+import RandomGlobal._
+
+
+object RandomAVL extends testing.Benchmark {
+
+ def run() {
+ val avl = new collection.mutable.TreeSet[Dummy]
+
+ var i = 0
+ while (i < sz) {
+ val elem = data(i)
+ avl += elem
+ i += 1
+ }
+ }
+
+}
+
+
+object RandomImmutableTreeSet extends testing.Benchmark {
+
+ def run() {
+ var tree = new collection.immutable.TreeSet[Dummy]
+
+ var i = 0
+ while (i < sz) {
+ val elem = data(i)
+ tree += elem
+ i += 1
+ }
+ }
+
+}
+
+
+object RandomJavaTreeSet extends testing.Benchmark {
+
+ def run() {
+ val tree = new java.util.TreeSet[Dummy]
+
+ var i = 0
+ while (i < sz) {
+ val elem = data(i)
+ tree add elem
+ i += 1
+ }
+ }
+
+}
diff --git a/test/benchmarking/AVL-insert.scala b/test/benchmarking/AVL-insert.scala
new file mode 100644
index 0000000000..4f3ab390c9
--- /dev/null
+++ b/test/benchmarking/AVL-insert.scala
@@ -0,0 +1,67 @@
+package scala.collection
+
+
+
+
+
+class Dummy(val a: Int) extends math.Ordered[Dummy] {
+ def compare(other: Dummy) = this.a - other.a
+ override def toString = a.toString
+}
+
+
+object Global {
+ val sz = 500000
+ val data = (0 until sz) map { new Dummy(_) } toArray
+}
+
+
+import Global._
+
+
+object AVL extends testing.Benchmark {
+
+ def run() {
+ val avl = new collection.mutable.TreeSet[Dummy]
+
+ var i = 0
+ while (i < sz) {
+ val elem = data(i)
+ avl += elem
+ i += 1
+ }
+ }
+
+}
+
+
+object ImmutableTreeSet extends testing.Benchmark {
+
+ def run() {
+ var tree = new collection.immutable.TreeSet[Dummy]
+
+ var i = 0
+ while (i < sz) {
+ val elem = data(i)
+ tree += elem
+ i += 1
+ }
+ }
+
+}
+
+
+object JavaTreeSet extends testing.Benchmark {
+
+ def run() {
+ val tree = new java.util.TreeSet[Dummy]
+
+ var i = 0
+ while (i < sz) {
+ val elem = data(i)
+ tree add elem
+ i += 1
+ }
+ }
+
+}
diff --git a/test/files/jvm/serialization.check b/test/files/jvm/serialization.check
index 15708f0c3b..bc56387f81 100644
--- a/test/files/jvm/serialization.check
+++ b/test/files/jvm/serialization.check
@@ -188,6 +188,10 @@ x = WrappedArray(1, 2, 3)
y = WrappedArray(1, 2, 3)
x equals y: true, y equals x: true
+x = TreeSet(1, 2, 3)
+y = TreeSet(1, 2, 3)
+x equals y: true, y equals x: true
+
x = xml:src="hello"
y = xml:src="hello"
x equals y: true, y equals x: true
diff --git a/test/files/jvm/serialization.scala b/test/files/jvm/serialization.scala
index 9391b60e46..73bed2d46b 100644
--- a/test/files/jvm/serialization.scala
+++ b/test/files/jvm/serialization.scala
@@ -286,7 +286,7 @@ object Test3_mutable {
import scala.collection.mutable.{
ArrayBuffer, ArrayBuilder, ArraySeq, ArrayStack, BitSet, DoubleLinkedList,
HashMap, HashSet, History, LinkedList, ListBuffer, Publisher, Queue,
- Stack, StringBuilder, WrappedArray}
+ Stack, StringBuilder, WrappedArray, TreeSet}
// in alphabetic order
try {
@@ -380,6 +380,11 @@ object Test3_mutable {
val wa1 = WrappedArray.make(Array(1, 2, 3))
val _wa1: WrappedArray[Int] = read(write(wa1))
check(wa1, _wa1)
+
+ // TreeSet
+ val ts1 = TreeSet[Int]() ++= Array(1, 2, 3)
+ val _ts1: TreeSet[Int] = read(write(ts1))
+ check(ts1, _ts1)
}
catch {
case e: Exception =>
diff --git a/test/files/neg/main1.check b/test/files/neg/main1.check
index 734c78e54d..1a7a13e1e9 100644
--- a/test/files/neg/main1.check
+++ b/test/files/neg/main1.check
@@ -1,25 +1,25 @@
-main1.scala:3: error: Foo has a main method, but foo1.Foo will not be a runnable program.
- Its companion is a trait, which means no static forwarder can be generated.
+main1.scala:3: error: Foo has a main method with parameter type Array[String], but foo1.Foo will not be a runnable program.
+ Reason: companion is a trait, which means no static forwarder can be generated.
object Foo { // companion is trait
^
-main1.scala:10: error: Foo has a main method, but foo2.Foo will not be a runnable program.
- Its companion contains its own main method, which means no static forwarder can be generated.
+main1.scala:10: error: Foo has a main method with parameter type Array[String], but foo2.Foo will not be a runnable program.
+ Reason: companion contains its own main method, which means no static forwarder can be generated.
object Foo { // companion has its own main
^
-main1.scala:22: error: Foo has a main method, but foo3.Foo will not be a runnable program.
- Its companion contains its own main method (implementation restriction: no main is allowed, regardless of signature), which means no static forwarder can be generated.
+main1.scala:22: error: Foo has a main method with parameter type Array[String], but foo3.Foo will not be a runnable program.
+ Reason: companion contains its own main method (implementation restriction: no main is allowed, regardless of signature), which means no static forwarder can be generated.
object Foo { // Companion contains main, but not an interfering main.
^
-main1.scala:31: error: Foo has a main method, but foo4.Foo will not be a runnable program.
- Its companion contains its own main method (implementation restriction: no main is allowed, regardless of signature), which means no static forwarder can be generated.
+main1.scala:31: error: Foo has a main method with parameter type Array[String], but foo4.Foo will not be a runnable program.
+ Reason: companion contains its own main method, which means no static forwarder can be generated.
object Foo extends Foo { // Inherits main from the class
^
-main1.scala:39: error: Foo has a main method, but foo5.Foo will not be a runnable program.
- Its companion contains its own main method (implementation restriction: no main is allowed, regardless of signature), which means no static forwarder can be generated.
+main1.scala:39: error: Foo has a main method with parameter type Array[String], but foo5.Foo will not be a runnable program.
+ Reason: companion contains its own main method, which means no static forwarder can be generated.
object Foo extends Foo { // Overrides main from the class
^
diff --git a/test/files/neg/nested-fn-print.check b/test/files/neg/nested-fn-print.check
new file mode 100644
index 0000000000..ea278554d4
--- /dev/null
+++ b/test/files/neg/nested-fn-print.check
@@ -0,0 +1,20 @@
+nested-fn-print.scala:4: error: only classes can have declared but undefined members
+(Note that variables need to be initialized to be defined)
+ var x3: Int => Double
+ ^
+nested-fn-print.scala:7: error: type mismatch;
+ found : String("a")
+ required: Int => (Float => Double)
+ x1 = "a"
+ ^
+nested-fn-print.scala:8: error: type mismatch;
+ found : String("b")
+ required: (Int => Float) => Double
+ x2 = "b"
+ ^
+nested-fn-print.scala:9: error: type mismatch;
+ found : String("c")
+ required: Int => Double
+ x3 = "c"
+ ^
+four errors found
diff --git a/test/files/neg/nested-fn-print.scala b/test/files/neg/nested-fn-print.scala
new file mode 100644
index 0000000000..9a4bd162c0
--- /dev/null
+++ b/test/files/neg/nested-fn-print.scala
@@ -0,0 +1,11 @@
+object Test {
+ var x1: Int => Float => Double = _
+ var x2: (Int => Float) => Double = _
+ var x3: Int => Double
+
+ def main(args: Array[String]): Unit = {
+ x1 = "a"
+ x2 = "b"
+ x3 = "c"
+ }
+}
diff --git a/test/files/neg/t0003.check b/test/files/neg/t0003.check
index 1913dde9dd..8bab55db3f 100644
--- a/test/files/neg/t0003.check
+++ b/test/files/neg/t0003.check
@@ -1,5 +1,5 @@
t0003.scala:2: error: type mismatch;
- found : A => B => B
+ found : A => (B => B)
required: A => B
def foo[A, B, C](l: List[A], f: A => B=>B, g: B=>B=>C): List[C] = l map (g compose f)
^
diff --git a/test/files/neg/t4749.check b/test/files/neg/t4749.check
new file mode 100644
index 0000000000..93ad3935fa
--- /dev/null
+++ b/test/files/neg/t4749.check
@@ -0,0 +1,28 @@
+t4749.scala:2: error: Fail1 has a main method with parameter type Array[String], but bippy.Fail1 will not be a runnable program.
+ Reason: main method must have exact signature (Array[String])Unit
+ object Fail1 {
+ ^
+t4749.scala:6: error: Fail2 has a main method with parameter type Array[String], but bippy.Fail2 will not be a runnable program.
+ Reason: main methods cannot be generic.
+ object Fail2 {
+ ^
+t4749.scala:13: error: Fail3 has a main method with parameter type Array[String], but bippy.Fail3 will not be a runnable program.
+ Reason: main methods cannot refer to type parameters or abstract types.
+ object Fail3 extends Bippy[Unit] { }
+ ^
+t4749.scala:16: error: Fail4 has a main method with parameter type Array[String], but bippy.Fail4 will not be a runnable program.
+ Reason: companion is a trait, which means no static forwarder can be generated.
+
+ object Fail4 {
+ ^
+t4749.scala:21: error: Fail5 has a main method with parameter type Array[String], but bippy.Fail5 will not be a runnable program.
+ Reason: companion contains its own main method, which means no static forwarder can be generated.
+
+ object Fail5 extends Fail5 { }
+ ^
+t4749.scala:26: error: Fail6 has a main method with parameter type Array[String], but bippy.Fail6 will not be a runnable program.
+ Reason: companion contains its own main method (implementation restriction: no main is allowed, regardless of signature), which means no static forwarder can be generated.
+
+ object Fail6 {
+ ^
+6 errors found
diff --git a/test/files/neg/t4749.flags b/test/files/neg/t4749.flags
new file mode 100644
index 0000000000..e8fb65d50c
--- /dev/null
+++ b/test/files/neg/t4749.flags
@@ -0,0 +1 @@
+-Xfatal-warnings \ No newline at end of file
diff --git a/test/files/neg/t4749.scala b/test/files/neg/t4749.scala
new file mode 100644
index 0000000000..0973c36097
--- /dev/null
+++ b/test/files/neg/t4749.scala
@@ -0,0 +1,44 @@
+package bippy {
+ object Fail1 {
+ def main(args: Array[String]): Any = ()
+ }
+
+ object Fail2 {
+ def main[T](args: Array[String]): T = null.asInstanceOf[T]
+ }
+
+ abstract class Bippy[T] {
+ def main(args: Array[String]): T = null.asInstanceOf[T]
+ }
+ object Fail3 extends Bippy[Unit] { }
+
+
+ object Fail4 {
+ def main(args: Array[String]): Unit = ()
+ }
+ trait Fail4 { }
+
+ object Fail5 extends Fail5 { }
+ class Fail5 {
+ def main(args: Array[String]): Unit = ()
+ }
+
+ object Fail6 {
+ def main(args: Array[String]): Unit = ()
+ }
+ class Fail6 {
+ def main = "bippy"
+ }
+
+ object Win1 {
+ def main(args: Array[String]): Unit = ()
+ }
+ object Win2 extends Bippy[Unit] {
+ override def main(args: Array[String]): Unit = ()
+ }
+ trait WinBippy[T] {
+ def main(args: Array[String]): T = null.asInstanceOf[T]
+ }
+ object Win3 extends WinBippy[Unit] { }
+}
+
diff --git a/test/files/neg/t692.check b/test/files/neg/t692.check
index 12b7d40ba5..4149366309 100644
--- a/test/files/neg/t692.check
+++ b/test/files/neg/t692.check
@@ -13,12 +13,7 @@ t692.scala:13: error: class Foo takes type parameters
t692.scala:14: error: class Foo takes type parameters
implicit def typeOfBar[T4 <: Foo](implicit elem : RefType[T4]) : RefType[Bar[T4]] =
^
-t692.scala:15: error: type mismatch;
- found : test3.this.BarType[T4]
- required: test3.this.RefType[test3.this.Bar[T4]]
- BarType(elem);
- ^
t692.scala:19: error: class Foo takes type parameters
class Bar[A <: Foo](implicit tpeA : Type[A]) extends Foo;
^
-7 errors found
+6 errors found
diff --git a/test/files/presentation/callcc-interpreter.check b/test/files/presentation/callcc-interpreter.check
index ca99a5afc5..3385ef12b7 100644
--- a/test/files/presentation/callcc-interpreter.check
+++ b/test/files/presentation/callcc-interpreter.check
@@ -23,7 +23,7 @@ retrieved 64 members
`method add(a: callccInterpreter.Value, b: callccInterpreter.Value)callccInterpreter.M[_ >: callccInterpreter.Num with callccInterpreter.Wrong.type <: Product with Serializable with callccInterpreter.Value]`
`method apply(a: callccInterpreter.Value, b: callccInterpreter.Value)callccInterpreter.M[callccInterpreter.Value]`
`method asInstanceOf[T0]=> T0`
-`method callCC[A](h: A => callccInterpreter.M[A] => callccInterpreter.M[A])callccInterpreter.M[A]`
+`method callCC[A](h: (A => callccInterpreter.M[A]) => callccInterpreter.M[A])callccInterpreter.M[A]`
`method clone()Object`
`method ensuring(cond: Boolean)callccInterpreter.type`
`method ensuring(cond: Boolean, msg: => Any)callccInterpreter.type`
diff --git a/test/files/presentation/ide-bug-1000531.check b/test/files/presentation/ide-bug-1000531.check
index 04cea738f5..ae202001eb 100644
--- a/test/files/presentation/ide-bug-1000531.check
+++ b/test/files/presentation/ide-bug-1000531.check
@@ -101,7 +101,7 @@ retrieved 123 members
`method takeWhile(p: B => Boolean)Iterator[B]`
`method toArray[B >: B](implicit evidence$1: ClassManifest[B])Array[B]`
`method toBuffer[B >: B]=> scala.collection.mutable.Buffer[B]`
-`method toIndexedSeq[B >: B]=> scala.collection.immutable.IndexedSeq[B]`
+`method toIndexedSeq=> scala.collection.immutable.IndexedSeq[B]`
`method toIterable=> Iterable[B]`
`method toIterator=> Iterator[B]`
`method toList=> List[B]`
diff --git a/test/files/run/si4147.scala b/test/files/run/si4147.scala
new file mode 100644
index 0000000000..c1e2d746a9
--- /dev/null
+++ b/test/files/run/si4147.scala
@@ -0,0 +1,36 @@
+
+
+
+import scala.collection._
+
+
+
+object Test {
+
+ def main(args: Array[String]) {
+ checkElementsAreSorted()
+ checkRangedImpl()
+ }
+
+ def checkElementsAreSorted() {
+ val tree = mutable.SortedSet[Int]()
+ tree ++= List(4, 3, 1, 6, 7, 5, 2)
+ assert(tree == immutable.SortedSet(1, 2, 3, 4, 5, 6, 7))
+ assert(tree.size == 7)
+ }
+
+ def checkRangedImpl() {
+ val tree = mutable.SortedSet[Int](3, 1, 6, 7, 5, 2)
+ val projection = tree.rangeImpl(Some(3), Some(6))
+ assert(projection == immutable.SortedSet(3, 5))
+ assert(projection.size == 2)
+
+ // Let's check that modification are taken into account
+ tree add 4
+ assert(tree == immutable.SortedSet(1, 2, 3, 4, 5, 6, 7))
+ assert(projection == immutable.SortedSet(3, 4, 5))
+ assert(tree.size == 7)
+ assert(projection.size == 3)
+ }
+
+}
diff --git a/test/files/run/xml-attribute.scala b/test/files/run/xml-attribute.scala
index 8b261acc94..2b83f70b22 100644
--- a/test/files/run/xml-attribute.scala
+++ b/test/files/run/xml-attribute.scala
@@ -5,29 +5,10 @@ object Test {
val noAttr = <t/>
val attrNull = <t a={ null: String }/>
val attrNone = <t a={ None: Option[Seq[Node]] }/>
- val preAttrNull = <t p:a={ null: String }/>
- val preAttrNone = <t p:a={ None: Option[Seq[Node]] }/>
assert(noAttr == attrNull)
assert(noAttr == attrNone)
- assert(noAttr == preAttrNull)
- assert(noAttr == preAttrNone)
-
- val noAttrStr = "<t></t>"
- assert(noAttr.toString() == noAttrStr)
- assert(attrNull.toString() == noAttrStr)
- assert(attrNone.toString() == noAttrStr)
- assert(preAttrNull.toString() == noAttrStr)
- assert(preAttrNone.toString() == noAttrStr)
-
- val xml1 = <t b="1" d="2"/>
- val xml2 = <t a={ null: String } p:a={ null: String } b="1" c={ null: String } d="2"/>
- val xml3 = <t b="1" c={ null: String } d="2" a={ null: String } p:a={ null: String }/>
- assert(xml1 == xml2)
- assert(xml1 == xml3)
-
- val xml1Str = "<t d=\"2\" b=\"1\"></t>"
- assert(xml1.toString() == xml1Str)
- assert(xml2.toString() == xml1Str)
- assert(xml3.toString() == xml1Str)
+ assert(noAttr.toString() == "<t></t>")
+ assert(attrNull.toString() == "<t></t>")
+ assert(attrNone.toString() == "<t></t>")
}
}
diff --git a/test/files/scalacheck/si4147.scala b/test/files/scalacheck/si4147.scala
new file mode 100644
index 0000000000..1453440ef1
--- /dev/null
+++ b/test/files/scalacheck/si4147.scala
@@ -0,0 +1,67 @@
+import org.scalacheck.Prop.forAll
+import org.scalacheck.Properties
+import org.scalacheck.ConsoleReporter.testStatsEx
+import org.scalacheck.Gen
+import org.scalacheck.ConsoleReporter
+
+
+import collection.mutable
+
+
+object Test extends Properties("Mutable TreeSet") {
+
+ val generator = Gen.listOfN(1000, Gen.chooseNum(0, 1000))
+
+ val denseGenerator = Gen.listOfN(1000, Gen.chooseNum(0, 200))
+
+ property("Insertion doesn't allow duplicates values.") = forAll(generator) { (s: List[Int]) =>
+ {
+ val t = mutable.TreeSet[Int](s: _*)
+ t == s.toSet
+ }
+ }
+
+ property("Verification of size method validity") = forAll(generator) { (s: List[Int]) =>
+ {
+ val t = mutable.TreeSet[Int](s: _*)
+ for (a <- s) {
+ t -= a
+ }
+ t.size == 0
+ }
+ }
+
+ property("All inserted elements are removed") = forAll(generator) { (s: List[Int]) =>
+ {
+ val t = mutable.TreeSet[Int](s: _*)
+ for (a <- s) {
+ t -= a
+ }
+ t == Set()
+ }
+ }
+
+ property("Elements are sorted.") = forAll(generator) { (s: List[Int]) =>
+ {
+ val t = mutable.TreeSet[Int](s: _*)
+ t.toList == s.distinct.sorted
+ }
+ }
+
+ property("Implicit CanBuildFrom resolution succeeds as well as the \"same-result-type\" principle.") =
+ forAll(generator) { (s: List[Int]) =>
+ {
+ val t = mutable.TreeSet[Int](s: _*)
+ val t2 = t.map(_ * 2)
+ t2.isInstanceOf[collection.mutable.TreeSet[Int]]
+ }
+ }
+
+ property("A view doesn't expose off bounds elements") = forAll(denseGenerator) { (s: List[Int]) =>
+ {
+ val t = mutable.TreeSet[Int](s: _*)
+ val view = t.rangeImpl(Some(50), Some(150))
+ view.filter(_ < 50) == Set[Int]() && view.filter(_ >= 150) == Set[Int]()
+ }
+ }
+}
diff --git a/test/scaladoc/scala/html/HtmlFactoryTest.scala b/test/scaladoc/scala/html/HtmlFactoryTest.scala
index 5b17affbf0..7fed4ca027 100644
--- a/test/scaladoc/scala/html/HtmlFactoryTest.scala
+++ b/test/scaladoc/scala/html/HtmlFactoryTest.scala
@@ -185,18 +185,18 @@ object Test extends Properties("HtmlFactory") {
property("Trac #4180") = {
createTemplate("Trac4180.scala") != None
}
-
- property("Trac #4372") = {
- createTemplate("Trac4372.scala") match {
- case node: scala.xml.Node => {
- val html = node.toString
- html.contains("<span class=\"name\" title=\"gt4s: $plus$colon\">+:</span>") &&
- html.contains("<span class=\"name\" title=\"gt4s: $minus$colon\">-:</span>") &&
- html.contains("""<span class="params">(<span name="n">n: <span name="scala.Int" class="extype">Int</span></span>)</span><span class="result">: <span name="scala.Int" class="extype">Int</span></span>""")
- }
- case _ => false
- }
- }
+ //
+ // property("Trac #4372") = {
+ // createTemplate("Trac4372.scala") match {
+ // case node: scala.xml.Node => {
+ // val html = node.toString
+ // html.contains("<span class=\"name\" title=\"gt4s: $plus$colon\">+:</span>") &&
+ // html.contains("<span class=\"name\" title=\"gt4s: $minus$colon\">-:</span>") &&
+ // html.contains("""<span class="params">(<span name="n">n: <span name="scala.Int" class="extype">Int</span></span>)</span><span class="result">: <span name="scala.Int" class="extype">Int</span></span>""")
+ // }
+ // case _ => false
+ // }
+ // }
property("Trac #4374 - public") = {
val files = createTemplates("Trac4374.scala")
@@ -426,11 +426,11 @@ object Test extends Properties("HtmlFactory") {
createTemplate("SI_4898.scala")
true
}
-
- property("Use cases should override their original members") =
- checkText1("SI_5054_q1.scala", """def test(): Int""") &&
- !checkText1("SI_5054_q1.scala", """def test(implicit lost: Int): Int""")
-
+ //
+ // property("Use cases should override their original members") =
+ // checkText1("SI_5054_q1.scala", """def test(): Int""") &&
+ // !checkText1("SI_5054_q1.scala", """def test(implicit lost: Int): Int""")
+ //
property("Use cases should keep their flags - final should not be lost") =
checkText1("SI_5054_q2.scala", """final def test(): Int""")