Skip to content

Commit 126ae09

Browse files
authored
Clarify types in class expectations (#2168)
Fixes #1989
1 parent c52c7df commit 126ae09

File tree

2 files changed

+24
-21
lines changed

2 files changed

+24
-21
lines changed

R/expect-inheritance.R

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,17 @@
2020
#' See [expect_vector()] for testing properties of objects created by vctrs.
2121
#'
2222
#' @param type String giving base type (as returned by [typeof()]).
23-
#' @param class
24-
#' * `expect_type()`: a single string giving an R base type.
25-
#' * `expect_s3_class()`: a character vector of class names or `NA` to assert
26-
#' that `object` isn't an S3 object. If you provide multiple class names,
27-
#' the test will pass if `object` inherits from any of them, unless
28-
#' `exact = TRUE`.
29-
#' * `expect_s4_class()`: a character vector of class names or `NA` to assert
30-
#' that `object` isn't an S4 object.
31-
#' * `expect_r6_class()`: a string.
32-
#' * `expect_s7_class()`: an [S7::S7_class()] object.
23+
#' @param class The required type varies depending on the function:
24+
#' * `expect_type()`: a string.
25+
#' * `expect_s3_class()`: a string or character vector. The behaviour of
26+
#' multiple values (i.e. a character vector) is controlled by the
27+
#' `exact` argument.
28+
#' * `expect_s4_class()`: a string.
29+
#' * `expect_r6_class()`: a string.
30+
#' * `expect_s7_class()`: an [S7::S7_class()] object.
31+
#'
32+
#' For historical reasons, `expect_s3_class()` and `expect_s4_class()` also
33+
#' take `NA` to assert that the `object` is not an S3 or S4 object.
3334
#' @inheritParams expect_that
3435
#' @family expectations
3536
#' @examples
@@ -85,7 +86,7 @@ expect_type <- function(object, type) {
8586
#' @rdname inheritance-expectations
8687
#' @param exact If `FALSE`, the default, checks that `object` inherits
8788
#' from any element of `class`. If `TRUE`, checks that object has a class
88-
#' that's identical to `class`.
89+
#' that exactly matches `class`.
8990
expect_s3_class <- function(object, class, exact = FALSE) {
9091
check_bool(exact)
9192

man/inheritance-expectations.Rd

Lines changed: 12 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)