From 24dabe814a0f06ca408a90787d3b43979f3cf90a Mon Sep 17 00:00:00 2001
From: Lukas Stadler <lukas.stadler@oracle.com>
Date: Thu, 23 Aug 2018 16:32:21 +0200
Subject: [PATCH] trim strings when casting to integer

---
 .../src/com/oracle/truffle/r/runtime/RRuntime.java            | 3 ++-
 .../src/com/oracle/truffle/r/test/ExpectedTestOutput.test     | 2 +-
 .../oracle/truffle/r/test/builtins/TestBuiltin_asinteger.java | 4 +---
 3 files changed, 4 insertions(+), 5 deletions(-)

diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/RRuntime.java b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/RRuntime.java
index 946ddaea7c..952fd55f57 100644
--- a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/RRuntime.java
+++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/RRuntime.java
@@ -450,7 +450,8 @@ public class RRuntime {
         // FIXME use R rules
         int result;
         try {
-            result = Integer.decode(Utils.trimLeadingZeros(s));  // decode supports hex constants
+            result = Integer.decode(Utils.trimLeadingZeros(s.trim()));  // decode supports hex
+                                                                        // constants
         } catch (NumberFormatException e) {
             if (exceptionOnFail) {
                 throw e;
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 32b76d9697..f2163da309 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
@@ -7377,7 +7377,7 @@ NAs introduced by coercion to integer range
 [551]  4  4  2  4  4  4  4  3  2  3  3  2 NA  3  4  4  3  3  4  4  4  1  4  4  4
 [576]  4  4  4  4  2  4  2  3  4  1  3  1 NA  4  1  2  2  1  4  3  3  4  1  1  3
 
-##com.oracle.truffle.r.test.builtins.TestBuiltin_asinteger.testasinteger2#Ignored.ImplementationError#
+##com.oracle.truffle.r.test.builtins.TestBuiltin_asinteger.testasinteger2#
 #argv <- list(c('   33', '   34', '   35', '   36', '   37', '   38', '   18', '   19', '   20', '   21', '   22', '   23', '   36', '   37', '   38', '   39'));as.integer(argv[[1]]);
  [1] 33 34 35 36 37 38 18 19 20 21 22 23 36 37 38 39
 
diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_asinteger.java b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_asinteger.java
index b4a10d8054..cfcf46fc1a 100644
--- a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_asinteger.java
+++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_asinteger.java
@@ -34,9 +34,7 @@ public class TestBuiltin_asinteger extends TestBase {
 
     @Test
     public void testasinteger2() {
-        // FIXME according to docs a leading whitespace should be accepted
-        assertEval(Ignored.ImplementationError,
-                        "argv <- list(c('   33', '   34', '   35', '   36', '   37', '   38', '   18', '   19', '   20', '   21', '   22', '   23', '   36', '   37', '   38', '   39'));as.integer(argv[[1]]);");
+        assertEval("argv <- list(c('   33', '   34', '   35', '   36', '   37', '   38', '   18', '   19', '   20', '   21', '   22', '   23', '   36', '   37', '   38', '   39'));as.integer(argv[[1]]);");
     }
 
     @Test
-- 
GitLab