matlab.unittest.qualifications.Verifiable.verifyMatches - Verify string matches specified regular expression - MATLAB (original) (raw)

Class: matlab.unittest.qualifications.Verifiable
Namespace: matlab.unittest.qualifications

Verify string matches specified regular expression

Syntax

Description

verifyMatches([testCase](#bt00qw%5F-1%5Fsep%5Fmw%5F8d5e73c7-bacb-46a7-a1c1-f24af91e6c03),[actual](#mw%5Fe7822eb8-13f6-4cce-b095-46fa0cbce7d7),[expression](#mw%5Fe7512a0a-e81c-4515-af88-a21a0b3fb1ec)) verifies that actual is a string scalar or character vector that matches the specified regular expression.

example

verifyMatches([testCase](#bt00qw%5F-1%5Fsep%5Fmw%5F8d5e73c7-bacb-46a7-a1c1-f24af91e6c03),[actual](#mw%5Fe7822eb8-13f6-4cce-b095-46fa0cbce7d7),[expression](#mw%5Fe7512a0a-e81c-4515-af88-a21a0b3fb1ec),[diagnostic](#mw%5Faef1e027-c005-49f9-afcb-d6c4b8a60c52)) also associates the diagnostic information in diagnostic with the qualification.

example

Input Arguments

expand all

Test case, specified as a matlab.unittest.qualifications.Verifiable object. Because the matlab.unittest.TestCase class subclasses matlab.unittest.qualifications.Verifiable and inherits its methods, testCase is typically amatlab.unittest.TestCase object.

Value to test, specified as a value of any data type. Although you can provide a value of any data type, the test fails if actual is not a string scalar or character vector.

Regular expression that the actual value must match, specified as a string scalar or character vector.

Diagnostic information to display when the qualification passes or fails, specified as a string array, character array, function handle, or array of matlab.automation.diagnostics.Diagnostic objects.

Depending on the test runner configuration, the testing framework can display diagnostics when the qualification passes or fails. By default, the framework displays diagnostics only when the qualification fails. You can override the default behavior by customizing the test runner. For example, use a DiagnosticsOutputPlugin instance to display both failing and passing event diagnostics.

Example: "My Custom Diagnostic"

Example: @dir

Examples

expand all

Create a test case for interactive testing.

testCase = matlab.unittest.TestCase.forInteractiveUse;

Define the actual value.

Verify that the actual value matches "^Som".

verifyMatches(testCase,actual,"^Som")

Show that case matters. The following test fails because the actual value does not start with a lowercase letter.

verifyMatches(testCase,actual,"^som","Test is case sensitive.")

Verification failed. ---------------- Test Diagnostic: ---------------- Test is case sensitive. --------------------- Framework Diagnostic: --------------------- verifyMatches failed. --> The value does not match the regular expression.

Actual Value:
    "Some Text"
Regular Expression:
    "^som"
------------------
Stack Information:
------------------
In C:\work\TestIfActualValueMatchesRegularExpressionExample.m (TestIfActualValueMatchesRegularExpressionExample) at 21

Define another regular expression. The [Tt]? contained in the expression indicates that either "T" or "t" matches at that location 0 times or 1 time.

expression = "Some [Tt]?ext";

Verify that the actual value matches the specified expression.

verifyMatches(testCase,actual,expression)

Tips

Version History

Introduced in R2013a