Skip to content

Commit

Permalink
Merge pull request #262 from ThinkR-open/255-add_dev_chunk_in_addin
Browse files Browse the repository at this point in the history
255 add dev chunk in addin
  • Loading branch information
ymansiaux authored Jun 11, 2024
2 parents 3c452e7 + 0670366 commit e4bbd08
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 42 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: fusen
Title: Build a Package from Rmarkdown Files
Version: 0.6.0.9001
Version: 0.6.0.9002
Authors@R: c(
person("Sebastien", "Rochette", , "[email protected]", role = c("aut", "cre"),
comment = c(ORCID = "0000-0002-1565-9313")),
Expand Down Expand Up @@ -48,7 +48,7 @@ Suggests:
withr
VignetteBuilder:
knitr
Config/fusen/version: 0.6.0.9000
Config/fusen/version: 0.6.0.9001
Config/testthat/edition: 3
Config/testthat/parallel: false
Encoding: UTF-8
Expand Down
7 changes: 7 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# fusen (development version 0.6.0.9002)

## New features

- RStudio Addin "Fusen : Add fusen chunks" as well as `fusen::add_fusen_chunks()` add a development chunk in complement to the "function", "example" and "test" chunks already provided (#255) @ymansiaux


# fusen (development version 0.6.0.9001)

## New features
Expand Down
4 changes: 4 additions & 0 deletions R/build_fusen_chunks.R
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ build_fusen_chunks <- function(function_name, export = TRUE) {
sep = "\n",
sprintf("# %s", function_name),
" ",
sprintf("```{r development-%s}", function_name),
sprintf("# You can prepare the code of the %s() function here", function_name),
"```",
" ",
sprintf("```{r function-%s}", function_name),
"#' Title",
"#' ",
Expand Down
1 change: 1 addition & 0 deletions dev/config_fusen.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ flat_addins.Rmd:
check: false
document: true
overwrite: ask
clean: ask
flat_create_flat.Rmd:
path: dev/flat_create_flat.Rmd
state: active
Expand Down
54 changes: 34 additions & 20 deletions dev/flat_addins.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ build_fusen_chunks <- function(function_name, export = TRUE) {
sep = "\n",
sprintf("# %s", function_name),
" ",
sprintf("```{r development-%s}", function_name),
sprintf("# You can prepare the code of the %s() function here", function_name),
"```",
" ",
sprintf("```{r function-%s}", function_name),
"#' Title",
"#' ",
Expand Down Expand Up @@ -169,6 +173,11 @@ test_that("build_fusen_chunks works properly", {
expect_true(
grepl("^# pouet", res)
)
expect_true(
grepl("development-pouet", res)
)
expect_true(
grepl("function-pouet", res)
)
Expand Down Expand Up @@ -208,6 +217,11 @@ test_that("build_fusen_chunks cleans functions names", {
expect_true(
grepl("^# po_uet", res)
)
expect_true(
grepl("development-po_uet}", res)
)
expect_true(
grepl("function-po_uet}", res)
)
Expand Down Expand Up @@ -263,7 +277,7 @@ test_that("build_fusen_chunks add lines with export as expected", {
curr_editor <- rstudioapi::getSourceEditorContext()
curr_position <- curr_editor$selection[[1L]]$range$start
# Change file
rstudioapi::navigateToFile(path_dev_history, line = 40)
rstudioapi::navigateToFile(path_dev_history, line = 44)
Sys.sleep(1)
open_editor <- rstudioapi::getSourceEditorContext()
id <- open_editor$id
Expand All @@ -282,18 +296,18 @@ test_that("build_fusen_chunks add lines with export as expected", {
} else {
print("test without interactive")
dev_lines <- readLines(path_dev_history)
dev_lines[40] <- build_fusen_chunks("zaza", export = TRUE)
dev_lines[44] <- build_fusen_chunks("zaza", export = TRUE)
cat(dev_lines, sep = "\n", file = path_dev_history)
}
dev_lines_new <- readLines(path_dev_history)
expect_equal(length(dev_lines_new), length(dev_lines_orig) + 24)
expect_equal(dev_lines_new[40], "# zaza")
expect_equal(dev_lines_new[42], "```{r function-zaza}")
expect_equal(dev_lines_new[49], "#' @export")
expect_equal(dev_lines_new[55], "```{r example-zaza}")
expect_equal(dev_lines_new[56], "zaza()")
expect_equal(dev_lines_new[59], "```{r tests-zaza}")
expect_equal(length(dev_lines_new), length(dev_lines_orig) + 28)
expect_equal(dev_lines_new[44], "# zaza")
expect_equal(dev_lines_new[46], "```{r development-zaza}")
expect_equal(dev_lines_new[50], "```{r function-zaza}")
expect_equal(dev_lines_new[57], "#' @export")
expect_equal(dev_lines_new[63], "```{r example-zaza}")
expect_equal(dev_lines_new[64], "zaza()")
expect_equal(dev_lines_new[67], "```{r tests-zaza}")
unlink(path_foosen, recursive = TRUE)
})
Expand Down Expand Up @@ -324,7 +338,7 @@ test_that("build_fusen_chunks add lines with noRd as expected", {
curr_editor <- rstudioapi::getSourceEditorContext()
curr_position <- curr_editor$selection[[1L]]$range$start
# Change file
rstudioapi::navigateToFile(path_dev_history, line = 40)
rstudioapi::navigateToFile(path_dev_history, line = 44)
Sys.sleep(1)
open_editor <- rstudioapi::getSourceEditorContext()
id <- open_editor$id
Expand All @@ -343,18 +357,18 @@ test_that("build_fusen_chunks add lines with noRd as expected", {
} else {
print("test without interactive")
dev_lines <- readLines(path_dev_history)
dev_lines[40] <- build_fusen_chunks("zaza", export = FALSE)
dev_lines[44] <- build_fusen_chunks("zaza", export = FALSE)
cat(dev_lines, sep = "\n", file = path_dev_history)
}
dev_lines_new <- readLines(path_dev_history)
expect_equal(length(dev_lines_new), length(dev_lines_orig) + 24)
expect_equal(dev_lines_new[40], "# zaza")
expect_equal(dev_lines_new[42], "```{r function-zaza}")
expect_equal(dev_lines_new[49], "#' @noRd")
expect_equal(dev_lines_new[55], "```{r example-zaza}")
expect_equal(dev_lines_new[56], "zaza()")
expect_equal(dev_lines_new[59], "```{r tests-zaza}")
expect_equal(length(dev_lines_new), length(dev_lines_orig) + 28)
expect_equal(dev_lines_new[44], "# zaza")
expect_equal(dev_lines_new[46], "```{r development-zaza}")
expect_equal(dev_lines_new[50], "```{r function-zaza}")
expect_equal(dev_lines_new[57], "#' @noRd")
expect_equal(dev_lines_new[63], "```{r example-zaza}")
expect_equal(dev_lines_new[64], "zaza()")
expect_equal(dev_lines_new[67], "```{r tests-zaza}")
unlink(path_foosen, recursive = TRUE)
})
})
Expand Down
50 changes: 30 additions & 20 deletions tests/testthat/test-build_fusen_chunks.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ test_that("build_fusen_chunks works properly", {
expect_true(
grepl("^# pouet", res)
)

expect_true(
grepl("development-pouet", res)
)

expect_true(
grepl("function-pouet", res)
)
Expand Down Expand Up @@ -46,6 +51,11 @@ test_that("build_fusen_chunks cleans functions names", {
expect_true(
grepl("^# po_uet", res)
)

expect_true(
grepl("development-po_uet}", res)
)

expect_true(
grepl("function-po_uet}", res)
)
Expand Down Expand Up @@ -101,7 +111,7 @@ test_that("build_fusen_chunks add lines with export as expected", {
curr_editor <- rstudioapi::getSourceEditorContext()
curr_position <- curr_editor$selection[[1L]]$range$start
# Change file
rstudioapi::navigateToFile(path_dev_history, line = 40)
rstudioapi::navigateToFile(path_dev_history, line = 44)
Sys.sleep(1)
open_editor <- rstudioapi::getSourceEditorContext()
id <- open_editor$id
Expand All @@ -120,18 +130,18 @@ test_that("build_fusen_chunks add lines with export as expected", {
} else {
print("test without interactive")
dev_lines <- readLines(path_dev_history)
dev_lines[40] <- build_fusen_chunks("zaza", export = TRUE)
dev_lines[44] <- build_fusen_chunks("zaza", export = TRUE)
cat(dev_lines, sep = "\n", file = path_dev_history)
}

dev_lines_new <- readLines(path_dev_history)
expect_equal(length(dev_lines_new), length(dev_lines_orig) + 24)
expect_equal(dev_lines_new[40], "# zaza")
expect_equal(dev_lines_new[42], "```{r function-zaza}")
expect_equal(dev_lines_new[49], "#' @export")
expect_equal(dev_lines_new[55], "```{r example-zaza}")
expect_equal(dev_lines_new[56], "zaza()")
expect_equal(dev_lines_new[59], "```{r tests-zaza}")
expect_equal(length(dev_lines_new), length(dev_lines_orig) + 28)
expect_equal(dev_lines_new[44], "# zaza")
expect_equal(dev_lines_new[46], "```{r development-zaza}")
expect_equal(dev_lines_new[50], "```{r function-zaza}")
expect_equal(dev_lines_new[57], "#' @export")
expect_equal(dev_lines_new[63], "```{r example-zaza}")
expect_equal(dev_lines_new[64], "zaza()")
expect_equal(dev_lines_new[67], "```{r tests-zaza}")

unlink(path_foosen, recursive = TRUE)
})
Expand Down Expand Up @@ -162,7 +172,7 @@ test_that("build_fusen_chunks add lines with noRd as expected", {
curr_editor <- rstudioapi::getSourceEditorContext()
curr_position <- curr_editor$selection[[1L]]$range$start
# Change file
rstudioapi::navigateToFile(path_dev_history, line = 40)
rstudioapi::navigateToFile(path_dev_history, line = 44)
Sys.sleep(1)
open_editor <- rstudioapi::getSourceEditorContext()
id <- open_editor$id
Expand All @@ -181,18 +191,18 @@ test_that("build_fusen_chunks add lines with noRd as expected", {
} else {
print("test without interactive")
dev_lines <- readLines(path_dev_history)
dev_lines[40] <- build_fusen_chunks("zaza", export = FALSE)
dev_lines[44] <- build_fusen_chunks("zaza", export = FALSE)
cat(dev_lines, sep = "\n", file = path_dev_history)
}

dev_lines_new <- readLines(path_dev_history)
expect_equal(length(dev_lines_new), length(dev_lines_orig) + 24)
expect_equal(dev_lines_new[40], "# zaza")
expect_equal(dev_lines_new[42], "```{r function-zaza}")
expect_equal(dev_lines_new[49], "#' @noRd")
expect_equal(dev_lines_new[55], "```{r example-zaza}")
expect_equal(dev_lines_new[56], "zaza()")
expect_equal(dev_lines_new[59], "```{r tests-zaza}")
expect_equal(length(dev_lines_new), length(dev_lines_orig) + 28)
expect_equal(dev_lines_new[44], "# zaza")
expect_equal(dev_lines_new[46], "```{r development-zaza}")
expect_equal(dev_lines_new[50], "```{r function-zaza}")
expect_equal(dev_lines_new[57], "#' @noRd")
expect_equal(dev_lines_new[63], "```{r example-zaza}")
expect_equal(dev_lines_new[64], "zaza()")
expect_equal(dev_lines_new[67], "```{r tests-zaza}")
unlink(path_foosen, recursive = TRUE)
})
})

0 comments on commit e4bbd08

Please sign in to comment.