File: test-utils.R

package info (click to toggle)
r-cran-highr 0.7%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 172 kB
  • sloc: sh: 10; makefile: 7
file content (39 lines) | stat: -rw-r--r-- 1,142 bytes parent folder | download | duplicates (4)
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
28
29
30
31
32
33
34
35
36
37
38
39
library(testit)

assert(
  'spaces(n) gives n spaces',
  spaces(-1) == '', spaces(0) == '', spaces(1) == ' ', spaces(5) == '     '
)

assert(
  'escape_latex() sanitizes backslashes and {}',
  escape_latex('\\') == '\\textbackslash{}',
  escape_latex('\\{}') == '\\textbackslash{}\\{\\}',
  escape_latex('{\\}') == '\\{\\textbackslash{}\\}',
  escape_latex('~!@#$%^&*()') == '~!@#$%^&*()'
)

assert(
  'escape_html() escapes HTML chars',
  escape_html('&"<>') == '&amp;&quot;&lt;&gt;',
  escape_html('~!@#$%^&*()') == '~!@#$%^&amp;*()'
)

assert(
  'try_parse() tells if a code fragment is complete or not',
  try_parse('1+1'), !try_parse('1+1+'), try_parse('if(TRUE)1'),
  !try_parse(c('if(T){','F')), try_parse(c('if(T){','F}'))
)

assert(
  'group_src() puts lines of the same expression into a list element',
  identical(group_src('1+1'), list('1+1')),
  identical(group_src(c('1+1+', '1')), list(c('1+1+', '1'))),
  identical(group_src(c('1+1+', '1', 'TRUE')), list(c('1+1+', '1'), 'TRUE'))
)

assert(
  'group_src() should signal an error for incomplete code',
  has_error(group_src('1+1+')),
  has_error(group_src(c('1+1', '1+1+')))
)