thisisnic commented on a change in pull request #10624:
URL: https://github.com/apache/arrow/pull/10624#discussion_r664040870



##########
File path: r/tests/testthat/test-dplyr-string-functions.R
##########
@@ -866,3 +866,57 @@ test_that("str_like", {
     df
   )
 })
+
+test_that("substrings", {
+  df <- tibble(
+    x = "Apache Arrow"
+  )
+
+  expect_dplyr_equal(
+    input %>%
+      mutate(
+        foo = "Apache Arrow",
+        bar1 = substr(foo, 1, 6), # Apache
+        bar2 = substr(foo, 0, 6), # Apache
+        bar3 = substr(foo, -1, 6), # Apache
+        bar4 = substr(foo, 6, 1), # ""
+        bar5 = substr(foo, -1, -2), # ""
+        bar6 = substr(foo, 8, 12) # Arrow
+      ) %>%
+      select(bar1:bar6) %>%
+      collect(),
+    df
+  )
+
+  expect_dplyr_equal(
+    input %>%
+      mutate(
+        foo = "Apache Arrow",
+        bar1 = substring(foo, 1, 6), # Apache
+        bar2 = substring(foo, 0, 6), # Apache
+        bar3 = substring(foo, -1, 6), # Apache
+        bar4 = substring(foo, 6, 1), # ""
+        bar5 = substring(foo, -1, -2), # ""
+        bar6 = substring(foo, 8, 12) # Arrow
+      ) %>%
+      select(bar1:bar6) %>%
+      collect(),
+    df
+  )
+
+  expect_dplyr_equal(
+    input %>%
+      mutate(
+        foo = "Apache Arrow",
+        bar1 = str_sub(foo, 1, 6), # Apache
+        bar2 = str_sub(foo, 0, 6), # Apache
+        bar3 = str_sub(foo, -1, 6), # Apache
+        bar4 = str_sub(foo, 6, 1), # ""
+        bar5 = str_sub(foo, -1, -2), # ""
+        bar6 = str_sub(foo, 8, 12) # Arrow
+      ) %>%
+      select(bar1:bar6) %>%
+      collect(),
+    df
+  )
+})

Review comment:
       ```suggestion
   test_that("substrings", {
     df <- tibble(
       x = "Apache Arrow"
     )
     
     # substr
   
     expect_dplyr_equal(
       input %>%
         mutate(y = substr(x, 1, 6)) %>%
         collect(),
       df
     )
     
     expect_dplyr_equal(
       input %>%
         mutate(y = substr(x, 0, 6)) %>%
         collect(),
       df
     )
     
     expect_dplyr_equal(
       input %>%
         mutate(y = substr(x, -1, 6)) %>% 
         collect(),
       df
     )
     
     expect_dplyr_equal(
       input %>%
         mutate(y = substr(x, 6, 1)) %>% 
         collect(),
       df
     )
     
     expect_dplyr_equal(
       input %>%
         mutate(y = substr(x, -1, -2)) %>%
         collect(),
       df
     )
     
     expect_dplyr_equal(
       input %>%
         mutate(y = substr(x, 1, 6)) %>% 
         collect(),
       df
     )
     
     expect_dplyr_equal(
       input %>%
         mutate(y = substr(x,  8, 12)) %>%
         collect(),
       df
     )
     
     expect_dplyr_equal(
       input %>%
         mutate(y = substr(x, -5, -1)) %>% 
         collect(),
       df
     )
   
     # substring
     
     expect_dplyr_equal(
       input %>%
         mutate(y = substring(x, 1, 6)) %>%
         collect(),
       df
     )
     
     expect_dplyr_equal(
       input %>%
         mutate(y = substring(x, 0, 6)) %>%
         collect(),
       df
     )
     
     expect_dplyr_equal(
       input %>%
         mutate(y = substring(x, -1, 6)) %>% 
         collect(),
       df
     )
     
     expect_dplyr_equal(
       input %>%
         mutate(y = substring(x, 6, 1)) %>% 
         collect(),
       df
     )
     
     expect_dplyr_equal(
       input %>%
         mutate(y = substring(x, -1, -2)) %>%
         collect(),
       df
     )
     
     expect_dplyr_equal(
       input %>%
         mutate(y = substring(x, 1, 6)) %>% 
         collect(),
       df
     )
     
     
     expect_dplyr_equal(
       input %>%
         mutate(y = substring(x,  8, 12)) %>%
         collect(),
       df
     )
     
     expect_dplyr_equal(
       input %>%
         mutate(y = substring(x, -5, -1)) %>% 
         collect(),
       df
     )
   
     # str_sub
     
     expect_dplyr_equal(
       input %>%
         mutate(y = str_sub(x, 1, 6)) %>% 
         collect(),
       df
     )
     
     expect_dplyr_equal(
       input %>%
         mutate(y = str_sub(x, 0, 6)) %>% 
         collect(),
       df
     )
     
     expect_dplyr_equal(
       input %>%
         mutate(y = str_sub(x, -1, 6)) %>% 
         collect(),
       df
     )
     
     expect_dplyr_equal(
       input %>%
         mutate(y = str_sub(x, 6, 1)) %>% 
         collect(),
       df
     )
     
     expect_dplyr_equal(
       input %>%
         mutate(y = str_sub(x, -1, -2)) %>% 
         collect(),
       df
     )
     
     expect_dplyr_equal(
       input %>%
         mutate(y = str_sub(x, 1, 6)) %>% 
         collect(),
       df
     )
     
     
     expect_dplyr_equal(
       input %>%
         mutate(y = str_sub(x,  8, 12)) %>% 
         collect(),
       df
     )
     
     expect_dplyr_equal(
       input %>%
         mutate(y = str_sub(x, -5, -1)) %>% 
         collect(),
       df
     )
     
   })
   
   ```




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to