Main Content

matlab.unittest.constraints.Matches 클래스

네임스페이스: matlab.unittest.constraints
슈퍼클래스: matlab.unittest.constraints.BooleanConstraint

값이 지정된 정규 표현식과 일치하는지 테스트

설명

matlab.unittest.constraints.Matches 클래스는 값이 지정된 정규 표현식과 일치하는지 테스트하는 제약 조건을 제공합니다.

생성

설명

예제

c = matlab.unittest.constraints.Matches(expression)은 값이 지정된 정규 표현식과 일치하는지 테스트하는 제약 조건을 만듭니다. 이 제약 조건은 string형 스칼라 또는 문자형 벡터가 expression과 일치하는 경우 충족됩니다.

예제

c = matlab.unittest.constraints.Matches(expression,Name,Value)는 하나 이상의 이름-값 인수를 사용하여 옵션을 추가로 설정합니다. 예를 들어, c = matlab.unittest.constraints.Matches(expression,"IgnoringCase",true)는 대/소문자를 무시하는 제약 조건을 만듭니다.

입력 인수

모두 확장

일치시킬 정규 표현식으로, 비어 있지 않은 string형 스칼라 또는 문자형 벡터로 지정됩니다.

이 인수는 Expression 속성을 설정합니다.

이름-값 인수

선택적 인수 쌍을 Name1=Value1,...,NameN=ValueN으로 지정합니다. 여기서 Name은 인수 이름이고 Value는 대응값입니다. 이름-값 인수는 다른 인수 뒤에 와야 하지만, 인수 쌍의 순서는 상관없습니다.

예: c = matlab.unittest.constraints.Matches(expression,IgnoringCase=true)

R2021a 이전 릴리스에서는 쉼표를 사용하여 각 이름과 값을 구분하고 Name을 따옴표로 묶으십시오.

예: c = matlab.unittest.constraints.Matches(expression,"IgnoringCase",true)

대/소문자 무시 여부로, 숫자형 또는 논리값 0(false) 또는 1(true)로 지정됩니다. 기본적으로 이 제약 조건은 대/소문자를 구분합니다.

이 인수는 IgnoreCase 속성을 설정합니다.

expression과 일치시킬 횟수로, 양의 정수 스칼라로 지정됩니다.

이 이름-값 인수를 지정하여 일치 항목이 겹치지 않게 나타나는 횟수만 계산할 수 있습니다. 예를 들어 다음 테스트는 실패합니다.

import matlab.unittest.TestCase
import matlab.unittest.constraints.Matches

testCase = TestCase.forInteractiveUse;
testCase.verifyThat("eyeye",Matches("e.e","WithCount",2))

데이터형: double | single | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

속성

모두 확장

일치시킬 정규 표현식으로, string형 스칼라 또는 문자형 벡터로 반환됩니다.

이 속성은 expression 입력 인수에 의해 설정됩니다.

특성:

GetAccess
public
SetAccess
immutable

대/소문자 무시 여부로, 논리값 0(false) 또는 1(true)로 반환됩니다. 기본적으로 이 제약 조건은 대/소문자를 구분합니다.

이 속성은 IgnoringCase 이름-값 인수에 의해 설정됩니다.

특성:

GetAccess
public
SetAccess
private

예제

모두 축소

Matches 제약 조건을 사용하여 문자열이 정규 표현식과 일치하는지 테스트합니다.

먼저 이 예제에서 사용되는 클래스를 가져옵니다.

import matlab.unittest.TestCase
import matlab.unittest.constraints.Matches

대화형 방식 테스트를 위한 테스트 케이스를 생성합니다.

testCase = TestCase.forInteractiveUse;

문자열 "Some Text"가 정규 표현식 "^Som"과 일치하는지 확인합니다.

testCase.verifyThat("Some Text",Matches("^Som"))
Verification passed.

대/소문자 여부에 따라 달라지는지 확인합니다. 실제 값이 소문자로 시작하지 않으므로 이 테스트는 실패합니다.

testCase.verifyThat("Some Text",Matches("^som"))
Verification failed.
    ---------------------
    Framework Diagnostic:
    ---------------------
    Matches failed.
    --> The value does not match the regular expression.
    
    Actual Value:
        "Some Text"
    Regular Expression:
        "^som"

테스트가 통과하도록 하기 위해, 대/소문자를 무시합니다.

testCase.verifyThat("Some Text",Matches("^som","IgnoringCase",true))
Verification passed.

이제, 다른 정규 표현식을 지정합니다. 표현식의 값 [Tt]?"T" 또는 "t"가 해당 위치에서 0회 또는 1회 일치함을 나타냅니다.

expression = "Some[Tt]?ext";

문자열 "SomeText"expression과 일치하는지 확인합니다.

testCase.verifyThat("SomeText",Matches(expression))
Verification passed.

"SomeText Sometext Someext"expression과 3회 일치하는지 테스트합니다. 테스트가 통과합니다.

testCase.verifyThat("SomeText Sometext Someext",Matches(expression, ...
    "WithCount",3))
Verification passed.

문자열 "sometext"가 정규 표현식과 일치하지 않는지 확인합니다.

testCase.verifyThat("sometext",~Matches(expression))
Verification passed.

버전 내역

R2013a에 개발됨

모두 확장