assertMatchRegex

Assert that a string matches a regular expression.

void
assertMatchRegex
(
string value
,
string pattern
,
string message = "Failed asserting match to regex"
,
string file = __FILE__
,
size_t line = __LINE__
)

Parameters

value string

The value used during the assertion.

pattern string

The regular expression pattern.

message string

The error message to display.

file string

The file name where the error occurred. The value is added automatically at the call site.

line size_t

The line where the error occurred. The value is added automatically at the call site.

Throws

DUnitAssertError if the assertation fails.

Examples

"foo".assertMatchRegex(r"^foo$");
"192.168.0.1".assertMatchRegex(r"((?:[\d]{1,3}\.){3}[\d]{1,3})");

// Assert a DUnitAssertError is thrown if assertMatchRegex fails.
"foo".assertMatchRegex(r"^bar$").assertThrow!(DUnitAssertError)("Failed asserting match to regex");

Meta