summaryrefslogtreecommitdiff
path: root/test/files
diff options
context:
space:
mode:
authorJosh Suereth <Joshua.Suereth@gmail.com>2012-09-14 09:22:25 -0700
committerJosh Suereth <Joshua.Suereth@gmail.com>2012-09-14 09:22:25 -0700
commit882d172dc524e2aa9b131b5a69e9bfd3790d35ca (patch)
tree57abc1fb65315ef747640aff9b1d04c4c4320623 /test/files
parent65358306ba2538a6954767952058d6281ef139e2 (diff)
parentf3fd018f145ffc02de03744259ba585d8152483f (diff)
downloadscala-882d172dc524e2aa9b131b5a69e9bfd3790d35ca.tar.gz
scala-882d172dc524e2aa9b131b5a69e9bfd3790d35ca.tar.bz2
scala-882d172dc524e2aa9b131b5a69e9bfd3790d35ca.zip
Merge pull request #1281 from jsuereth/fix/SI-4813
Fix SI-4813 - Clone doesn't work on LinkedList.
Diffstat (limited to 'test/files')
-rw-r--r--test/files/run/t4813.scala37
1 files changed, 37 insertions, 0 deletions
diff --git a/test/files/run/t4813.scala b/test/files/run/t4813.scala
new file mode 100644
index 0000000000..6d48ca8758
--- /dev/null
+++ b/test/files/run/t4813.scala
@@ -0,0 +1,37 @@
+import collection.mutable._
+import reflect._
+
+
+object Test extends App {
+ def runTest[T, U](col: T)(clone: T => U)(mod: T => Unit)(implicit ct: ClassTag[T]): Unit = {
+ val cloned = clone(col)
+ assert(cloned == col, s"cloned should be equal to original. $cloned != $col")
+ mod(col)
+ assert(cloned != col, s"cloned should not modify when original does: $ct")
+ }
+
+ // Seqs
+ runTest(ArrayBuffer(1,2,3))(_.clone) { buf => buf transform (_ + 1) }
+ runTest(ArraySeq(1,2,3))(_.clone) { buf => buf transform (_ + 1) }
+ runTest(Buffer(1,2,3))(_.clone) { buf => buf transform (_ + 1) }
+ runTest(DoubleLinkedList(1,2,3))(_.clone) { buf => buf transform (_ + 1) }
+ runTest(IndexedSeq(1,2,3))(_.clone) { buf => buf transform (_ + 1) }
+ runTest(LinearSeq(1,2,3))(_.clone) { buf => buf transform (_ + 1) }
+ runTest(LinkedList(1,2,3))(_.clone) { buf => buf transform (_ + 1) }
+ runTest(ListBuffer(1,2,3))(_.clone) { buf => buf transform (_ + 1) }
+ runTest(MutableList(1,2,3))(_.clone) { buf => buf transform (_ + 1) }
+ runTest(Queue(1,2,3))(_.clone) { buf => buf transform (_ + 1) }
+ runTest(Stack(1,2,3))(_.clone) { buf => buf transform (_ + 1) }
+
+ // Sets
+ runTest(BitSet(1,2,3))(_.clone) { buf => buf add 4 }
+ runTest(HashSet(1,2,3))(_.clone) { buf => buf add 4 }
+ runTest(Set(1,2,3))(_.clone) { buf => buf add 4 }
+ runTest(SortedSet(1,2,3))(_.clone) { buf => buf add 4 }
+ runTest(TreeSet(1,2,3))(_.clone) { buf => buf add 4 }
+
+ // Maps
+ runTest(HashMap(1->1,2->2,3->3))(_.clone) { buf => buf put (4,4) }
+ runTest(WeakHashMap(1->1,2->2,3->3))(_.clone) { buf => buf put (4,4) }
+}
+