Skip to content

Commit

Permalink
fix: use cbind and data.frame in tests instead of dplyr
Browse files Browse the repository at this point in the history
  • Loading branch information
averissimo committed Oct 16, 2024
1 parent fcb9c4a commit 619e3ae
Showing 1 changed file with 20 additions and 20 deletions.
40 changes: 20 additions & 20 deletions tests/testthat/test-get_code.R
Original file line number Diff line number Diff line change
Expand Up @@ -700,59 +700,59 @@ testthat::describe("Backticked symbol", {
testthat::it("starting with underscore is detected in code dependency", {
td <- teal_data() |>
within({
`_add_column_` <- function(lhs, rhs) dplyr::bind_cols(lhs, rhs) # nolint: object_name.
iris_ds <- `_add_column_`(iris, dplyr::tibble(new_col = "new column"))
`_add_column_` <- function(lhs, rhs) cbind(lhs, rhs) # nolint: object_name.
iris_ds <- `_add_column_`(iris, data.frame(new_col = "new column"))
})

testthat::expect_identical(
get_code(td, datanames = "iris_ds"),
paste(
sep = "\n",
"`_add_column_` <- function(lhs, rhs) dplyr::bind_cols(lhs, rhs)",
"iris_ds <- `_add_column_`(iris, dplyr::tibble(new_col = \"new column\"))"
"`_add_column_` <- function(lhs, rhs) cbind(lhs, rhs)",
"iris_ds <- `_add_column_`(iris, data.frame(new_col = \"new column\"))"
)
)
})

testthat::it("with space character is detected in code dependency", {
td <- teal_data() |>
within({
`add column` <- function(lhs, rhs) dplyr::bind_cols(lhs, rhs) # nolint: object_name.
iris_ds <- `add column`(iris, dplyr::tibble(new_col = "new column"))
`add column` <- function(lhs, rhs) cbind(lhs, rhs) # nolint: object_name.
iris_ds <- `add column`(iris, data.frame(new_col = "new column"))
})

testthat::expect_identical(
get_code(td, datanames = "iris_ds"),
paste(
sep = "\n",
"`add column` <- function(lhs, rhs) dplyr::bind_cols(lhs, rhs)",
"iris_ds <- `add column`(iris, dplyr::tibble(new_col = \"new column\"))"
"`add column` <- function(lhs, rhs) cbind(lhs, rhs)",
"iris_ds <- `add column`(iris, data.frame(new_col = \"new column\"))"
)
)
})

testthat::it("without special characters is cleaned and detecteed in code dependency", {
td <- teal_data() |>
within({
`add_column` <- function(lhs, rhs) dplyr::bind_cols(lhs, rhs)
iris_ds <- `add_column`(iris, dplyr::tibble(new_col = "new column"))
`add_column` <- function(lhs, rhs) cbind(lhs, rhs)
iris_ds <- `add_column`(iris, data.frame(new_col = "new column"))
})

testthat::expect_identical(
get_code(td, datanames = "iris_ds"),
paste(
sep = "\n",
"add_column <- function(lhs, rhs) dplyr::bind_cols(lhs, rhs)",
"iris_ds <- add_column(iris, dplyr::tibble(new_col = \"new column\"))"
"add_column <- function(lhs, rhs) cbind(lhs, rhs)",
"iris_ds <- add_column(iris, data.frame(new_col = \"new column\"))"
)
)
})

testthat::it("with non-native pipe used as function is detected code dependency", {
td <- teal_data() |>
within({
`%add_column%` <- function(lhs, rhs) dplyr::bind_cols(lhs, rhs)
iris_ds <- `%add_column%`(iris, dplyr::tibble(new_col = "new column"))
`%add_column%` <- function(lhs, rhs) cbind(lhs, rhs)
iris_ds <- `%add_column%`(iris, data.frame(new_col = "new column"))
})

# Note that the original code is changed to use the non-native pipe operator
Expand All @@ -761,17 +761,17 @@ testthat::describe("Backticked symbol", {
get_code(td, datanames = "iris_ds"),
paste(
sep = "\n",
"`%add_column%` <- function(lhs, rhs) dplyr::bind_cols(lhs, rhs)",
"iris_ds <- iris %add_column% dplyr::tibble(new_col = \"new column\")"
"`%add_column%` <- function(lhs, rhs) cbind(lhs, rhs)",
"iris_ds <- iris %add_column% data.frame(new_col = \"new column\")"
)
)
})

testthat::it("with non-native pipe is detected code dependency", {
td <- teal_data() |>
within({
`%add_column%` <- function(lhs, rhs) dplyr::bind_cols(lhs, rhs)
iris_ds <- iris %add_column% dplyr::tibble(new_col = "new column")
`%add_column%` <- function(lhs, rhs) cbind(lhs, rhs)
iris_ds <- iris %add_column% data.frame(new_col = "new column")
})

# Note that the original code is changed to use the non-native pipe operator
Expand All @@ -780,8 +780,8 @@ testthat::describe("Backticked symbol", {
get_code(td, datanames = "iris_ds"),
paste(
sep = "\n",
"`%add_column%` <- function(lhs, rhs) dplyr::bind_cols(lhs, rhs)",
"iris_ds <- iris %add_column% dplyr::tibble(new_col = \"new column\")"
"`%add_column%` <- function(lhs, rhs) cbind(lhs, rhs)",
"iris_ds <- iris %add_column% data.frame(new_col = \"new column\")"
)
)
})
Expand Down

0 comments on commit 619e3ae

Please sign in to comment.