Skip to content

Commit

Permalink
Adapt tests to upcoming {patrick} release (#2709)
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelChirico authored Jan 16, 2025
1 parent eb6abc8 commit b6d945d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 24 deletions.
17 changes: 7 additions & 10 deletions tests/testthat/test-fixed_regex_linter.R
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ test_that("fixed_regex_linter blocks simple disallowed usages", {
})

patrick::with_parameters_test_that(
"fixed_regex_linter is robust to unrecognized escapes error",
"fixed_regex_linter is robust to unrecognized escapes error for {char}",
{
expect_lint(
sprintf(R"{grep('\\%s', x)}", char),
Expand All @@ -56,14 +56,11 @@ patrick::with_parameters_test_that(
fixed_regex_linter()
)
},
.cases = local({
char <- c(
"^", "$", "{", "}", "(", ")", ".", "*", "+", "?",
"|", "[", "]", R"(\\)", "<", ">", "=", ":", ";", "/",
"_", "-", "!", "@", "#", "%", "&", "~"
)
data.frame(char = char, .test_name = char)
})
char = c(
"^", "$", "{", "}", "(", ")", ".", "*", "+", "?",
"|", "[", "]", R"(\\)", "<", ">", "=", ":", ";", "/",
"_", "-", "!", "@", "#", "%", "&", "~"
)
)

test_that("fixed_regex_linter catches regex like [.] or [$]", {
Expand Down Expand Up @@ -326,7 +323,7 @@ local({
skip_cases <- character()
}
patrick::with_parameters_test_that(
"fixed replacements are correct",
"fixed replacements of {regex_expr} with {fixed_expr} is correct",
{
# TODO(google/patrick#19): handle this more cleanly by skipping up-front
skip_if(
Expand Down
23 changes: 9 additions & 14 deletions tests/testthat/test-pipe_continuation_linter.R
Original file line number Diff line number Diff line change
Expand Up @@ -138,55 +138,50 @@ test_that("pipe-continuation linter handles native pipe", {

local({
linter <- pipe_continuation_linter()
valid_code <- c(
# all on one line
.cases <- tibble::tribble(
~code_string, ~.test_name,
trim_some("
my_fun <- function() {
a %>% b()
}
"),
"), "two on one line",
trim_some("
my_fun <- function() {
a %>% b() %>% c()
}
"),
"), "three on one line",
trim_some("
with(
diamonds,
x %>% head(10) %>% tail(5)
)
"),
"), "three inside with()",
trim_some("
test_that('blah', {
test_data <- diamonds %>% head(10) %>% tail(5)
})
"),

# two different single-line pipelines
"), "three inside test_that()",
trim_some("
{
x <- a %>% b %>% c
y <- c %>% b %>% a
}
"),

# at most one pipe-character per line
"), "two different single-line pipelines",
trim_some("
my_fun <- function() {
a %>%
b() %>%
c()
}
")
"), "at most one pipe-character per line"
)
patrick::with_parameters_test_that(
"valid nesting is handled",
# nolint next: unnecessary_nesting_linter. TODO(#2334): Remove this nolint.
{
expect_lint(code_string, NULL, linter)
},
.test_name = valid_code,
code_string = valid_code
.cases = .cases
)
})

Expand Down

0 comments on commit b6d945d

Please sign in to comment.