diff options
author | Rex Kerr <ichoran@gmail.com> | 2015-08-30 17:27:05 -0700 |
---|---|---|
committer | Rex Kerr <ichoran@gmail.com> | 2015-08-30 17:27:05 -0700 |
commit | 2c16790ae48debe6e8b07b7ece86b0c665359cfd (patch) | |
tree | 8c3ac3916aec0d33d3fca4f570dfd1f73d29bc57 /test/junit | |
parent | 4f35ab77e6b4456025facc63297e7f2e93c2b9d0 (diff) | |
download | scala-2c16790ae48debe6e8b07b7ece86b0c665359cfd.tar.gz scala-2c16790ae48debe6e8b07b7ece86b0c665359cfd.tar.bz2 scala-2c16790ae48debe6e8b07b7ece86b0c665359cfd.zip |
SI-9379 Added toString to .zipped to allow Stream etc to short-circuit
Tuple2Zipped and Tuple3Zipped would try to compute a hash code when .toString was called on them. This overrides toString to print (collection1, collection2).zipped instead, using the collection's own toString method. This allows collections that have a toString but not a hashCode (such as Iterator.from(0) and s = 1 #:: s) to print out as they usually do.
JUnit test to verify the deferral to collections' .toString.
Diffstat (limited to 'test/junit')
-rw-r--r-- | test/junit/scala/collection/immutable/StreamTest.scala | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/test/junit/scala/collection/immutable/StreamTest.scala b/test/junit/scala/collection/immutable/StreamTest.scala index fad4e502eb..1b257aabc4 100644 --- a/test/junit/scala/collection/immutable/StreamTest.scala +++ b/test/junit/scala/collection/immutable/StreamTest.scala @@ -107,4 +107,20 @@ class StreamTest { def withFilter_map_properly_lazy_in_tail: Unit = { assertStreamOpLazyInTail(_.withFilter(_ % 2 == 0).map(identity), List(1, 2)) } + + @Test + def test_si9379() { + class Boom { + private var i = -1 + def inc = { + i += 1 + if (i > 1000) throw new NoSuchElementException("Boom! Too many elements!") + i + } + } + val b = new Boom + val s = Stream.continually(b.inc) + // zipped.toString must allow s to short-circuit evaluation + assertTrue((s, s).zipped.toString contains s.toString) + } } |