@@ -695,3 +695,134 @@ testthat::test_that("data() call is returned when data name is provided as a cha
695695 )
696696 )
697697})
698+
699+ testthat :: describe(" Backticked symbol" , {
700+ testthat :: it(" code can be retrieved with get_code" , {
701+ td <- within(
702+ teal_data(),
703+ {
704+ `%cbind%` <- function (lhs , rhs ) cbind(lhs , rhs ) # nolint: object_name.
705+ iris_ds <- iris %cbind % data.frame (new_col = " new column" )
706+ }
707+ )
708+
709+ testthat :: expect_identical(
710+ get_code(td , datanames = " %cbind%" ),
711+ " `%cbind%` <- function(lhs, rhs) cbind(lhs, rhs)"
712+ )
713+ })
714+
715+ testthat :: it(" code can be retrieved with get_code" , {
716+ td <- within(
717+ teal_data(),
718+ {
719+ `%cbind%` <- function (lhs , rhs ) cbind(lhs , rhs ) # nolint: object_name.
720+ iris_ds <- iris %cbind % data.frame (new_col = " new column" )
721+ }
722+ )
723+
724+ testthat :: expect_identical(
725+ get_code(td , datanames = " `%cbind%`" ),
726+ " `%cbind%` <- function(lhs, rhs) cbind(lhs, rhs)"
727+ )
728+ })
729+
730+ testthat :: it(" starting with underscore is detected in code dependency" , {
731+ td <- within(
732+ teal_data(),
733+ {
734+ `_add_column_` <- function (lhs , rhs ) cbind(lhs , rhs ) # nolint: object_name.
735+ iris_ds <- `_add_column_`(iris , data.frame (new_col = " new column" ))
736+ }
737+ )
738+
739+ testthat :: expect_identical(
740+ get_code(td , datanames = " iris_ds" ),
741+ paste(
742+ sep = " \n " ,
743+ " `_add_column_` <- function(lhs, rhs) cbind(lhs, rhs)" ,
744+ " iris_ds <- `_add_column_`(iris, data.frame(new_col = \" new column\" ))"
745+ )
746+ )
747+ })
748+
749+ testthat :: it(" with space character is detected in code dependency" , {
750+ td <- within(
751+ teal_data(),
752+ {
753+ `add column` <- function (lhs , rhs ) cbind(lhs , rhs ) # nolint: object_name.
754+ iris_ds <- `add column`(iris , data.frame (new_col = " new column" ))
755+ }
756+ )
757+
758+ testthat :: expect_identical(
759+ get_code(td , datanames = " iris_ds" ),
760+ paste(
761+ sep = " \n " ,
762+ " `add column` <- function(lhs, rhs) cbind(lhs, rhs)" ,
763+ " iris_ds <- `add column`(iris, data.frame(new_col = \" new column\" ))"
764+ )
765+ )
766+ })
767+
768+ testthat :: it(" without special characters is cleaned and detected in code dependency" , {
769+ td <- within(
770+ teal_data(),
771+ {
772+ `add_column` <- function (lhs , rhs ) cbind(lhs , rhs )
773+ iris_ds <- `add_column`(iris , data.frame (new_col = " new column" ))
774+ }
775+ )
776+
777+ testthat :: expect_identical(
778+ get_code(td , datanames = " iris_ds" ),
779+ paste(
780+ sep = " \n " ,
781+ " add_column <- function(lhs, rhs) cbind(lhs, rhs)" ,
782+ " iris_ds <- add_column(iris, data.frame(new_col = \" new column\" ))"
783+ )
784+ )
785+ })
786+
787+ testthat :: it(" with non-native pipe used as function is detected code dependency" , {
788+ td <- within(
789+ teal_data(),
790+ {
791+ `%add_column%` <- function (lhs , rhs ) cbind(lhs , rhs )
792+ iris_ds <- `%add_column%`(iris , data.frame (new_col = " new column" ))
793+ }
794+ )
795+
796+ # Note that the original code is changed to use the non-native pipe operator
797+ # correctly.
798+ testthat :: expect_identical(
799+ get_code(td , datanames = " iris_ds" ),
800+ paste(
801+ sep = " \n " ,
802+ " `%add_column%` <- function(lhs, rhs) cbind(lhs, rhs)" ,
803+ " iris_ds <- iris %add_column% data.frame(new_col = \" new column\" )"
804+ )
805+ )
806+ })
807+
808+ testthat :: it(" with non-native pipe is detected code dependency" , {
809+ td <- within(
810+ teal_data(),
811+ {
812+ `%add_column%` <- function (lhs , rhs ) cbind(lhs , rhs )
813+ iris_ds <- iris %add_column % data.frame (new_col = " new column" )
814+ }
815+ )
816+
817+ # Note that the original code is changed to use the non-native pipe operator
818+ # correctly.
819+ testthat :: expect_identical(
820+ get_code(td , datanames = " iris_ds" ),
821+ paste(
822+ sep = " \n " ,
823+ " `%add_column%` <- function(lhs, rhs) cbind(lhs, rhs)" ,
824+ " iris_ds <- iris %add_column% data.frame(new_col = \" new column\" )"
825+ )
826+ )
827+ })
828+ })
0 commit comments