Skip to content

Commit 7d28d9d

Browse files
committed
Make sure that Stream factory preserves laziness
1 parent bb4ff52 commit 7d28d9d

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/test/scala/collection/FactoryTest.scala

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package collection
22

3-
import scala.collection.{Factory, Iterable, BitSet, mutable, immutable}
3+
import org.junit.{Assert, Test}
4+
5+
import scala.collection.{BitSet, Factory, Iterable, immutable, mutable}
46
import scala.collection.compat._
57

68
class FactoryTest {
@@ -17,4 +19,13 @@ class FactoryTest {
1719
Map: Factory[(Int, String), Map[Int, String]]
1820
immutable.TreeMap: Factory[(Int, String), immutable.TreeMap[Int, String]]
1921

22+
@Test
23+
def streamFactoryPreservesLaziness(): Unit = {
24+
val factory = implicitly[Factory[Int, Stream[Int]]]
25+
var counter = 0
26+
val source = Stream.continually { counter += 1; 1 }
27+
val result = factory.fromSpecific(source)
28+
Assert.assertEquals(1, counter) // One element has been evaluated because Stream is not lazy in its head
29+
}
30+
2031
}

0 commit comments

Comments
 (0)