-
-
Notifications
You must be signed in to change notification settings - Fork 878
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Parse the text to detect doc comments and inlines properly in spin() (#…
…1605) Fixes rstudio/rmarkdown#1444
- Loading branch information
1 parent
bcb1204
commit 45eee67
Showing
3 changed files
with
41 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
library(testit) | ||
|
||
spin_w_tempfile = function(...) { | ||
tmp = tempfile(fileext = ".R") | ||
writeLines(c(...), tmp) | ||
spinned = spin(tmp, knit = FALSE) | ||
result = readLines(spinned) | ||
file.remove(c(tmp, spinned)) | ||
result | ||
} | ||
|
||
assert( | ||
'spin() detects lines for documentation', | ||
identical(spin_w_tempfile("#' test", "1 * 1", "#' test"), | ||
c("test", "", "```{r }", "1 * 1", "```", "", "test")), | ||
# a multiline string literal contains the pattern of doc or inline | ||
identical(spin_w_tempfile("code <- \"", "#' test\""), | ||
c("", "```{r }", "code <- \"", "#' test\"", "```", "")), | ||
identical(spin_w_tempfile("code <- \"", "{{ 1 + 1 }}", "\""), | ||
c("", "```{r }", "code <- \"", "{{ 1 + 1 }}", "\"", "```", "")), | ||
# a multiline symbol contains the pattern of doc or inline | ||
identical(spin_w_tempfile("`", "#' test", "`"), | ||
c("", "```{r }", "`", "#' test", "`", "```", "")), | ||
identical(spin_w_tempfile("`", "{{ 1 + 1 }}", "`"), | ||
c("", "```{r }", "`", "{{ 1 + 1 }}", "`", "```", "")) | ||
) |