summaryrefslogtreecommitdiff
path: root/test/junit/scala/collection/immutable/PagedSeqTest.scala
blob: 6c974db884e085225aeef766714014daa1356c68 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package scala.collection.immutable

import org.junit.runner.RunWith
import org.junit.runners.JUnit4
import org.junit.{Ignore, Test}
import org.junit.Assert._

@RunWith(classOf[JUnit4])
class PagedSeqTest {
  // should not NPE, and should equal the given Seq
  @Test
  @Ignore("This tests a non-stack safe method in a deprecated class that requires ~1.5M stack, disabling")
  def test_SI6615(): Unit = {
    assertEquals(Seq('a'), PagedSeq.fromStrings(List.fill(5000)("a")).slice(4096, 4097))
  }

  // should not NPE, and should be empty
  @Test
  def test_SI9480(): Unit = {
    assertEquals(Seq(), PagedSeq.fromStrings(List("a")).slice(1))
  }

  // Slices shouldn't read outside where they belong
  @Test
  def test_SI6519 {
    var readAttempt = 0
    val sideEffectingIterator = new Iterator[Int] {
      def hasNext = readAttempt < 65536
      def next = { readAttempt += 1; readAttempt }
    }
    val s = PagedSeq.fromIterator(sideEffectingIterator).slice(0,2).mkString
    assertEquals(s, "12")
    assert(readAttempt <= 4096)
  }
}