diff --git a/R/controls.R b/R/controls.R index 75bd937..a85a8a6 100644 --- a/R/controls.R +++ b/R/controls.R @@ -55,6 +55,7 @@ editor_modes <- function() { is_editor_options <- function(object) inherits(object, "editor_options") as_editor_options <- function(object) UseMethod("as_editor_options") -as_editor_options.default <- function(object) object +as_editor_options.editor_options <- function(object) object +as_editor_options.cur_value <- function(object) object as_editor_options.NULL <- function(object) NULL as_editor_options.logical <- function(object) if (isTRUE(object)) editor_options() else NULL diff --git a/tests/testthat/test-editor.R b/tests/testthat/test-editor.R index c83132f..afb81d7 100644 --- a/tests/testthat/test-editor.R +++ b/tests/testthat/test-editor.R @@ -37,20 +37,46 @@ test_that("editor_options works", { ) }) +test_that("as_editor_options works", { + expect_equal( + as_editor_options(NULL), + NULL + ) + + expect_equal( + as_editor_options(TRUE), + editor_options() + ) + + expect_equal( + as_editor_options(FALSE), + NULL + ) + + expect_equal( + as_editor_options(cur_value()), + cur_value() + ) + + expect_equal( + as_editor_options(editor_options("modify")), + editor_options("modify") + ) +}) test_that("editor_options json works", { expect_equal( - as_json.editor_options(editor_options()), + as_json(editor_options()), structure("{}", class = "json") ) expect_equal( - as_json.editor_options(editor_options(mode = "lasso")), + as_json(editor_options(mode = "lasso")), structure('{"mode":"lasso"}', class = "json") ) expect_equal( - as_json.editor_options(editor_options(features = wk::wkt("LINESTRING (1 1)", "OGC:CRS84"))), + as_json(editor_options(features = wk::wkt("LINESTRING (1 1)", "OGC:CRS84"))), structure( '{"geojson":{"type":"FeatureCollection","features":[{"type":"Feature","properties":{},"geometry":{"type":"LineString","coordinates":[[1.0,1.0]]}}]}}', # nolint class = "json"