assert Contains(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.
수신자
매개변수 제약
assert 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.
assert 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.
관련 규칙 · Assert inequality and text containment →결과
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
링크Assert inequality and text containment
링크Assert inequality and text containment
assert 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.
assert 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
링크import std.testimport std.iotest.assertNe([1, 2], [1, 3])let present: Option<int> = Some(1)let absent: Option<int> = None()test.assertNe(present, absent)test.assertContains("Topaz", "opa")test.assertContains("é", "é")test.assertContains("text", "")test.assertContains("", "")io.writeLine("comparisons passed")
comparisons passed
기대 결과
기대 결과
실행을 마칩니다. 종료 코드 0.
comparisons passed
Evaluate each operand once in source order
링크import std.testimport std.iofunction operand(label: string, value: int) -> int {io.writeLine(label)return value}let result: () = test.assertNe(operand("actual", 3), operand("expected", 4))io.writeLine("{result}")
actual
expected
()
기대 결과
기대 결과
실행을 마칩니다. 종료 코드 0.
actualexpected()
Stop after equal operands fail assertNe
링크import std.testimport std.iofunction operand(label: string, value: int) -> int {io.writeLine(label)return value}test.assertNe(operand("actual", 7), operand("expected", 7))io.writeLine("after")
actual
expected
기대 결과
기대 결과
거절 단계 run. 종료 코드가 0이 아닙니다.
stdlib-assert-ne-equal at
main.tpz:9:1
actualexpected
Keep substring matching case sensitive
링크import std.testimport std.ioio.writeLine("before")test.assertContains("Topaz", "topaz")io.writeLine("after")
before
기대 결과
Keep composed and decomposed spellings distinct
링크import std.testimport std.ioio.writeLine("before")test.assertContains("é", "é")io.writeLine("after")
before
기대 결과
기대 결과
거절 단계 run. 종료 코드가 0이 아닙니다.
stdlib-assert-contains-spelling at
main.tpz:5:1
before
Reject values that ordinary equality cannot compare
링크import std.testlet value = () => 1test.assertNe(value, value)
표준 출력 없음.기대 결과
Accept exact substrings and an empty needle
링크import std.testimport std.iotest.assertContains("Topaz", "opa")test.assertContains("é", "é")test.assertContains("text", "")test.assertContains("", "")io.writeLine("text contained")
text contained
기대 결과
기대 결과
실행을 마칩니다. 종료 코드 0.
text contained