File: test-utils.R

package info (click to toggle)
r-cran-formatr 1.14-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 376 kB
  • sloc: javascript: 19; sh: 10; makefile: 2
file content (22 lines) | stat: -rw-r--r-- 981 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
library(testit)

assert('move_leftbrace() works', {
  # no indent before abc, so no indent before {
  (move_leftbrace(c('abc() {', '    }')) %==% c('abc()', '{', '    }'))
  # 3 spaces before abc, 3 before {
  (move_leftbrace(c('   a() {', '}')) %==% c('   a()', '   {', '}'))
  (move_leftbrace(rep(c('   a() {', '}'), 5)) %==% rep(c('   a()', '   {', '}'), 5))
  # blank lines are not removed
  (move_leftbrace(c('a', '', 'b')) %==% c('a', '', 'b'))
  (move_leftbrace(c('if (TRUE) {', '  if (FALSE) {', '    1', '  }', '}')) %==%
      c('if (TRUE)', '{', '  if (FALSE)', '  {', '    1', '  }', '}'))
  (move_leftbrace(c('if (TRUE) {', '  1', '} else {', '  2}')) %==%
      c('if (TRUE)', '{', '  1', '} else', '{', '  2}'))
})

assert('reindent_lines() works', {
  (reindent_lines('') %==% '')
  (reindent_lines(c('', '')) %==% c('', ''))
  (reindent_lines('    ', n = 2) %==% '  ')
  (reindent_lines(c('if (TRUE) {', '    1', '}'), n = 2) %==% c('if (TRUE) {', '  1', '}'))
})