diff options
author | Marc Siegel <marc.siegel@timgroup.com> | 2015-02-25 10:59:50 -0500 |
---|---|---|
committer | Marc Siegel <marc.siegel@timgroup.com> | 2015-02-25 14:32:56 -0500 |
commit | 05f46dc9feaec11b9ad3a725a4e183b915bedf0e (patch) | |
tree | a4a70110ee8f2d56248e341786a3d6182ee19f6e /test | |
parent | 198c201590d8ab25b0474bf68266714a7542a37d (diff) | |
download | scala-05f46dc9feaec11b9ad3a725a4e183b915bedf0e.tar.gz scala-05f46dc9feaec11b9ad3a725a4e183b915bedf0e.tar.bz2 scala-05f46dc9feaec11b9ad3a725a4e183b915bedf0e.zip |
SI-9134 Verify Stream#withFilter#map lazy in tail
As discussed in comments on [the issue](https://issues.scala-lang.org/browse/SI-9134),
it appears that the fix for SI-8990 also fixed this issue.
These tests demonstrate that it is fixed and will serve
as regression tests. Also, if back-ported to 2.11.x, they
could drive a potentially different fix there.
Squashed:
- incorporate review comments from adriaanm
Diffstat (limited to 'test')
-rw-r--r-- | test/junit/scala/collection/immutable/StreamTest.scala | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/test/junit/scala/collection/immutable/StreamTest.scala b/test/junit/scala/collection/immutable/StreamTest.scala index 36732fef2c..437cbc8926 100644 --- a/test/junit/scala/collection/immutable/StreamTest.scala +++ b/test/junit/scala/collection/immutable/StreamTest.scala @@ -80,4 +80,29 @@ class StreamTest { assertTrue( wf.map(identity).length == 5 ) // success instead of NPE } + /** Test helper to verify that the given Stream operation is properly lazy in the tail */ + def assertStreamOpLazyInTail(op: (=> Stream[Int]) => Stream[Int], expectedEvaluated: List[Int]): Unit = { + // mutable state to record every strict evaluation + var evaluated: List[Int] = Nil + + def trackEffectsOnNaturals: Stream[Int] = { + def loop(i: Int): Stream[Int] = { evaluated ++= List(i); i #:: loop(i + 1) } + loop(1) + } + + // call op on a stream which records every strict evaluation + val result = op(trackEffectsOnNaturals) + + assertTrue( evaluated == expectedEvaluated ) + } + + @Test // SI-9134 + def filter_map_properly_lazy_in_tail: Unit = { + assertStreamOpLazyInTail(_.filter(_ % 2 == 0).map(identity), List(1, 2)) + } + + @Test // SI-9134 + def withFilter_map_properly_lazy_in_tail: Unit = { + assertStreamOpLazyInTail(_.withFilter(_ % 2 == 0).map(identity), List(1, 2)) + } } |