Skip to content

Commit

Permalink
Add pipe_consistency tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bairdj committed Jul 24, 2023
1 parent f0fc3a2 commit 07f57dd
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions tests/testthat/test-pipe-consistency-linter.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
test_that("pipe_consistency skips allowed usage", {
expect_lint("1:3 %>% mean() %>% as.character()", NULL, pipe_consistency_linter())
expect_lint("1:3 |> mean() |> as.character()", NULL, pipe_consistency_linter())
# With no pipes
expect_lint("x <- 1:5", NULL, pipe_consistency_linter())
# Across multiple lines
expect_lint(
c("1:3 %>%", "mean() %>%", "as.character()"),
NULL,
pipe_consistency_linter()
)
})

test_that("pipe_consistency lints inconsistent usage", {
expected_msg <- rex::rex("Use consistent pipe operators (either all %>% or all |>).")
expect_lint(
"1:3 |> mean() %>% as.character()",
list(
list(message = expected_msg, line_number = 1L, column_number = 5L),
list(message = expected_msg, line_number = 1L, column_number = 15L)
),
pipe_consistency_linter()
)

expect_lint(
"1:3 %>% mean() |> as.character()",
list(
list(message = expected_msg, line_number = 1L, column_number = 5L),
list(message = expected_msg, line_number = 1L, column_number = 16L)
),
pipe_consistency_linter()
)

# Across lines
expect_lint(
c("1:3 %>%", "mean() |>", "as.character()"),
list(
list(message = expected_msg, line_number = 1L, column_number = 5L),
list(message = expected_msg, line_number = 2L, column_number = 8L)
),
pipe_consistency_linter()
)
})

0 comments on commit 07f57dd

Please sign in to comment.