Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

matlab.unittest.constraints.StartsWithSubstring class

Package: matlab.unittest.constraints
Superclasses: matlab.unittest.constraints.BooleanConstraint

Constraint specifying string starting with substring

Construction

StartsWithSubstring(prefix) creates a constraint specifying a string scalar or character vector starting with a substring. The constraint is satisfied only if the actual value starts with an expected prefix, prefix.

StartsWithSubstring(prefix,Name,Value) provides a constraint with additional options specified by one or more Name,Value pair arguments. Name must appear inside single quotes (''). You can specify several name-value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

Input Arguments

prefix

Text at the start of the actual value, specified as a string scalar or character vector. prefix can include newline characters.

Name-Value Pair Arguments

Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside single quotes (' '). You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

'IgnoringCase'

Indicator if the constraint is insensitive to case, specified as false or true (logical 0 or 1)

Default: false

'IgnoringWhitespace'

Indicator if the constraint is insensitive to whitespace, specified as false or true (logical 0 or 1)

Default: false

Properties

IgnoreCase

Indicator if the constraint is insensitive to case, specified in the name-value pair argument, 'IgnoringCase'. This property applies at all levels of recursion, such as nested structures.

IgnoreWhitespace

Indicator if the constraint is insensitive to whitespace, specified in the name-value pair argument, 'IgnoringWhitespace'. This property applies at all levels of recursion, such as nested structures.

Prefix

Text at the start of the actual value, specified in the input argument, prefix.

Copy Semantics

Value. To learn how value classes affect copy operations, see Copying Objects in the MATLAB® documentation.

Examples

expand all

Create a test case for interactive testing.

import matlab.unittest.TestCase
import matlab.unittest.constraints.StartsWithSubstring

testCase = TestCase.forInteractiveUse;

Define the actual value.

actVal = 'This Is One Long Message';

Test that actVal starts with 'This'.

testCase.verifyThat(actVal, StartsWithSubstring('This'))
Interactive verification passed.

Test that actVal starts with 'this is'.

testCase.verifyThat(actVal, StartsWithSubstring('this is'))
Interactive verification failed.

---------------------
Framework Diagnostic:
---------------------
StartsWithSubstring failed.
--> The value does not start with the supplied prefix.

Actual char:
    This Is One Long Message
Expected Prefix:
    this is

By default, the StartsWithSubstring constraint is case sensitive.

Repeat the test, this time ignoring case.

testCase.verifyThat(actVal, StartsWithSubstring('this is',...
    'IgnoringCase', true))
Interactive verification passed.

Test that actVal starts with 'thisisone'. For the test to pass, configure the constraint to ignore whitespace and case.

testCase.verifyThat(actVal, StartsWithSubstring('thisisone', ...
    'IgnoringCase', true, 'IgnoringWhitespace', true))
Interactive verification passed.

Assert that actVal does not start with 'long'.

testCase.assertThat(actVal, ~StartsWithSubstring('Long'))
Interactive assertion passed.
Was this topic helpful?