@@ -740,3 +740,135 @@ testthat::test_that("data() call is returned when data name is provided as a cha
740740 )
741741 )
742742})
743+
744+
745+ testthat :: describe(" Backticked symbol" , {
746+ testthat :: it(" code can be retrieved with get_code" , {
747+ td <- within(
748+ teal_data(),
749+ {
750+ `%cbind%` <- function (lhs , rhs ) cbind(lhs , rhs ) # nolint: object_name.
751+ iris_ds <- iris %cbind % data.frame (new_col = " new column" )
752+ }
753+ )
754+
755+ testthat :: expect_identical(
756+ get_code(td , datanames = " %cbind%" ),
757+ " `%cbind%` <- function(lhs, rhs) cbind(lhs, rhs)"
758+ )
759+ })
760+
761+ testthat :: it(" code can be retrieved with get_code" , {
762+ td <- within(
763+ teal_data(),
764+ {
765+ `%cbind%` <- function (lhs , rhs ) cbind(lhs , rhs ) # nolint: object_name.
766+ iris_ds <- iris %cbind % data.frame (new_col = " new column" )
767+ }
768+ )
769+
770+ testthat :: expect_identical(
771+ get_code(td , datanames = " `%cbind%`" ),
772+ " `%cbind%` <- function(lhs, rhs) cbind(lhs, rhs)"
773+ )
774+ })
775+
776+ testthat :: it(" starting with underscore is detected in code dependency" , {
777+ td <- within(
778+ teal_data(),
779+ {
780+ `_add_column_` <- function (lhs , rhs ) cbind(lhs , rhs ) # nolint: object_name.
781+ iris_ds <- `_add_column_`(iris , data.frame (new_col = " new column" ))
782+ }
783+ )
784+
785+ testthat :: expect_identical(
786+ get_code(td , datanames = " iris_ds" ),
787+ paste(
788+ sep = " \n " ,
789+ " `_add_column_` <- function(lhs, rhs) cbind(lhs, rhs)" ,
790+ " iris_ds <- `_add_column_`(iris, data.frame(new_col = \" new column\" ))"
791+ )
792+ )
793+ })
794+
795+ testthat :: it(" with space character is detected in code dependency" , {
796+ td <- within(
797+ teal_data(),
798+ {
799+ `add column` <- function (lhs , rhs ) cbind(lhs , rhs ) # nolint: object_name.
800+ iris_ds <- `add column`(iris , data.frame (new_col = " new column" ))
801+ }
802+ )
803+
804+ testthat :: expect_identical(
805+ get_code(td , datanames = " iris_ds" ),
806+ paste(
807+ sep = " \n " ,
808+ " `add column` <- function(lhs, rhs) cbind(lhs, rhs)" ,
809+ " iris_ds <- `add column`(iris, data.frame(new_col = \" new column\" ))"
810+ )
811+ )
812+ })
813+
814+ testthat :: it(" without special characters is cleaned and detected in code dependency" , {
815+ td <- within(
816+ teal_data(),
817+ {
818+ `add_column` <- function (lhs , rhs ) cbind(lhs , rhs )
819+ iris_ds <- `add_column`(iris , data.frame (new_col = " new column" ))
820+ }
821+ )
822+
823+ testthat :: expect_identical(
824+ get_code(td , datanames = " iris_ds" ),
825+ paste(
826+ sep = " \n " ,
827+ " add_column <- function(lhs, rhs) cbind(lhs, rhs)" ,
828+ " iris_ds <- add_column(iris, data.frame(new_col = \" new column\" ))"
829+ )
830+ )
831+ })
832+
833+ testthat :: it(" with non-native pipe used as function is detected code dependency" , {
834+ td <- within(
835+ teal_data(),
836+ {
837+ `%add_column%` <- function (lhs , rhs ) cbind(lhs , rhs )
838+ iris_ds <- `%add_column%`(iris , data.frame (new_col = " new column" ))
839+ }
840+ )
841+
842+ # Note that the original code is changed to use the non-native pipe operator
843+ # correctly.
844+ testthat :: expect_identical(
845+ get_code(td , datanames = " iris_ds" ),
846+ paste(
847+ sep = " \n " ,
848+ " `%add_column%` <- function(lhs, rhs) cbind(lhs, rhs)" ,
849+ " iris_ds <- iris %add_column% data.frame(new_col = \" new column\" )"
850+ )
851+ )
852+ })
853+
854+ testthat :: it(" with non-native pipe is detected code dependency" , {
855+ td <- within(
856+ teal_data(),
857+ {
858+ `%add_column%` <- function (lhs , rhs ) cbind(lhs , rhs )
859+ iris_ds <- iris %add_column % data.frame (new_col = " new column" )
860+ }
861+ )
862+
863+ # Note that the original code is changed to use the non-native pipe operator
864+ # correctly.
865+ testthat :: expect_identical(
866+ get_code(td , datanames = " iris_ds" ),
867+ paste(
868+ sep = " \n " ,
869+ " `%add_column%` <- function(lhs, rhs) cbind(lhs, rhs)" ,
870+ " iris_ds <- iris %add_column% data.frame(new_col = \" new column\" )"
871+ )
872+ )
873+ })
874+ })
0 commit comments