-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
51 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 14 additions & 19 deletions
33
test/junit/scala/collection/mutable/ArrayBuilderTest.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,35 @@ | ||
package scala.collection.mutable | ||
|
||
import org.junit.Test | ||
import org.junit.Assert.assertEquals | ||
import org.junit.Test | ||
|
||
import scala.runtime.PStatics.VM_MaxArraySize | ||
import scala.tools.testkit.AssertUtil.assertThrows | ||
|
||
import scala.runtime.PStatics | ||
class ArrayBuilderTest { | ||
|
||
/* Test for scala/bug#12617 */ | ||
|
||
val MaxArraySize: Int = PStatics.VM_MaxArraySize | ||
|
||
@Test | ||
def testCapacityGrowthLimit: Unit = { | ||
|
||
def t12617: Unit = { | ||
val ab: ArrayBuilder[Unit] = ArrayBuilder.make[Unit] | ||
|
||
var i: Int = 0 | ||
while (i < MaxArraySize) { | ||
ab.addOne(()) | ||
i += 1 | ||
} | ||
// ArrayBuilder.ofUnit.addAll doesn't iterate if the iterator has a `knownSize` | ||
ab.addAll(new Iterator[Unit] { | ||
override def knownSize: Int = VM_MaxArraySize | ||
def hasNext: Boolean = true | ||
def next(): Unit = () | ||
}) | ||
|
||
// reached maximum size without entering an infinite loop? | ||
assertEquals(ab.length, MaxArraySize) | ||
assertEquals(ab.length, VM_MaxArraySize) | ||
|
||
// expect an exception when trying to grow larger than maximum size by addOne | ||
assertThrows[Exception](ab.addOne(())) | ||
assertThrows[Exception](ab.addOne(()), _.endsWith("Requested length: 2147483640; current length: 2147483639")) | ||
|
||
val arr:Array[Unit] = Array[Unit]((), (), (), (), (), (), (), (), (), (), (), ()) | ||
val arr = Array[Unit]((), (), (), (), (), (), (), (), (), (), (), ()) | ||
|
||
// expect an exception when trying to grow larger than maximum size by addAll(iterator) | ||
assertThrows[Exception](ab.addAll(arr.iterator)) | ||
assertThrows[Exception](ab.addAll(arr.iterator), _.endsWith("Requested length: -2147483645; current length: 2147483639; increase: 12")) | ||
|
||
// expect an exception when trying to grow larger than maximum size by addAll(array) | ||
assertThrows[Exception](ab.addAll(arr)) | ||
|
||
} | ||
} |