Skip to content

Commit 2ced371

Browse files
committed
simple acceptance test
- Add test for styling `.Rmd` files.
1 parent 868cb13 commit 2ced371

File tree

4 files changed

+43
-5
lines changed

4 files changed

+43
-5
lines changed

R/serialized_tests.R

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,10 @@ test_collection <- function(test, sub_test = NULL,
2828
...) {
2929
path <- rprojroot::find_testthat_root_file(test)
3030

31-
pattern <- if_else(!is.null(sub_test),
32-
paste0("^", sub_test, ".*", "in\\.R$"),
33-
"in\\.R$")
31+
pattern <- paste0(
32+
if (!is.null(sub_test)) paste0("^", sub_test, ".*"),
33+
"in\\.R(?:|md)$"
34+
)
3435

3536
in_names <- list.files(file.path(path),
3637
pattern = pattern,
@@ -62,7 +63,7 @@ test_collection <- function(test, sub_test = NULL,
6263
#' styler:::construct_out(c("path/to/file/first-in.R",
6364
#' "path/to/file/first-extended-in.R"))
6465
construct_out <- function(in_paths) {
65-
gsub("\\-.*$", "\\-out\\.R", in_paths)
66+
gsub("\\-.*([.]R(?:|md))$", "\\-out\\1", in_paths)
6667
}
6768

6869
#' Construct paths of a tree object given the paths of *-in.R files
@@ -113,7 +114,6 @@ transform_and_check <- function(in_item, out_item,
113114
)
114115

115116
if (transformed) {
116-
target <- enc::read_lines_enc(out_item)
117117
warning(in_name, " was different from ", out_name,
118118
immediate. = TRUE, call. = FALSE)
119119
} else {

tests/testthat/rmd/simple-in.Rmd

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Header
2+
3+
Some text.
4+
5+
```{r}
6+
1+1
7+
```
8+
9+
More text.
10+
11+
```{r another, results="asis"}
12+
# another chunk
13+
fun(a=1)
14+
```

tests/testthat/rmd/simple-out.Rmd

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Header
2+
3+
Some text.
4+
5+
```{r}
6+
1 + 1
7+
```
8+
9+
More text.
10+
11+
```{r another, results="asis"}
12+
# another chunk
13+
fun(a = 1)
14+
```

tests/testthat/test-rmd.R

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
context("rmd")
2+
3+
test_that("can style .Rmd files", {
4+
test_collection(
5+
"rmd",
6+
transformer = transform_rmd,
7+
transformer_fun = style_text,
8+
write_tree = FALSE
9+
)
10+
})

0 commit comments

Comments
 (0)