Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reorganize tests for unneeded_concatenation_linter() #1859

Merged
merged 3 commits into from
Dec 18, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 27 additions & 9 deletions tests/testthat/test-unneeded_concatenation_linter.R
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
test_that("returns the correct linting", {
test_that("unneeded_concatenation_linter skips allowed usages", {
linter <- unneeded_concatenation_linter()
msg_c <- rex::escape("Unneeded concatenation of a constant. Remove the \"c\" call.")
msg_e <- rex::escape(
"Unneeded concatenation without arguments. Replace the \"c\" call by NULL or, whenever possible, vector()"
)

expect_lint("c(x)", NULL, linter)
expect_lint("c(1, 2)", NULL, linter)
Expand All @@ -12,11 +8,33 @@ test_that("returns the correct linting", {
expect_lint("lapply(1, c)", NULL, linter)
expect_lint("c(a = 1)", NULL, linter)
expect_lint("c('a' = 1)", NULL, linter)
})

test_that("unneeded_concatenation_linter blocks disallowed usages", {
linter <- unneeded_concatenation_linter()
msg_c <- rex::escape('Unneeded concatenation of a constant. Remove the "c" call.')
msg_e <- rex::escape('Unneeded concatenation without arguments. Replace the "c" call by NULL')

expect_lint("c()", list(message = msg_e, line_number = 1L, column_number = 1L), linter)
expect_lint("c(NULL)", list(message = msg_c, line_number = 1L, column_number = 1L), linter)
expect_lint("c(1)", list(message = msg_c, line_number = 1L, column_number = 1L), linter)
expect_lint("c (\n'a' )", list(message = msg_c, line_number = 1L, column_number = 1L), linter)
expect_lint(
"c()",
list(message = msg_e, line_number = 1L, column_number = 1L),
linter
)
expect_lint(
"c(NULL)",
list(message = msg_c, line_number = 1L, column_number = 1L),
linter
)
expect_lint(
"c(1)",
list(message = msg_c, line_number = 1L, column_number = 1L),
linter
)
expect_lint(
"c (\n'a' )",
list(message = msg_c, line_number = 1L, column_number = 1L),
linter
)
expect_lint(
"c(y, c('c('),\nc())",
list(
Expand Down