1context("unneeded_concatenation_linter")
2
3test_that("returns the correct linting", {
4  linter <- unneeded_concatenation_linter
5  msg_c <- rex::escape("Unneded concatenation of a constant. Remove the \"c\" call.")
6  msg_e <- rex::escape(
7    "Unneded concatenation without arguments. Replace the \"c\" call by NULL or vector().")
8
9  expect_lint("c(x)", NULL, linter)
10  expect_lint("c(1, 2)", NULL, linter)
11  expect_lint("c(x, recursive=TRUE)", NULL, linter)
12  expect_lint("c(1, recursive=FALSE)", NULL, linter)
13  expect_lint("lapply(1, c)", NULL, linter)
14
15  expect_lint("c()", list(message=msg_e, line_number=1L, column_number=1L), linter)
16  expect_lint("c(NULL)", list(message=msg_c, line_number=1L, column_number=1L), linter)
17  expect_lint("c(1)", list(message=msg_c, line_number=1L, column_number=1L), linter)
18  expect_lint("c (\n'a' )", list(message=msg_c, line_number=1L, column_number=1L), linter)
19  expect_lint("c(y, c('c('),\nc())",
20              list(
21                list(message=msg_c, line_number=1L, column_number=6L),
22                list(message=msg_e, line_number=2L, column_number=1L)
23              ),
24              linter)
25})
26
27