diff options
author | Lukas Rytz <lukas.rytz@typesafe.com> | 2016-05-30 11:56:31 +0200 |
---|---|---|
committer | Lukas Rytz <lukas.rytz@typesafe.com> | 2016-05-30 11:56:31 +0200 |
commit | 9edbe3d671d31581d278b309c89d5c05bb2d8295 (patch) | |
tree | dee9e193bde0adc97d61e650c44b04e3423dfe91 /test | |
parent | 7d5a0b326deb5fd6efbbe0d8b1f32894589a3118 (diff) | |
parent | 0b79f4bf586268947b3e72750413e7106c4ad46e (diff) | |
download | scala-9edbe3d671d31581d278b309c89d5c05bb2d8295.tar.gz scala-9edbe3d671d31581d278b309c89d5c05bb2d8295.tar.bz2 scala-9edbe3d671d31581d278b309c89d5c05bb2d8295.zip |
Merge pull request #5191 from som-snytt/issue/9382
SI-9382 Privatize enhanced x in Tuple2Zipped.Ops
Diffstat (limited to 'test')
-rw-r--r-- | test/files/neg/t9382.check | 10 | ||||
-rw-r--r-- | test/files/neg/t9382.scala | 6 | ||||
-rw-r--r-- | test/files/run/tuple-zipped.scala | 41 | ||||
-rw-r--r-- | test/junit/scala/collection/immutable/StreamTest.scala | 16 | ||||
-rw-r--r-- | test/junit/scala/runtime/ZippedTest.scala | 68 |
5 files changed, 84 insertions, 57 deletions
diff --git a/test/files/neg/t9382.check b/test/files/neg/t9382.check new file mode 100644 index 0000000000..93bf48926a --- /dev/null +++ b/test/files/neg/t9382.check @@ -0,0 +1,10 @@ +t9382.scala:3: error: value x is not a member of (List[Int], List[Int]) + def f = (List(1,2,3), List(4,5,6)).x + ^ +t9382.scala:4: error: value x is not a member of (List[Int], List[Int], List[Int]) + def g = (List(1,2,3), List(4,5,6), List(7,8,9)).x + ^ +t9382.scala:5: error: value x is not a member of (Int, Int) + def huh = (1,2).x + ^ +three errors found diff --git a/test/files/neg/t9382.scala b/test/files/neg/t9382.scala new file mode 100644 index 0000000000..19703525e4 --- /dev/null +++ b/test/files/neg/t9382.scala @@ -0,0 +1,6 @@ + +trait T { + def f = (List(1,2,3), List(4,5,6)).x + def g = (List(1,2,3), List(4,5,6), List(7,8,9)).x + def huh = (1,2).x +} diff --git a/test/files/run/tuple-zipped.scala b/test/files/run/tuple-zipped.scala deleted file mode 100644 index 37ac52977f..0000000000 --- a/test/files/run/tuple-zipped.scala +++ /dev/null @@ -1,41 +0,0 @@ - -import scala.language.postfixOps - -object Test { - val xs1 = List.range(1, 100) - val xs2 = xs1.view - val xs3 = xs1 take 10 - val ss1 = Stream from 1 - val ss2 = ss1.view - val ss3 = ss1 take 10 - val as1 = 1 to 100 toArray - val as2 = as1.view - val as3 = as1 take 10 - - def xss1 = List[Seq[Int]](xs1, xs2, xs3, ss1, ss2, ss3, as1, as2, as3) - def xss2 = List[Seq[Int]](xs1, xs2, xs3, ss3, as1, as2, as3) // no infinities - def xss3 = List[Seq[Int]](xs2, xs3, ss3, as1) // representative sampling - - def main(args: Array[String]): Unit = { - for (cc1 <- xss1 ; cc2 <- xss2) { - val sum1 = (cc1, cc2).zipped map { case (x, y) => x + y } sum - val sum2 = (cc1, cc2).zipped map (_ + _) sum - - assert(sum1 == sum2) - } - - for (cc1 <- xss1 ; cc2 <- xss2 ; cc3 <- xss3) { - val sum1 = (cc1, cc2, cc3).zipped map { case (x, y, z) => x + y + z } sum - val sum2 = (cc1, cc2, cc3).zipped map (_ + _ + _) sum - - assert(sum1 == sum2) - } - - assert((ss1, ss1).zipped exists ((x, y) => true)) - assert((ss1, ss1, ss1).zipped exists ((x, y, z) => true)) - - assert(!(ss1, ss2, 1 to 3).zipped.exists(_ + _ + _ > 100000)) - assert((1 to 3, ss1, ss2).zipped.forall(_ + _ + _ > 0)) - assert((ss1, 1 to 3, ss2).zipped.map(_ + _ + _).size == 3) - } -} diff --git a/test/junit/scala/collection/immutable/StreamTest.scala b/test/junit/scala/collection/immutable/StreamTest.scala index 1b257aabc4..fad4e502eb 100644 --- a/test/junit/scala/collection/immutable/StreamTest.scala +++ b/test/junit/scala/collection/immutable/StreamTest.scala @@ -107,20 +107,4 @@ 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) - } } diff --git a/test/junit/scala/runtime/ZippedTest.scala b/test/junit/scala/runtime/ZippedTest.scala new file mode 100644 index 0000000000..d3ce4945aa --- /dev/null +++ b/test/junit/scala/runtime/ZippedTest.scala @@ -0,0 +1,68 @@ + +package scala.runtime + +import scala.language.postfixOps + +import org.junit.Assert._ +import org.junit.Test +import org.junit.runner.RunWith +import org.junit.runners.JUnit4 + +/** Tests Tuple?Zipped */ +@RunWith(classOf[JUnit4]) +class ZippedTest { + @Test + def crossZipped() { + + val xs1 = List.range(1, 100) + val xs2 = xs1.view + val xs3 = xs1 take 10 + val ss1 = Stream from 1 + val ss2 = ss1.view + val ss3 = ss1 take 10 + val as1 = 1 to 100 toArray + val as2 = as1.view + val as3 = as1 take 10 + + def xss1 = List[Seq[Int]](xs1, xs2, xs3, ss1, ss2, ss3, as1, as2, as3) + def xss2 = List[Seq[Int]](xs1, xs2, xs3, ss3, as1, as2, as3) // no infinities + def xss3 = List[Seq[Int]](xs2, xs3, ss3, as1) // representative sampling + + for (cc1 <- xss1 ; cc2 <- xss2) { + val sum1 = (cc1, cc2).zipped map { case (x, y) => x + y } sum + val sum2 = (cc1, cc2).zipped map (_ + _) sum + + assert(sum1 == sum2) + } + + for (cc1 <- xss1 ; cc2 <- xss2 ; cc3 <- xss3) { + val sum1 = (cc1, cc2, cc3).zipped map { case (x, y, z) => x + y + z } sum + val sum2 = (cc1, cc2, cc3).zipped map (_ + _ + _) sum + + assert(sum1 == sum2) + } + + assert((ss1, ss1).zipped exists ((x, y) => true)) + assert((ss1, ss1, ss1).zipped exists ((x, y, z) => true)) + + assert(!(ss1, ss2, 1 to 3).zipped.exists(_ + _ + _ > 100000)) + assert((1 to 3, ss1, ss2).zipped.forall(_ + _ + _ > 0)) + assert((ss1, 1 to 3, ss2).zipped.map(_ + _ + _).size == 3) + } + + @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) + } +} |