Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/test that #5

Merged
merged 6 commits into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@ Encoding: UTF-8
LazyData: true
RoxygenNote: 7.2.3
Depends:
R (>= 2.10)
R (>= 4.1.0)
URL: https://eodagmbh.github.io/r-maplibregl/
Imports:
geojsonsf,
htmlwidgets,
purrr
Suggests:
testthat (>= 3.0.0)
Config/testthat/edition: 3
7 changes: 3 additions & 4 deletions R/layer.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,15 @@
#'
#' @export
Layer <- function(type, id, source = NULL, paint = NULL, layout = NULL, ...) {
lay <- list(
list(
type = type,
id = id,
source = source,
paint = paint,
layout = layout
) |>
purrr::compact()
class(lay) <- "MapLibreLayer"
return(lay)
purrr::compact() |>
set_maplibre_class("MapLibreLayer")
}


Expand Down
33 changes: 15 additions & 18 deletions R/marker.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,27 @@
#' @param popup
#' @export
#' @example examples/markers.R
Marker <- function(lngLat, popup , ...) {
mark <- list(
lngLat = lngLat,
Marker <- function(lngLat, popup = NULL, ...) {
list(
lngLat = lngLat,
popup = popup,
options = MarkerOptions(...)
) |>
purrr::compact()
class(mark) <- "MapLibreMarker"
return(mark)
purrr::compact() |>
set_maplibre_class("MapLibreMarker")
}

#' Title
#'
#' @param ...
#'
#' @return
#' @export
#'
#' @examples
MarkerOptions <- function(...){
MarkerOptions <- function(...) {
marker_options <- list(...)
stopifnot(sapply(marker_options[c("anchor", "color", "pitchAlignment", "rotationAlignment")], function(x){is.null(x) | is.character(x)}))
stopifnot(sapply(marker_options["draggable"], function(x) {is.null(x) | is.logical(x)}))
stopifnot(sapply(marker_options[c("rotation", "scale")], function(x) {is.null(x) | is.numeric(x)}))
stopifnot(sapply(marker_options[c("anchor", "color", "pitchAlignment", "rotationAlignment")], function(x) {
is.null(x) | is.character(x)
}))
stopifnot(sapply(marker_options["draggable"], function(x) {
is.null(x) | is.logical(x)
}))
stopifnot(sapply(marker_options[c("rotation", "scale")], function(x) {
is.null(x) | is.numeric(x)
}))
marker_options <- marker_options |>
purrr::compact()
class(marker_options) <- "MarkerOptions"
Expand Down
4 changes: 4 additions & 0 deletions R/utils.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
set_maplibre_class <- function(.obj, class_name) {
class(.obj) <- c(class(.obj), class_name)
return(.obj)
}
4 changes: 2 additions & 2 deletions data-raw/basemaps.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ PROVIDERS <- list(
url = "https://basemaps.cartocdn.com/gl/%s-gl-style/style.json",
themes = c("dark-matter", "voyager", "positron")
)
#, mapbox = list(
# , mapbox = list(
# url = "mapbox://styles/mapbox/%s",
# themes = c("streets-v11", "outdoors-v11", "light-v10", "dark-v10", "satellite-v9", "satellite-steets-v11")
#)
# )
)

build_urls <- function(provider) {
Expand Down
12 changes: 12 additions & 0 deletions tests/testthat.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# This file is part of the standard setup for testthat.
# It is recommended that you do not modify it.
#
# Where should you do additional test configuration?
# Learn more about the roles of various files in:
# * https://r-pkgs.org/testing-design.html#sec-tests-files-overview
# * https://testthat.r-lib.org/articles/special-files.html

library(testthat)
library(maplibre)

test_check("maplibre")
17 changes: 17 additions & 0 deletions tests/testthat/test-layer.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
test_that("layer spec", {
# Prepare
id <- "test"
type <- "fill"

# Act
layer <- Layer(
id = id,
type = type
)

# Assert
expect_equal(layer$id, id)
expect_equal(layer$type, type)
expect_s3_class(layer, c("list"))
expect_s3_class(layer, c("MapLibreLayer"))
})
12 changes: 12 additions & 0 deletions tests/testthat/test-marker.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
test_that("marker spec", {
# Prepare
lng_lat <- c(5, 5)

# Act
marker <- Marker(lng_lat)

# Assert
expect_equal(marker$lngLat, lng_lat)
expect_s3_class(marker, "list")
expect_s3_class(marker, "MapLibreMarker")
})