Skip to content

Commit

Permalink
test editor options
Browse files Browse the repository at this point in the history
  • Loading branch information
anthonynorth committed Oct 24, 2023
1 parent 359f4d4 commit dcc2dc3
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
3 changes: 2 additions & 1 deletion R/controls.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
32 changes: 29 additions & 3 deletions tests/testthat/test-editor.R
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit dcc2dc3

Please sign in to comment.