File tree Expand file tree Collapse file tree 1 file changed +25
-0
lines changed
test/junit/scala/collection/immutable Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -80,4 +80,29 @@ class StreamTest {
80
80
assertTrue( wf.map(identity).length == 5 ) // success instead of NPE
81
81
}
82
82
83
+ /** Test helper to verify that the given Stream operation is properly lazy in the tail */
84
+ def assertStreamOpLazyInTail (op : (=> Stream [Int ]) => Stream [Int ], expectedEvaluated : List [Int ]): Unit = {
85
+ // mutable state to record every strict evaluation
86
+ var evaluated : List [Int ] = Nil
87
+
88
+ def trackEffectsOnNaturals : Stream [Int ] = {
89
+ def loop (i : Int ): Stream [Int ] = { evaluated ++= List (i); i #:: loop(i + 1 ) }
90
+ loop(1 )
91
+ }
92
+
93
+ // call op on a stream which records every strict evaluation
94
+ val result = op(trackEffectsOnNaturals)
95
+
96
+ assertTrue( evaluated == expectedEvaluated )
97
+ }
98
+
99
+ @ Test // SI-9134
100
+ def filter_map_properly_lazy_in_tail : Unit = {
101
+ assertStreamOpLazyInTail(_.filter(_ % 2 == 0 ).map(identity), List (1 , 2 ))
102
+ }
103
+
104
+ @ Test // SI-9134
105
+ def withFilter_map_properly_lazy_in_tail : Unit = {
106
+ assertStreamOpLazyInTail(_.withFilter(_ % 2 == 0 ).map(identity), List (1 , 2 ))
107
+ }
83
108
}
You can’t perform that action at this time.
0 commit comments