R/make-expectation.R

Defines functions make_expectation

Documented in make_expectation

#' Make an equality test.
#'
#' This a convenience function to make a expectation that checks that
#' input stays the same.
#'
#' @param x a vector of values
#' @param expectation the type of equality you want to test for
#'   (`"equals"`, `"is_equivalent_to"`, `"is_identical_to"`)
#' @export
#' @keywords internal
#' @examples
#' x <- 1:10
#' make_expectation(x)
#'
#' make_expectation(mtcars$mpg)
#'
#' df <- data.frame(x = 2)
#' make_expectation(df)
make_expectation <- function(x, expectation = "equals") {
  obj <- substitute(x)
  expectation <- match.arg(
    expectation,
    c("equals", "is_equivalent_to", "is_identical_to")
  )

  dput(substitute(
    expect_equal(obj, values),
    list(obj = obj, expectation = as.name(expectation), values = x)
  ))
}

Try the testthat package in your browser

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

testthat documentation built on Oct. 6, 2023, 5:10 p.m.