mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2024-12-21 16:04:09 -08:00
Add test for System.arraycopy with different source/target indexes
This commit is contained in:
parent
e4c32681b9
commit
4e3cb5628f
|
@ -15,6 +15,7 @@
|
|||
*/
|
||||
package org.teavm.classlib.java.lang;
|
||||
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
@ -44,6 +45,28 @@ public class SystemTest {
|
|||
assertSame(a, dest[2]);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void copiesArrayPart() {
|
||||
var a = new Object();
|
||||
var b = new Object();
|
||||
var src = new Object[] { a, b, a };
|
||||
var dest = new Object[5];
|
||||
System.arraycopy(src, 0, dest, 1, 3);
|
||||
assertNull(dest[0]);
|
||||
assertSame(a, dest[1]);
|
||||
assertSame(b, dest[2]);
|
||||
assertSame(a, dest[3]);
|
||||
assertNull(dest[4]);
|
||||
|
||||
dest = new Object[5];
|
||||
System.arraycopy(src, 1, dest, 0, 2);
|
||||
assertSame(b, dest[0]);
|
||||
assertSame(a, dest[1]);
|
||||
assertNull(dest[2]);
|
||||
assertNull(dest[3]);
|
||||
assertNull(dest[4]);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void copiesPrimitiveArray() {
|
||||
int[] src = { 23, 24, 25 };
|
||||
|
@ -54,6 +77,18 @@ public class SystemTest {
|
|||
assertEquals(25, dest[2]);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void copiesPrimitiveArrayPart() {
|
||||
var src = new int[] { 23, 24, 25 };
|
||||
var dest = new int[5];
|
||||
System.arraycopy(src, 0, dest, 1, 3);
|
||||
assertArrayEquals(new int[] { 0, 23, 24, 25, 0 }, dest);
|
||||
|
||||
dest = new int[5];
|
||||
System.arraycopy(src, 1, dest, 0, 2);
|
||||
assertArrayEquals(new int[] { 24, 25, 0, 0, 0 }, dest);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void copiesToSubclassArray() {
|
||||
String[] src = { "foo", "bar", "baz" };
|
||||
|
|
Loading…
Reference in New Issue
Block a user