Skip to content

Commit

Permalink
preserve the order the option were defined in the generated doc (#7)
Browse files Browse the repository at this point in the history
* preserve the order the option were defined in the generated doc

* adding unit tests to support docs order PR

---------

Co-authored-by: dgkf <18220321+dgkf@users.noreply.github.com>
  • Loading branch information
meztez and dgkf authored Nov 28, 2023
1 parent 9224795 commit a2c1102
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion R/options_roxygen.R
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ as_roxygen_docs <- function(
"@seealso options getOption Sys.setenv Sys.getenv",
"@section Options:",
"\\describe{",
vapply(setdiff(names(optenv), CONST_OPTIONS_META), function(n) {
vapply(setdiff(names(details), CONST_OPTIONS_META), function(n) {
sprintf(
"\\item{%s}{\\describe{%s}}\n", n,
paste0(
Expand Down
19 changes: 19 additions & 0 deletions tests/testthat/test-output.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,22 @@ test_that("options objects pretty print", {
expect_match(out, " default")
Sys.unsetenv("OPT_A")
})

test_that("options objects prints options in definition order", {
e <- new.env(parent = baseenv())

expect_silent(with(e, options::define_option(
"B",
default = 2,
envvar_name = "OPT_B"
)))

expect_silent(with(e, options::define_option(
"A",
default = 1,
envvar_name = "OPT_A"
)))

expect_silent(out <- paste0(capture.output(e$.options), collapse = "\n"))
expect_match(out, "OPT_B.*OPT_A")
})
9 changes: 9 additions & 0 deletions tests/testthat/test-roxygen2.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@ test_that("roxygen2-style block is generated from options env object", {
expect_match(block, "\\{envvar: \\}\\{OPT_A")
})

test_that("roxygen2 options documentation is in definition order", {
e <- test_env()
expect_silent(with(e, options::define_option("B")))
expect_silent(with(e, options::define_option("A")))

expect_silent(block <- paste0(as_roxygen_docs(env = e), collapse = "\n"))
expect_match(block, "\\\\item\\{B\\}.*\\\\item\\{A\\}")
})

test_that("roxygen2-style params block is generated from as_params", {
e <- test_env()

Expand Down

0 comments on commit a2c1102

Please sign in to comment.