diff options
author | Stefan Zeiger <szeiger@novocode.com> | 2016-07-05 16:08:25 +0200 |
---|---|---|
committer | Stefan Zeiger <szeiger@novocode.com> | 2016-07-07 17:34:08 +0200 |
commit | c2ca66af4214dcd2e17be038741fe63a47bb2725 (patch) | |
tree | 0bfc595953d349b519faf9b75ca3c30ac710e767 /test | |
parent | 6612ba010b0e70c53550d1e47141c8dc89a55f23 (diff) | |
download | scala-c2ca66af4214dcd2e17be038741fe63a47bb2725.tar.gz scala-c2ca66af4214dcd2e17be038741fe63a47bb2725.tar.bz2 scala-c2ca66af4214dcd2e17be038741fe63a47bb2725.zip |
SI-6881 Detect reference equality when comparing streams
`==` already covers this case. We override `equals` in `Stream` to do
the same when `equals` is called directly. This takes care of identical
streams.
To support short-circuiting equality checks on elements prepended to
identical streams we also override `sameElements` in `Cons` to treat
the case where both sides are `Cons` separately.
Tests in StreamTest.test_reference_equality.
Diffstat (limited to 'test')
-rw-r--r-- | test/junit/scala/collection/immutable/StreamTest.scala | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/test/junit/scala/collection/immutable/StreamTest.scala b/test/junit/scala/collection/immutable/StreamTest.scala index fad4e502eb..7046525f37 100644 --- a/test/junit/scala/collection/immutable/StreamTest.scala +++ b/test/junit/scala/collection/immutable/StreamTest.scala @@ -107,4 +107,14 @@ class StreamTest { def withFilter_map_properly_lazy_in_tail: Unit = { assertStreamOpLazyInTail(_.withFilter(_ % 2 == 0).map(identity), List(1, 2)) } + + @Test // SI-6881 + def test_reference_equality: Unit = { + // Make sure we're tested with reference equality + val s = Stream.from(0) + assert(s == s, "Referentially identical streams should be equal (==)") + assert(s equals s, "Referentially identical streams should be equal (equals)") + assert((0 #:: 1 #:: s) == (0 #:: 1 #:: s), "Cons of referentially identical streams should be equal (==)") + assert((0 #:: 1 #:: s) equals (0 #:: 1 #:: s), "Cons of referentially identical streams should be equal (equals)") + } } |