1
-
2
- test_that(" can eval" , {
1
+ test_that(" can eval inline code" , {
3
2
out1 <- roc_proc_text(rd_roclet(), "
3
+
4
4
#' @title Title `r 1 + 1`
5
5
#' @description Description `r 2 + 2`
6
6
#' @md
7
- foo <- function() {}" )[[1 ]]
8
-
7
+ foo <- function() NULL
8
+
9
+ " )[[1 ]]
9
10
expect_equal(out1 $ get_value(" title" ), " Title 2" )
10
11
expect_equal(out1 $ get_value(" description" ), " Description 4" )
11
12
})
12
13
13
- test_that(" uses the same env for a block, but not across blocks " , {
14
+ test_that(" can eval fenced code " , {
14
15
out1 <- roc_proc_text(rd_roclet(), "
15
- #' Title `r foobarxxx123 <- 420` `r foobarxxx123`
16
+
17
+ #' @title Title
18
+ #' @details Details
19
+ #' ```{r lorem}
20
+ #' 1+1
21
+ #' ```
22
+ #' @md
23
+ foo <- function() NULL
24
+
25
+ " )[[1 ]]
26
+ expect_match(out1 $ get_value(" details" ), " 2" )
27
+ })
28
+
29
+ test_that(" use same env within, but not across blocks" , {
30
+ example <- "
31
+ #' Title `r baz <- 420` `r baz`
16
32
#'
17
- #' Description `r exists('foobarxxx123 ', inherits = FALSE)`
33
+ #' Description `r exists('baz ', inherits = FALSE)`
18
34
#' @md
19
- #' @name dummy
20
- NULL
35
+ bar <- function() NULL
36
+
37
+ #' Title
38
+ #'
39
+ #' Description `r exists('baz', inherits = FALSE)`
40
+ #' @md
41
+ zap <- function() NULL
42
+ "
43
+ out1 <- roc_proc_text(rd_roclet(), example )[[1 ]]
44
+ out2 <- roc_proc_text(rd_roclet(), example )[[2 ]]
45
+ expect_equal(out1 $ get_value(" title" ), " Title 420" )
46
+ expect_equal(out1 $ get_value(" description" ), " Description TRUE" )
47
+ expect_equal(out2 $ get_value(" description" ), " Description FALSE" )
48
+ })
21
49
22
- #' Title another
50
+ test_that(" appropriate knit print method for fenced and inline is applied" , {
51
+ rlang :: local_bindings(
52
+ knit_print.foo = function (x , inline = FALSE , ... ) {
53
+ knitr :: asis_output(ifelse(inline , " inline" , " fenced" ))
54
+ },
55
+ .env = globalenv()
56
+ )
57
+ out1 <- roc_proc_text(rd_roclet(), "
58
+ #' @title Title `r structure('default', class = 'foo')`
59
+ #'
60
+ #' @details Details
61
+ #'
62
+ #' ```{r}
63
+ #' structure('default', class = 'foo')
64
+ #' ```
23
65
#'
24
- #' Description `r exists('foobarxxx123', inherits = FALSE)`
25
66
#' @md
26
- #' @name dummy2
27
- NULL" )
28
- expect_equal( out1 $ dummy.Rd $ get_value( " title " ), " Title 420 420 " )
29
- expect_equal (out1 $ dummy .Rd$ get_value(" description " ), " Description TRUE" )
30
- expect_equal (out1 $ dummy2 .Rd$ get_value(" description " ), " Description FALSE " )
67
+ #' @name bar
68
+ NULL
69
+ " )
70
+ expect_match (out1 $ bar .Rd$ get_value(" details " ), " fenced " , fixed = TRUE )
71
+ expect_match (out1 $ bar .Rd$ get_value(" title " ), " inline " , fixed = TRUE )
31
72
})
32
73
33
74
test_that(" can create markdown markup" , {
@@ -40,12 +81,24 @@ test_that("can create markdown markup", {
40
81
test_that(" can create markdown markup piecewise" , {
41
82
expect_identical(
42
83
markdown(
43
- " Description [`r paste0('https://url] ')`](`r paste0('link text')`)"
84
+ " Description [`r paste0('https://url')`](`r paste0('link text')`)"
44
85
),
45
- " Description \\ link{https://url}] (link text)"
86
+ " Description \\ link{https://url}(link text)"
46
87
)
47
88
})
48
89
90
+ test_that(" can create escaped markdown markup" , {
91
+ # this workaround is recommended by @yihui
92
+ # "proper" escaping for inline knitr tracked in https://github.com/yihui/knitr/issues/1704
93
+ out1 <- roc_proc_text(rd_roclet(), "
94
+ #' Title
95
+ #' Description `r paste0('\\ x60', 'bar', '\\ x60')`
96
+ #' @md
97
+ foo <- function() NULL
98
+ " )[[1 ]]
99
+ expect_match(out1 $ get_value(" title" ), " \\ code{bar}" , fixed = TRUE )
100
+ })
101
+
49
102
test_that(" NULL creates no text" , {
50
103
expect_identical(
51
104
markdown(" Description --`r NULL`--" ),
@@ -89,7 +142,7 @@ test_that("interleaving fences and inline code", {
89
142
out1 <- roc_proc_text(rd_roclet(), "
90
143
#' Title
91
144
#'
92
- #' @details Details `r x <- 10`
145
+ #' @details Details `r x <- 10; x `
93
146
#'
94
147
#' ```{r}
95
148
#' y <- x + 10
0 commit comments