tests/testthat/test-maybe_map.R

test_that("maybe_map will fail with non-maybe values", {
  for_all(
    a = anything(),
    property = function(a)
      maybe_map(a, identity) %>%
        expect_error()
  )
})

test_that("maybe_map will fail with a maybe returning function", {
  safe_identity <- function(a) just(identity(a))

  for_all(
    a = anything(),
    property = function(a)
      just(a) %>%
        maybe_map(safe_identity) %>%
        expect_error()
  )
})

test_that("maybe_map will not modify a maybe value with the identity function", {
  nothing() %>%
    maybe_map(identity) %>%
    is_nothing() %>%
    expect_true()

  for_all(
    a = anything(),
    property = function(a)
      just(a) %>%
        maybe_map(identity) %>%
        expect_identical(just(a))
  )
})

Try the maybe package in your browser

Any scripts or data that you put into this service are public.

maybe documentation built on Aug. 7, 2023, 5:11 p.m.