assert Contains(text: string, needle: string) - > ()- Модуль
- std.
test → - Получатель
- Неприменимо
- Минимальное число аргументов
- 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. Ненулевой код завершения.
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
Ожидаемый результат
Ожидаемый результат
Этап отклонения run. Ненулевой код завершения.
stdlib-assert-contains-case at
main.tpz:5:1
before
Keep composed and decomposed spellings distinct
Ссылкаimport std.testimport std.ioio.writeLine("before")test.assertContains("é", "é")io.writeLine("after")
before
Ожидаемый результат
Ожидаемый результат
Этап отклонения run. Ненулевой код завершения.
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)
Нет стандартного вывода.Ожидаемый результат
Ожидаемый результат
Этап отклонения check. Ненулевой код завершения.
stdlib-assert-ne-non-comparable at
main.tpz:4:1
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