assert Some<T>(value: Option<T>) - > T- Модуль
- std.
test → - Получатель
- Неприменимо
- Минимальное число аргументов
- 1
- Максимальное число аргументов
- 1
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 accepts an Option<T> and returns the T payload of Some(value). Passing None() raises TPZ4007.
assert accepts an Option<T> and returns unit for None(). Passing Some(value) raises TPZ4007.
Presence depends on the outer constructor. Some(None()), Some(false), and Some(0) are present values. assertSome returns their payloads unchanged.
Each argument is evaluated once. A successful assertion prints nothing and performs no additional effects. Failure reports the assertion call and stops the current test before its next statement.
The failure messages identify the unexpected constructor. A present payload uses ordinary value rendering.
assertSome failed: got None
assertNone failed: got Some({value})Use a match to handle absence as normal program behavior. These assertions report a failed test when the chosen presence expectation is false.
Связанное правило · Assert presence or absence →Результат
The declared result type is T.
Эффекты
Ошибки
Result and effects
СсылкаReturn the payload of an outer Some unchanged. An absent outer option raises TPZ4007.
Related entries
СсылкаAssert presence or absence
СсылкаAssert presence or absence
assert accepts an Option<T> and returns the T payload of Some(value). Passing None() raises TPZ4007.
assert accepts an Option<T> and returns unit for None(). Passing Some(value) raises TPZ4007.
Presence depends on the outer constructor. Some(None()), Some(false), and Some(0) are present values. assertSome returns their payloads unchanged.
Each argument is evaluated once. A successful assertion prints nothing and performs no additional effects. Failure reports the assertion call and stops the current test before its next statement.
The failure messages identify the unexpected constructor. A present payload uses ordinary value rendering.
assertSome failed: got None
assertNone failed: got Some({value})Use a match to handle absence as normal program behavior. These assertions report a failed test when the chosen presence expectation is false.
Причина
Outer constructor checks keep absence separate from a stored false, zero, or absent nested value. They give tests the same Option meaning as ordinary pattern matching.
Distinguish nested absence from an absent outer value
Ссылкаimport std.testimport std.iolet present: Option<int> = Some(7)let absent: Option<int> = None()let nested: Option<Option<int>> = Some(None())let value = test.assertSome(present)let result: () = test.assertNone(absent)test.assertNone(test.assertSome(nested))io.writeLine("{value}/{result}")
7/()
Ожидаемый результат
Ожидаемый результат
Выполнение завершается. Код завершения 0.
7/()
Fail assertSome on an absent value
Ссылкаimport std.testimport std.iolet value: Option<int> = None()io.writeLine("before")test.assertSome(value)io.writeLine("after")
before
Ожидаемый результат
Ожидаемый результат
Этап отклонения run. Ненулевой код завершения.
stdlib-assert-some-none at
main.tpz:6:1
before
Fail assertNone with the present payload
Ссылкаimport std.testimport std.iolet value: Option<int> = Some(7)io.writeLine("before")test.assertNone(value)io.writeLine("after")
before
Ожидаемый результат
Ожидаемый результат
Этап отклонения run. Ненулевой код завершения.
stdlib-assert-none-some at
main.tpz:6:1
before