Skip to content

Commit

Permalink
add tests for with_id and ids_with_token (#1114)
Browse files Browse the repository at this point in the history
* add tests for with_id and ids_with_token

fixes #1101

* implicit integer

Co-authored-by: Michael Chirico <chiricom@google.com>
  • Loading branch information
AshesITR and MichaelChirico authored Apr 28, 2022
1 parent a530a73 commit 36a18e0
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
3 changes: 1 addition & 2 deletions tests/testthat/test-get_source_expressions.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ with_content_to_parse <- function(content, code) {
eval(substitute(code), envir = content_env)
}


test_that("tab positions have been corrected", {
with_content_to_parse("1\n\t",
expect_length(pc, 2L)
Expand All @@ -26,7 +25,7 @@ test_that("tab positions have been corrected", {
)

with_content_to_parse("\t\tTRUE",
expect_identical(unlist(pc[[1]][pc[[1L]][["text"]] == "TRUE", c("col1", "col2")], use.names = FALSE), c(3L, 6L))
expect_identical(unlist(pc[[1L]][pc[[1L]][["text"]] == "TRUE", c("col1", "col2")], use.names = FALSE), c(3L, 6L))
)

with_content_to_parse("x\t<-\tTRUE", {
Expand Down
13 changes: 13 additions & 0 deletions tests/testthat/test-ids_with_token.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
test_that("ids_with_token works as expected", {
source_expression <- get_source_expressions("tmp.R", "a <- 42L")$expressions[[1L]]
ref <- ids_with_token(source_expression = source_expression, value = "expr")
expect_equal(ref, c(1L, 3L, 6L))
expect_equal(source_expression$parsed_content$token[ref], rep_len("expr", length(ref)))

# deprecated argument
expect_warning(
old_arg <- ids_with_token(source_file = source_expression, value = "expr"),
"Argument source_file was deprecated"
)
expect_equal(old_arg, ref)
})
19 changes: 19 additions & 0 deletions tests/testthat/test-with_id.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
test_that("with_id works as expected", {
source_expression <- get_source_expressions("tmp.R", "a <- 42L")$expressions[[1L]]
ref <- with_id(
source_expression = source_expression,
ids_with_token(source_expression = source_expression, value = "expr")
)
expect_equal(ref, source_expression$parsed_content[c(1L, 3L, 6L), ])
expect_equal(ref$token, rep_len("expr", nrow(ref)))

# deprecated argument
expect_warning(
old_arg <- with_id(
source_file = source_expression,
id = ids_with_token(source_expression = source_expression, value = "expr")
),
"Argument source_file was deprecated"
)
expect_equal(old_arg, ref)
})

0 comments on commit 36a18e0

Please sign in to comment.