File: make-expectation.R

package info (click to toggle)
r-cran-testthat 3.2.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,452 kB
  • sloc: cpp: 9,261; ansic: 37; sh: 14; makefile: 5
file content (30 lines) | stat: -rw-r--r-- 765 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#' 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)
  ))
}