tests/test-cran/test-utils.R

library(testit)

assert('smartypants() transforms ASCII typographic markers', {
  # all pants names produce their HTML entities
  mkd = paste(names(pants), collapse = ' ')
  (smartypants(mkd) %==% paste(
    '½ ⅓ ⅔ ¼ ¾ ⅕ ⅖ ⅗',
    '⅘ ⅙ ⅚ ⅛ ⅜ ⅝ ⅞',
    '⅐ ⅑ ⅒ © ® ™'
  ))
  # fractions are transformed
  (smartypants('1/2') %==% '½')
  (smartypants('1/3') %==% '⅓')
  (smartypants('3/4') %==% '¾')
  # copyright/trademark symbols
  (smartypants('(c)') %==% '©')
  (smartypants('(r)') %==% '®')
  (smartypants('(tm)') %==% '™')
  # no transformation in code blocks
  (smartypants(c('text (c)', '```', '(c)', '```')) %==% c('text ©', '```', '(c)', '```'))
})

assert('merge_list() merges named lists, later values override earlier ones', {
  (merge_list(list(a = 1), list(b = 2)) %==% list(a = 1, b = 2))
  (merge_list(list(a = 1), list(a = 2)) %==% list(a = 2))
  (merge_list(list(a = 1, b = 2), list(a = 3)) %==% list(a = 3, b = 2))
  # non-list arguments are ignored
  (merge_list(list(a = 1), NULL) %==% list(a = 1))
  (merge_list(list(a = 1), 'not a list') %==% list(a = 1))
  # first list wins when later args are non-list
  (merge_list(list(a = 1), list(), list(a = 2)) %==% list(a = 2))
})

assert('is_file() detects whether an input looks like a file path', {
  # a string with an extension looks like a file
  (is_file('foo.md'))
  (is_file('path/to/file.Rmd'))
  # I() wrapping disables file detection
  (!is_file(I('foo.md')))
  # a character vector of length > 1 is not a file
  (!is_file(c('a.md', 'b.md')))
  # a string with no extension and non-existent path is not a file
  (!is_file('justtext'))
  # a plain string that is a bare word (no ext, not existing) is not a file
  (!is_file('hello world'))
})

assert('restore_html() unescapes HTML entities', {
  (restore_html('"') %==% '"')
  (restore_html('&') %==% '&')
  (restore_html('&lt;') %==% '<')
  (restore_html('&gt;') %==% '>')
  (restore_html('a &lt;b&gt; c') %==% 'a <b> c')
  # multiple entities in one string
  (restore_html('&lt;div&gt;&amp;&lt;/div&gt;') %==% '<div>&</div>')
})

assert('locale_lang() returns a BCP 47 language tag string', {
  lang = locale_lang()
  (is.character(lang))
  # either empty or a valid BCP 47 tag (letters, possibly with a hyphen and region)
  (nchar(lang) == 0L || grepl('^[a-z]{2,3}(-[A-Z]{2,3})?$', lang))
})

Try the litedown package in your browser

Any scripts or data that you put into this service are public.

litedown documentation built on July 11, 2026, 9:07 a.m.