diff options
author | Rex Kerr <ichoran@gmail.com> | 2014-08-24 15:51:33 -0700 |
---|---|---|
committer | Jason Zaugg <jzaugg@gmail.com> | 2015-01-08 15:14:37 +1000 |
commit | 76619953a628e8c6d3792872a3456260a58d9ffc (patch) | |
tree | 612336e9833779755285a84cac63d0841f0805e6 /test/files/run/t6827.scala | |
parent | 333dfbdaafd8fbb7ff0fc3b43060bcc0e4fb989d (diff) | |
download | scala-76619953a628e8c6d3792872a3456260a58d9ffc.tar.gz scala-76619953a628e8c6d3792872a3456260a58d9ffc.tar.bz2 scala-76619953a628e8c6d3792872a3456260a58d9ffc.zip |
SI-7128 copyToArray(xs, 0, 0) should not fail
Fixed all copyToArray methods to do exactly what the docs say
they do, with the least-suprise behavior of not throwing an
exception if you ask to copy nothing (but would have copied out of
range).
Iterator had an undocumented requirement for the target index to
be in range regardless if anything happened; this has been removed.
Diffstat (limited to 'test/files/run/t6827.scala')
-rw-r--r-- | test/files/run/t6827.scala | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/test/files/run/t6827.scala b/test/files/run/t6827.scala index 8e17af09e2..eb020711bb 100644 --- a/test/files/run/t6827.scala +++ b/test/files/run/t6827.scala @@ -31,4 +31,24 @@ object Test extends App { // okay, see SI-7128 "...".toIterator.copyToArray(new Array[Char](0), 0, 0) + + + // Bonus test from @som-snytt to check for overflow in + // index calculations. + def testOverflow(start: Int, len: Int, expected: List[Char]) { + def copyFromIterator = { + val arr = Array.fill[Char](3)('-') + "abc".toIterator.copyToArray(arr, start, len) + arr.toList + } + def copyFromArray = { + val arr = Array.fill[Char](3)('-') + "abc".toArray.copyToArray(arr, start, len) + arr.toList + } + assert(copyFromIterator == expected) + assert(copyFromArray == expected) + } + testOverflow(1, Int.MaxValue - 1, "-ab".toList) + testOverflow(1, Int.MaxValue, "-ab".toList) } |