| 1 |
library(testit) |
| 2 |
|
| 3 |
assert('detect_pattern() automatically detects syntax patterns', { |
| 4 |
(detect_pattern('<<>>=') %==% 'rnw') |
| 5 |
(detect_pattern('<<foo, bar=TRUE>>=') %==% 'rnw') |
| 6 |
(detect_pattern('% begin.rcode') %==% 'tex') |
| 7 |
(detect_pattern('<!--begin.rcode') %==% 'html') |
| 8 |
(detect_pattern('``` {r}') %==% 'md') |
| 9 |
(detect_pattern('asdf', 'rnw') %==% 'rnw') |
| 10 |
(is.null(detect_pattern('foo'))) |
| 11 |
}) |
| 12 |
|
| 13 |
assert('group_pattern() checks if a pattern contains a group', { |
| 14 |
(group_pattern('(.*)')) |
| 15 |
(!group_pattern('()')) |
| 16 |
(!group_pattern('abc')) |
| 17 |
(!group_pattern(NULL)) |
| 18 |
}) |
| 19 |
|
| 20 |
ce_rnw = all_patterns$rnw$chunk.end |
| 21 |
assert('patterns for Rnw', { |
| 22 |
(grep(ce_rnw, ' @') %==% 1L) # spaces before @ |
| 23 |
(grep(ce_rnw, '@ ') %==% 1L) # spaces after @ |
| 24 |
(grep(ce_rnw, '@ %asdf') %==% 1L) # comments after % |
| 25 |
(grep(ce_rnw, '@ asdf') %==% integer()) # only spaces/comments allowed |
| 26 |
(grep(ce_rnw, ' @ a% sdf') %==% integer()) |
| 27 |
}) |
| 28 |
|
| 29 |
cb_md = all_patterns$md$chunk.begin |
| 30 |
assert('patterns for md', { |
| 31 |
# Chunk options |
| 32 |
(grepl(cb_md, '```{r}')) |
| 33 |
(grepl(cb_md, '```{r label}')) |
| 34 |
(grepl(cb_md, '```{r, eval=FALSE}')) |
| 35 |
(grepl(cb_md, '```{awk}')) |
| 36 |
# Pandoc's fenced code attributes |
| 37 |
(!grepl(cb_md, '```{.class}')) |
| 38 |
(!grepl(cb_md, '```{#id}')) |
| 39 |
(!grepl(cb_md, '```{style="color: red"}')) |
| 40 |
# Pandoc's raw attribute |
| 41 |
(!grepl(cb_md, '```{=latex}')) |
| 42 |
}) |