Skip to content

Commit cf06cc1

Browse files
committed
Add tests for styling Rmd file
1 parent dc974fc commit cf06cc1

File tree

5 files changed

+90
-0
lines changed

5 files changed

+90
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
Some text
2+
```{r}
3+
# Some R code
4+
f <- function(x) {
5+
x
6+
}
7+
```
8+
More text
9+
```{r}
10+
# More R code
11+
g <- function(y) {
12+
y
13+
}
14+
```
15+
Final text
16+
```{r}
17+
1 + 2
18+
```
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
```{r}
2+
# Start with chunk
3+
```
4+
Some text before empty chunk
5+
```{r}
6+
7+
```
8+
Final text before longer code chunk
9+
This text chunk has multiple lines
10+
```{r}
11+
# random
12+
this(is_a_call(x))
13+
if (x) {
14+
r()
15+
a <- 3
16+
bcds <- 5
17+
}
18+
```
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
Some text
2+
```{r}
3+
# Some R code
4+
f <- function(x) {
5+
x
6+
}
7+
```
8+
More text before malformed chunk
9+
# More R code
10+
g <- function(y) {
11+
y
12+
}
13+
```
14+
Final text
15+
```{r}
16+
1 + 2
17+
```
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
Some text
2+
```{r}
3+
# Some R code
4+
f <- function(x) {
5+
x
6+
}
7+
```
8+
More text
9+
```{r}
10+
# More R code which is invalid
11+
g <- function(y) {
12+
y
13+
```
14+
Final text
15+
```{r}
16+
1 + 2
17+
```

tests/testthat/test-public_api.R

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,23 @@ test_that("styler does not return error when there is no file to style", {
2727

2828
# styling active region cannot be tested automatically since
2929
# rstudioapi::insertText() needs the context id.
30+
31+
context("public API - Rmd")
32+
33+
test_that("styler can style Rmd file", {
34+
expect_false(
35+
style_file(testthat_file("public-api", "xyzfile_rmd", "random.Rmd"), strict = FALSE)
36+
)
37+
expect_false(
38+
style_file(testthat_file("public-api", "xyzfile_rmd", "random2.Rmd"), strict = FALSE)
39+
)
40+
})
41+
42+
test_that("styler handles malformed Rmd file and invalid R code in chunk", {
43+
expect_warning(
44+
style_file(testthat_file("public-api", "xyzfile_rmd", "random3.Rmd"), strict = FALSE)
45+
)
46+
expect_warning(
47+
style_file(testthat_file("public-api", "xyzfile_rmd", "random4.Rmd"), strict = FALSE)
48+
)
49+
})

0 commit comments

Comments
 (0)