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
Type: string

The value used during the assertion.

pattern
Type: string

The regular expression pattern.

message
Type: string

The error message to display.

file
Type: string

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

line
Type: size_t

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

Throws

DUnitAssertError if the assertation fails.

Examples

1 "foo".assertMatchRegex(r"^foo$");
2 "192.168.0.1".assertMatchRegex(r"((?:[\d]{1,3}\.){3}[\d]{1,3})");
3 
4 // Assert a DUnitAssertError is thrown if assertMatchRegex fails.
5 "foo".assertMatchRegex(r"^bar$").assertThrow!(DUnitAssertError)("Failed asserting match to regex");

Meta