diff --git a/tests/src/test/java/org/teavm/classlib/java/lang/SystemTest.java b/tests/src/test/java/org/teavm/classlib/java/lang/SystemTest.java index a76b46b25..8e434c9a2 100644 --- a/tests/src/test/java/org/teavm/classlib/java/lang/SystemTest.java +++ b/tests/src/test/java/org/teavm/classlib/java/lang/SystemTest.java @@ -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" };