File: test-repeat_linter.R

package info (click to toggle)
r-cran-lintr 3.2.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 4,396 kB
  • sloc: sh: 13; xml: 10; makefile: 2
file content (27 lines) | stat: -rw-r--r-- 923 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
test_that("test repeat_linter", {
  linter <- repeat_linter()
  msg <- rex::rex("Use 'repeat' instead of 'while (TRUE)' for infinite loops.")

  expect_lint("repeat { }", NULL, linter)
  expect_lint("while (FALSE) { }", NULL, linter)
  expect_lint("while (i < 5) { }", NULL, linter)
  expect_lint("while (j < 5) TRUE", NULL, linter)
  expect_lint("while (TRUE && j < 5) { ... }", NULL, linter)

  expect_lint("while (TRUE) { }", msg, linter)
  expect_lint("for (i in 1:10) { while (TRUE) { if (i == 5) { break } } }", msg, linter)
  expect_lint("while (TRUE) { while (TRUE) { } }", list(msg, msg), linter)
  expect_lint(
    trim_some("{
      while (TRUE) {
      }
      while (TRUE) {
      }
    }"),
    list(
      list(message = msg, line_number = 2L, column_number = 3L, ranges = list(c(3L, 14L))),
      list(message = msg, line_number = 4L, column_number = 3L, ranges = list(c(3L, 14L)))
    ),
    linter
  )
})