Null-terminate Collection.toArray destination only in JVM

In other platforms the elements following the collection elements
should not be changed.

As a part of efforts to stabilize Native stdlib.
This commit is contained in:
Abduqodiri Qurbonzoda
2023-06-01 12:52:46 +03:00
committed by Space Team
parent 60455daa9d
commit 6fdfd4e8dd
14 changed files with 46 additions and 40 deletions
@@ -5,6 +5,7 @@
package test.collections
import test.*
import test.collections.behaviors.iteratorBehavior
import test.collections.behaviors.listIteratorBehavior
import test.collections.behaviors.listIteratorProperties
@@ -622,12 +623,20 @@ class ArrayDequeTest {
val dest = Array(expected.size + 2) { it + 100 }
@Suppress("UNCHECKED_CAST")
val nullTerminatedExpected = (expected as Array<Any?>) + null + (expected.size + 101)
val expectedDest = buildList {
addAll(expected)
if (TestPlatform.current == TestPlatform.Jvm) {
add(null)
} else {
add(expected.size + 100)
}
add(expected.size + 101)
}.toTypedArray()
val actual = deque.testToArray(dest)
assertTrue(
nullTerminatedExpected contentEquals actual,
message = "Expected: ${nullTerminatedExpected.contentToString()}, Actual: ${actual.contentToString()}"
expectedDest contentEquals actual,
message = "Expected: ${expectedDest.contentToString()}, Actual: ${actual.contentToString()}"
)
}
@@ -1311,7 +1311,12 @@ class CollectionTest {
assertTrue("toArray1" in coll.invocations || "toArray2" in coll.invocations)
val arr2: Array<String> = coll.toArray(Array(coll.size + 1) { "" })
assertEquals(data + listOf(null), arr2.asList())
testOnlyOn(TestPlatform.Jvm) {
assertEquals(data + listOf(null), arr2.asList())
}
testExceptOn(TestPlatform.Jvm) {
assertEquals(data + listOf(""), arr2.asList())
}
}
@Test