summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorJosh Suereth <Joshua.Suereth@gmail.com>2012-03-14 15:02:47 -0700
committerJosh Suereth <Joshua.Suereth@gmail.com>2012-03-14 15:02:47 -0700
commit8e9e2e30db0cb36029443a49179dfab4eb08c43a (patch)
tree5effda865f8fb978f32d8d6c0add9775a55d0cb4 /test
parentb8b51b70bf34889e55263ee1f99f0c9d7aca1ea4 (diff)
parentc192c10e1367a356f7d9e920651f025f29c56947 (diff)
downloadscala-8e9e2e30db0cb36029443a49179dfab4eb08c43a.tar.gz
scala-8e9e2e30db0cb36029443a49179dfab4eb08c43a.tar.bz2
scala-8e9e2e30db0cb36029443a49179dfab4eb08c43a.zip
Merge pull request #253 from rjmac/backport/4835
Backport/4835
Diffstat (limited to 'test')
-rw-r--r--test/files/run/t4835.check7
-rw-r--r--test/files/run/t4835.scala38
2 files changed, 45 insertions, 0 deletions
diff --git a/test/files/run/t4835.check b/test/files/run/t4835.check
new file mode 100644
index 0000000000..531c3d7bb6
--- /dev/null
+++ b/test/files/run/t4835.check
@@ -0,0 +1,7 @@
+-1 0 1 2 3 4 5 6 7 8 9
+-1 1 3 5 7 9 11 13 15 17 19
+1 1
+2 1 2
+2 1 A 2
+3 1 2 3
+3 1 A 2 B 3
diff --git a/test/files/run/t4835.scala b/test/files/run/t4835.scala
new file mode 100644
index 0000000000..50d161be40
--- /dev/null
+++ b/test/files/run/t4835.scala
@@ -0,0 +1,38 @@
+/*
+ * Test case for SI-4835. This tests confirm that the fix
+ * doesn't break laziness. To test memory consumption,
+ * I need to confirm that OutOfMemoryError doesn't occur.
+ * I could create such tests. However, such tests consume
+ * too much time and memory.
+ */
+object Test {
+ private final val INFINITE = -1
+ def testStreamIterator(num: Int, stream: Stream[Int]): Unit = {
+ val iter = stream.iterator
+ print(num)
+ // if num == -1, then steram is infinite sequence
+ if (num == INFINITE) {
+ for(i <- 0 until 10) {
+ print(" " + iter.next())
+ }
+ } else {
+ while(iter.hasNext) {
+ print(" " + iter.next())
+ }
+ }
+ println()
+ }
+
+ def main(args: Array[String]): Unit = {
+ import Stream.{from, cons, empty}
+ testStreamIterator(INFINITE, from(0))
+ testStreamIterator(INFINITE, from(0).filter(_ % 2 == 1))
+ testStreamIterator(1, Stream(1))
+ testStreamIterator(2, Stream(1, 2))
+ //Stream with side effect
+ testStreamIterator(2, cons(1, cons({ print(" A"); 2}, empty)))
+ testStreamIterator(3, Stream(1, 2, 3))
+ //Stream with side effect
+ testStreamIterator(3, cons(1, cons({ print(" A"); 2}, cons({ print(" B"); 3}, Stream.empty))))
+ }
+}