File: expect_match.Rd

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 (103 lines) | stat: -rw-r--r-- 2,826 bytes parent folder | download
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/expectations-matches.R
\name{expect_match}
\alias{expect_match}
\alias{expect_no_match}
\title{Does a string match a regular expression?}
\usage{
expect_match(
  object,
  regexp,
  perl = FALSE,
  fixed = FALSE,
  ...,
  all = TRUE,
  info = NULL,
  label = NULL
)

expect_no_match(
  object,
  regexp,
  perl = FALSE,
  fixed = FALSE,
  ...,
  all = TRUE,
  info = NULL,
  label = NULL
)
}
\arguments{
\item{object}{Object to test.

Supports limited unquoting to make it easier to generate readable failures
within a function or for loop. See \link{quasi_label} for more details.}

\item{regexp}{Regular expression to test against.}

\item{perl}{logical.  Should Perl-compatible regexps be used?}

\item{fixed}{If \code{TRUE}, treats \code{regexp} as a string to be matched exactly
(not a regular expressions). Overrides \code{perl}.}

\item{...}{
  Arguments passed on to \code{\link[base:grep]{base::grepl}}
  \describe{
    \item{\code{ignore.case}}{if \code{FALSE}, the pattern matching is \emph{case
      sensitive} and if \code{TRUE}, case is ignored during matching.}
    \item{\code{useBytes}}{logical.  If \code{TRUE} the matching is done
    byte-by-byte rather than character-by-character.  See
    \sQuote{Details}.}
  }}

\item{all}{Should all elements of actual value match \code{regexp} (TRUE),
or does only one need to match (FALSE).}

\item{info}{Extra information to be included in the message. This argument
is soft-deprecated and should not be used in new code. Instead see
alternatives in \link{quasi_label}.}

\item{label}{Used to customise failure messages. For expert use only.}
}
\description{
Does a string match a regular expression?
}
\details{
\code{expect_match()} is a wrapper around \code{\link[=grepl]{grepl()}}. See its documentation for
more detail about the individual arguments. \code{expect_no_match()} provides
the complementary case, checking that a string \emph{does not} match a regular
expression.
}
\section{Functions}{
\itemize{
\item \code{expect_no_match()}: Check that a string doesn't match a regular
expression.

}}
\examples{
expect_match("Testing is fun", "fun")
expect_match("Testing is fun", "f.n")
expect_no_match("Testing is fun", "horrible")

\dontrun{
expect_match("Testing is fun", "horrible")

# Zero-length inputs always fail
expect_match(character(), ".")
}
}
\seealso{
Other expectations: 
\code{\link{comparison-expectations}},
\code{\link{equality-expectations}},
\code{\link{expect_error}()},
\code{\link{expect_length}()},
\code{\link{expect_named}()},
\code{\link{expect_null}()},
\code{\link{expect_output}()},
\code{\link{expect_reference}()},
\code{\link{expect_silent}()},
\code{\link{inheritance-expectations}},
\code{\link{logical-expectations}}
}
\concept{expectations}