diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/ExpectedTestOutput.test b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/ExpectedTestOutput.test index cc7e4e4fea9a0a6c3a0e75245573104b2bb8a1ae..57a4818c80ba9f64ec2ff5741afe8e9c7fda50e0 100644 --- a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/ExpectedTestOutput.test +++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/ExpectedTestOutput.test @@ -141637,6 +141637,114 @@ NULL [external object] [1] 1 2 3 +##com.oracle.truffle.r.test.library.fastr.TestJavaInterop.testArraysWithNullConversion# +#if (!any(R.version$engine == "FastR")) { list('a', NULL, 'c') } else { ta <- new('com.oracle.truffle.r.test.library.fastr.TestJavaInterop$TestArraysClass');as.vector(ta$charObjectArrayWithNull) } +[[1]] +[1] "a" + +[[2]] +NULL + +[[3]] +[1] "c" + + +##com.oracle.truffle.r.test.library.fastr.TestJavaInterop.testArraysWithNullConversion# +#if (!any(R.version$engine == "FastR")) { list('a', NULL, 'c') } else { ta <- new('com.oracle.truffle.r.test.library.fastr.TestJavaInterop$TestArraysClass');as.vector(ta$stringArrayWithNull) } +[[1]] +[1] "a" + +[[2]] +NULL + +[[3]] +[1] "c" + + +##com.oracle.truffle.r.test.library.fastr.TestJavaInterop.testArraysWithNullConversion# +#if (!any(R.version$engine == "FastR")) { list(1, NULL, 3) } else { ta <- new('com.oracle.truffle.r.test.library.fastr.TestJavaInterop$TestArraysClass');as.vector(ta$byteObjectArrayWithNull) } +[[1]] +[1] 1 + +[[2]] +NULL + +[[3]] +[1] 3 + + +##com.oracle.truffle.r.test.library.fastr.TestJavaInterop.testArraysWithNullConversion# +#if (!any(R.version$engine == "FastR")) { list(1, NULL, 3) } else { ta <- new('com.oracle.truffle.r.test.library.fastr.TestJavaInterop$TestArraysClass');as.vector(ta$longObjectArrayWithNull) } +[[1]] +[1] 1 + +[[2]] +NULL + +[[3]] +[1] 3 + + +##com.oracle.truffle.r.test.library.fastr.TestJavaInterop.testArraysWithNullConversion# +#if (!any(R.version$engine == "FastR")) { list(1.1, NULL, 1.3) } else { ta <- new('com.oracle.truffle.r.test.library.fastr.TestJavaInterop$TestArraysClass');as.vector(ta$doubleObjectArrayWithNull) } +[[1]] +[1] 1.1 + +[[2]] +NULL + +[[3]] +[1] 1.3 + + +##com.oracle.truffle.r.test.library.fastr.TestJavaInterop.testArraysWithNullConversion# +#if (!any(R.version$engine == "FastR")) { list(1.1, NULL, 1.3) } else { ta <- new('com.oracle.truffle.r.test.library.fastr.TestJavaInterop$TestArraysClass');as.vector(ta$floatObjectArrayWithNull) } +[[1]] +[1] 1.1 + +[[2]] +NULL + +[[3]] +[1] 1.3 + + +##com.oracle.truffle.r.test.library.fastr.TestJavaInterop.testArraysWithNullConversion# +#if (!any(R.version$engine == "FastR")) { list(1L, NULL, 3L) } else { ta <- new('com.oracle.truffle.r.test.library.fastr.TestJavaInterop$TestArraysClass');as.vector(ta$integerObjectArrayWithNull) } +[[1]] +[1] 1 + +[[2]] +NULL + +[[3]] +[1] 3 + + +##com.oracle.truffle.r.test.library.fastr.TestJavaInterop.testArraysWithNullConversion# +#if (!any(R.version$engine == "FastR")) { list(1L, NULL, 3L) } else { ta <- new('com.oracle.truffle.r.test.library.fastr.TestJavaInterop$TestArraysClass');as.vector(ta$shortObjectArrayWithNull) } +[[1]] +[1] 1 + +[[2]] +NULL + +[[3]] +[1] 3 + + +##com.oracle.truffle.r.test.library.fastr.TestJavaInterop.testArraysWithNullConversion# +#if (!any(R.version$engine == "FastR")) { list(T, NULL, T) } else { ta <- new('com.oracle.truffle.r.test.library.fastr.TestJavaInterop$TestArraysClass');as.vector(ta$booleanObjectArrayWithNull) } +[[1]] +[1] TRUE + +[[2]] +NULL + +[[3]] +[1] TRUE + + ##com.oracle.truffle.r.test.library.fastr.TestJavaInterop.testAsList# #if (!any(R.version$engine == "FastR")) { 'a' } else { to <- new.external(new.java.class('com.oracle.truffle.r.test.library.fastr.TestJavaInterop$TestClass')); l<-as.list(to$arrayObject); l[[1]]$data } [1] "a" diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/library/fastr/TestJavaInterop.java b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/library/fastr/TestJavaInterop.java index 23b4808a091a254bddc3bbeec0e9e575bf1a2d05..71b89793172a4d91a5923a661260dc8bea015be4 100644 --- a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/library/fastr/TestJavaInterop.java +++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/library/fastr/TestJavaInterop.java @@ -1105,6 +1105,19 @@ public class TestJavaInterop extends TestBase { assertEvalFastR(CREATE_TEST_ARRAYS + " ifelse(ta$stringList, 1, 2)", "c(NA, NA, NA)"); } + @Test + public void testArraysWithNullConversion() throws IllegalArgumentException { + assertEvalFastR(CREATE_TEST_ARRAYS + "as.vector(ta$booleanObjectArrayWithNull)", "list(T, NULL, T)"); + assertEvalFastR(CREATE_TEST_ARRAYS + "as.vector(ta$byteObjectArrayWithNull)", "list(1, NULL, 3)"); + assertEvalFastR(CREATE_TEST_ARRAYS + "as.vector(ta$charObjectArrayWithNull)", "list('a', NULL, 'c')"); + assertEvalFastR(CREATE_TEST_ARRAYS + "as.vector(ta$doubleObjectArrayWithNull)", "list(1.1, NULL, 1.3)"); + assertEvalFastR(CREATE_TEST_ARRAYS + "as.vector(ta$floatObjectArrayWithNull)", "list(1.1, NULL, 1.3)"); + assertEvalFastR(CREATE_TEST_ARRAYS + "as.vector(ta$integerObjectArrayWithNull)", "list(1L, NULL, 3L)"); + assertEvalFastR(CREATE_TEST_ARRAYS + "as.vector(ta$longObjectArrayWithNull)", "list(1, NULL, 3)"); + assertEvalFastR(CREATE_TEST_ARRAYS + "as.vector(ta$shortObjectArrayWithNull)", "list(1L, NULL, 3L)"); + assertEvalFastR(CREATE_TEST_ARRAYS + "as.vector(ta$stringArrayWithNull)", "list('a', NULL, 'c')"); + } + @Test public void testForeignVectorArithmeticOp() throws NoSuchFieldException, IllegalAccessException { @@ -2216,38 +2229,47 @@ public class TestJavaInterop extends TestBase { public Boolean[] booleanObjectArray = {true, false, true}; public Boolean[][] booleanObjectArray2 = {{true, false, true}, {true, false, true}}; public Boolean[][][] booleanObjectArray3 = {{{true, false, true}, {true, false, true}}, {{true, false, true}, {true, false, true}}}; + public Boolean[] booleanObjectArrayWithNull = {true, null, true}; public Byte[] byteObjectArray = {1, 2, 3}; public Byte[][] byteObjectArray2 = {{1, 2, 3}, {1, 2, 3}}; public Byte[][][] byteObjectArray3 = {{{1, 2, 3}, {1, 2, 3}}, {{1, 2, 3}, {1, 2, 3}}}; + public Byte[] byteObjectArrayWithNull = {1, null, 3}; public Character[] charObjectArray = {'a', 'b', 'c'}; public Character[][] charObjectArray2 = {{'a', 'b', 'c'}, {'a', 'b', 'c'}}; public Character[][][] charObjectArray3 = {{{'a', 'b', 'c'}, {'a', 'b', 'c'}}, {{'a', 'b', 'c'}, {'a', 'b', 'c'}}}; + public Character[] charObjectArrayWithNull = {'a', null, 'c'}; public Double[] doubleObjectArray = {1.1, 1.2, 1.3}; public Double[][] doubleObjectArray2 = {{1.1, 1.2, 1.3}, {1.1, 1.2, 1.3}}; public Double[][][] doubleObjectArray3 = {{{1.1, 1.2, 1.3}, {1.1, 1.2, 1.3}}, {{1.1, 1.2, 1.3}, {1.1, 1.2, 1.3}}}; + public Double[] doubleObjectArrayWithNull = {1.1, null, 1.3}; public Float[] floatObjectArray = {1.1f, 1.2f, 1.3f}; public Float[][] floatObjectArray2 = {{1.1f, 1.2f, 1.3f}, {1.1f, 1.2f, 1.3f}}; public Float[][][] floatObjectArray3 = {{{1.1f, 1.2f, 1.3f}, {1.1f, 1.2f, 1.3f}}, {{1.1f, 1.2f, 1.3f}, {1.1f, 1.2f, 1.3f}}}; + public Float[] floatObjectArrayWithNull = {1.1f, null, 1.3f}; public Integer[] integerObjectArray = {1, 2, 3}; public Integer[][] integerObjectArray2 = {{1, 2, 3}, {1, 2, 3}}; public Integer[][][] integerObjectArray3 = {{{1, 2, 3}, {1, 2, 3}}, {{1, 2, 3}, {1, 2, 3}}}; + public Integer[] integerObjectArrayWithNull = {1, null, 3}; public Long[] longObjectArray = {1L, 2L, 3L}; public Long[][] longObjectArray2 = {{1L, 2L, 3L}, {1L, 2L, 3L}}; public Long[][][] longObjectArray3 = {{{1L, 2L, 3L}, {1L, 2L, 3L}}, {{1L, 2L, 3L}, {1L, 2L, 3L}}}; + public Long[] longObjectArrayWithNull = {1L, null, 3L}; public Short[] shortObjectArray = {1, 2, 3}; public Short[][] shortObjectArray2 = {{1, 2, 3}, {1, 2, 3}}; public Short[][][] shortObjectArray3 = {{{1, 2, 3}, {1, 2, 3}}, {{1, 2, 3}, {1, 2, 3}}}; + public Short[] shortObjectArrayWithNull = {1, null, 3}; public String[] stringArray = {"a", "b", "c"}; public String[][] stringArray2 = {{"a", "b", "c"}, {"a", "b", "c"}}; public String[][][] stringArray3 = {{{"a", "b", "c"}, {"a", "b", "c"}}, {{"a", "b", "c"}, {"a", "b", "c"}}}; + public String[] stringArrayWithNull = {"a", null, "c"}; public Object[] onlyIntegerObjectArray = {1, 2, 3}; public Object[] onlyLongObjectArray = {1L, 2L, 3L};