본문으로 건너뛰기
토파즈6.0 · 출시 전
다운로드 →

문서 검색

명세 6.0

방향키로 결과를 고르고 Enter를 눌러 여세요.

API 이름, 진단 번호, 규칙 또는 프로젝트 주제를 입력하세요.

    라이브러리

    std.test.assertContains

    Checks that text contains a requested string.

    assertContains(text: string, needle: string) -> ()
    수신자
    해당 없음
    최소 인자 수
    2
    최대 인자 수
    2

    Declaration and parameters

    링크

    사용 조건

    기본 포함 · 미정

    Import std.test in language mode 5.21.

    The current compiler selects std/test.tpz for this language mode. Availability in other released editions and inclusion in each installed distribution are Pending.

    수신자

    매개변수 제약

    assertNe(actual, expected) returns unit when ordinary value equality says the operands differ. It performs no string conversion before comparison.

    The operands must have a common comparable type under the ordinary equality rules. Known noncomparable values produce TPZ5007 during checking. A comparison fault propagates with its own diagnostic.

    assertContains(text, needle) returns unit when the exact needle occurs as a contiguous substring. Matching is case sensitive and preserves Unicode spelling. An empty needle succeeds even when the text is empty.

    Arguments are evaluated once from left to right before testing the condition. Successful calls have no further side effects and print nothing.

    A false assertion raises TPZ4007 at the assertion call. It returns no value and stops the current test before the next statement. Earlier argument side effects remain visible. Test runner handling of later test cases follows the test execution contract.

    The inequality failure message uses the ordinary rendering of the shared value in this form.

    assertNe failed: both values are `{value}`

    The containment failure message includes the original text and needle in this form.

    assertContains failed: `{text}` does not contain `{needle}`

    These assertions add test failure reporting to ordinary equality and string containment. They do not define a separate comparison relation.

    결과

    The declared result type is ().

    효과

    실패

    Result and effects

    링크

    Return unit when text contains the exact needle. An empty needle succeeds. A missing needle raises TPZ4007 with both strings.

    Related entries

    링크

    std.test →

    Assert inequality and text containment

    링크
    규칙topaz.stdlib.contract.test-comparisons.rule

    Assert inequality and text containment

    assertNe(actual, expected) returns unit when ordinary value equality says the operands differ. It performs no string conversion before comparison.

    The operands must have a common comparable type under the ordinary equality rules. Known noncomparable values produce TPZ5007 during checking. A comparison fault propagates with its own diagnostic.

    assertContains(text, needle) returns unit when the exact needle occurs as a contiguous substring. Matching is case sensitive and preserves Unicode spelling. An empty needle succeeds even when the text is empty.

    Arguments are evaluated once from left to right before testing the condition. Successful calls have no further side effects and print nothing.

    A false assertion raises TPZ4007 at the assertion call. It returns no value and stops the current test before the next statement. Earlier argument side effects remain visible. Test runner handling of later test cases follows the test execution contract.

    The inequality failure message uses the ordinary rendering of the shared value in this form.

    assertNe failed: both values are `{value}`

    The containment failure message includes the original text and needle in this form.

    assertContains failed: `{text}` does not contain `{needle}`

    These assertions add test failure reporting to ordinary equality and string containment. They do not define a separate comparison relation.

    이유

    Tests should disagree with a program value only when the same ordinary comparison disagrees. Silent success keeps output useful, and immediate failure prevents a false premise from affecting later assertions.

    Compare values and exact substrings

    링크
    main.tpzCompare values and exact substrings플레이그라운드 열기 →
    1. import std.test
    2. import std.io
    3. test.assertNe([1, 2], [1, 3])
    4. let present: Option<int> = Some(1)
    5. let absent: Option<int> = None()
    6. test.assertNe(present, absent)
    7. test.assertContains("Topaz", "opa")
    8. test.assertContains("é", "é")
    9. test.assertContains("text", "")
    10. test.assertContains("", "")
    11. io.writeLine("comparisons passed")
    기대 출력종료 코드 0
    comparisons passed
    
    $ topaz run main.tpz · 대상 제품 5.21.3
    기대 결과

    기대 결과

    실행을 마칩니다. 종료 코드 0.

    기대 표준 출력
    1. comparisons passed

    Evaluate each operand once in source order

    링크
    main.tpzEvaluate each operand once in source order플레이그라운드 열기 →
    1. import std.test
    2. import std.io
    3. function operand(label: string, value: int) -> int {
    4. io.writeLine(label)
    5. return value
    6. }
    7. let result: () = test.assertNe(operand("actual", 3), operand("expected", 4))
    8. io.writeLine("{result}")
    기대 출력종료 코드 0
    actual
    expected
    ()
    
    $ topaz run main.tpz · 대상 제품 5.21.3
    기대 결과

    기대 결과

    실행을 마칩니다. 종료 코드 0.

    기대 표준 출력
    1. actual
    2. expected
    3. ()

    Stop after equal operands fail assertNe

    링크
    main.tpzStop after equal operands fail assertNe플레이그라운드 열기 →
    1. import std.test
    2. import std.io
    3. function operand(label: string, value: int) -> int {
    4. io.writeLine(label)
    5. return value
    6. }
    7. test.assertNe(operand("actual", 7), operand("expected", 7))
    8. io.writeLine("after")
    기대 출력0이 아닌 종료 코드
    actual
    expected
    
    $ topaz run main.tpz · 대상 제품 5.21.3
    기대 결과

    기대 결과

    거절 단계 run. 종료 코드가 0이 아닙니다.

    기대 표준 출력
    1. actual
    2. expected

    Keep substring matching case sensitive

    링크
    main.tpzKeep substring matching case sensitive플레이그라운드 열기 →
    1. import std.test
    2. import std.io
    3. io.writeLine("before")
    4. test.assertContains("Topaz", "topaz")
    5. io.writeLine("after")
    기대 출력0이 아닌 종료 코드
    before
    
    $ topaz run main.tpz · 대상 제품 5.21.3
    기대 결과

    기대 결과

    거절 단계 run. 종료 코드가 0이 아닙니다.

    기대 표준 출력
    1. before

    Keep composed and decomposed spellings distinct

    링크
    main.tpzKeep composed and decomposed spellings distinct플레이그라운드 열기 →
    1. import std.test
    2. import std.io
    3. io.writeLine("before")
    4. test.assertContains("é", "é")
    5. io.writeLine("after")
    기대 출력0이 아닌 종료 코드
    before
    
    $ topaz run main.tpz · 대상 제품 5.21.3
    기대 결과

    기대 결과

    거절 단계 run. 종료 코드가 0이 아닙니다.

    • TPZ4007 →

      stdlib-assert-contains-spelling at main.tpz:5:1

    기대 표준 출력
    1. before

    Reject values that ordinary equality cannot compare

    링크
    main.tpzReject values that ordinary equality cannot compare플레이그라운드 열기 →
    1. import std.test
    2. let value = () => 1
    3. test.assertNe(value, value)
    기대 출력0이 아닌 종료 코드
    표준 출력 없음.
    $ topaz check main.tpz --format json · 대상 제품 5.21.3
    기대 결과

    기대 결과

    거절 단계 check. 종료 코드가 0이 아닙니다.

    • TPZ5007 →

      stdlib-assert-ne-non-comparable at main.tpz:4:1

    Accept exact substrings and an empty needle

    링크
    main.tpzAccept exact substrings and an empty needle플레이그라운드 열기 →
    1. import std.test
    2. import std.io
    3. test.assertContains("Topaz", "opa")
    4. test.assertContains("é", "é")
    5. test.assertContains("text", "")
    6. test.assertContains("", "")
    7. io.writeLine("text contained")
    기대 출력종료 코드 0
    text contained
    
    $ topaz run main.tpz · 대상 제품 5.21.3
    기대 결과

    기대 결과

    실행을 마칩니다. 종료 코드 0.

    기대 표준 출력
    1. text contained

    Diagnostics

    링크

    Assertion failed →

    Value is not comparable or keyable →

    메뉴

    다운로드 →