Debian Codegraph @

tests/test-cran/test-citation.R

raw
1 library(testit)
2
3 pkgs = c('KernSmooth', 'xfun', 'knitr')
4 pkg_bib(pkgs, tempfile(), tweak = FALSE)
5
6 assert('& is escaped in title when pkg_bib(tweak = TRUE)', {
7 (length(grep(' & ', grep(
8 '^\\s*title =', capture.output(pkg_bib(pkgs, tweak = TRUE)), value = TRUE
9 ))) %==% 0L)
10 })
11
12 assert('pkg_bib() warns on missing packages', {
13 has_warning(pkg_bib(c('xfun', '__nonexistent_pkg__'), tempfile()))
14 })
15
16 assert('make_unique() converts repeated values to unique suffixes', {
17 # already unique → returned unchanged
18 (make_unique(c('a', 'b', 'c')) %==% c('a', 'b', 'c'))
19 # empty input
20 (make_unique(character(0)) %==% character(0))
21 # duplicate values get letter suffixes (a, b, c, ...)
22 res = make_unique(c('2020', '2020', '2020'))
23 (res %==% c('2020a', '2020b', '2020c'))
24 # more than 26 duplicates: numeric suffix fallback
25 res2 = make_unique(rep('x', 28))
26 (res2[27] %==% 'x27')
27 (res2[28] %==% 'x28')
28 })