diff --git a/libraries/stdlib/jvm/build.gradle b/libraries/stdlib/jvm/build.gradle index cbcc79f32dd..9c57bf3c02b 100644 --- a/libraries/stdlib/jvm/build.gradle +++ b/libraries/stdlib/jvm/build.gradle @@ -261,4 +261,10 @@ compileTestKotlin { } } +test { + if (project.hasProperty("kotlin.stdlib.test.long.sequences")) { + systemProperty("kotlin.stdlib.test.long.sequences", "true") + } +} + kotlin.experimental.coroutines 'enable' diff --git a/libraries/stdlib/jvm/test/collections/IndexOverflowJVMTest.kt b/libraries/stdlib/jvm/test/collections/IndexOverflowJVMTest.kt new file mode 100644 index 00000000000..c6f7b56e109 --- /dev/null +++ b/libraries/stdlib/jvm/test/collections/IndexOverflowJVMTest.kt @@ -0,0 +1,45 @@ +/* + * Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license + * that can be found in the license/LICENSE.txt file. + */ + +package test.collections + +import org.junit.Assume +import org.junit.Test +import kotlin.test.* + +class IndexOverflowJVMTest { + + @BeforeTest + fun checkIsNotIgnored() { + Assume.assumeTrue(System.getProperty("kotlin.stdlib.test.long.sequences")?.toBoolean() ?: false) + } + + + companion object { + fun repeatCounted(value: T, count: Long = Int.MAX_VALUE + 1L): Sequence = Sequence { + object : Iterator { + var counter = count + override fun hasNext(): Boolean = counter > 0 + override fun next(): T = value.also { counter-- } + } + } + + val maxIndexSequence = repeatCounted("k", (Int.MAX_VALUE + 1L) + 1L) // here the last index is one greater than Int.MAX_VALUE + val maxIndexIterable = maxIndexSequence.asIterable() + + + val longCountSequence = Sequence { + object : Iterator { + var counter = 0L + override fun hasNext(): Boolean = true + override fun next(): Long = counter++ + } + } + } + + + + +} \ No newline at end of file