assert None<T>(value: Option<T>) - > ()- Module
- std.
test - Receiver
- Not applicable
- Minimum arity
- 1
- Maximum arity
- 1
Declaration and parameters
LinkAvailability
Included by default: Pending
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.
Source evidence
- compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
b48527d0a174· 1957 - compiler/crates/topaz_resolve/src/stdlib.rs at
b48527d0a174· 71 - compiler/crates/topaz_resolve/src/stdlib.rs at
b48527d0a174· 447 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
b48527d0a174· 1957 - compiler/crates/topaz_self_frontend/topaz/checker/builtin_signatures.tpz at
b48527d0a174· 272 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
b48527d0a174· 1973 - compiler/crates/topaz_self_frontend/topaz/checker/call_facts.tpz at
b48527d0a174· 676 - compiler/crates/topaz_self_frontend/topaz/checker/call_facts.tpz at
b48527d0a174· 978 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
b48527d0a174· 1264
Receiver
Parameter constraints
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.
```text 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.
Related rule: Assert presence or absenceResult
The declared result type is ().
Effects
Failures
Result and effects
LinkReturn unit for an absent outer option. A present outer option raises TPZ4007 with its payload.
Related entries
LinkAssert presence or absence
LinkAssert 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.
```text 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.
Why
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.
Source evidence
- compiler/crates/topaz_value/src/value/builtins/test.rs at
912a5e86e1f9· 101 - compiler/crates/topaz_value/src/value/builtins/test.rs at
912a5e86e1f9· 116 - compiler/crates/topaz_self_frontend/topaz/emitter/builtins.tpz at
912a5e86e1f9· 161 - compiler/crates/topaz_self_frontend/topaz/emitter/emit.tpz at
912a5e86e1f9· 1004 - compiler/crates/topaz_self_frontend/topaz/checker/expression_core.tpz at
f3807a34248e· 594 - compiler/crates/topaz_self_frontend/topaz/checker/call_facts.tpz at
f3807a34248e· 301 - compiler/crates/topaz_rt/src/closure.rs at
f3807a34248e· 1030 -
topaz.stdlib.contract.test-option-variantsatworking-tree - topaz.decision.test-assertions-and-golden.1 at
topaz.decisi
Distinguish nested absence from an absent outer value
Linkimport 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/()
Expected result
Expected result
Execution completes. Exit code 0.
7/()
Source evidence
- compiler/crates/topaz_value/src/value/builtins/test.rs at
912a5e86e1f9· 101 - compiler/crates/topaz_value/src/value/builtins/test.rs at
912a5e86e1f9· 116 - compiler/crates/topaz_self_frontend/topaz/emitter/builtins.tpz at
912a5e86e1f9· 161 - compiler/crates/topaz_self_frontend/topaz/emitter/emit.tpz at
912a5e86e1f9· 1004 - compiler/crates/topaz_self_frontend/topaz/checker/expression_core.tpz at
f3807a34248e· 594 - compiler/crates/topaz_self_frontend/topaz/checker/call_facts.tpz at
f3807a34248e· 301 - compiler/crates/topaz_rt/src/closure.rs at
f3807a34248e· 1030 -
topaz.stdlib.contract.test-option-variantsatworking-tree - topaz.decision.test-assertions-and-golden.1 at
topaz.decisi
Fail assertSome on an absent value
Linkimport std.testimport std.iolet value: Option<int> = None()io.writeLine("before")test.assertSome(value)io.writeLine("after")
before
Expected result
Expected result
Rejection during run. Nonzero exit.
TPZ4007stdlib-assert-some-none atmain.tpz:6:1
before
Source evidence
- compiler/crates/topaz_value/src/value/builtins/test.rs at
912a5e86e1f9· 101 - compiler/crates/topaz_value/src/value/builtins/test.rs at
912a5e86e1f9· 116 - compiler/crates/topaz_self_frontend/topaz/emitter/builtins.tpz at
912a5e86e1f9· 161 - compiler/crates/topaz_self_frontend/topaz/emitter/emit.tpz at
912a5e86e1f9· 1004 - compiler/crates/topaz_self_frontend/topaz/checker/expression_core.tpz at
f3807a34248e· 594 - compiler/crates/topaz_self_frontend/topaz/checker/call_facts.tpz at
f3807a34248e· 301 - compiler/crates/topaz_rt/src/closure.rs at
f3807a34248e· 1030 -
topaz.stdlib.contract.test-option-variantsatworking-tree - topaz.decision.test-assertions-and-golden.1 at
topaz.decisi
Fail assertNone with the present payload
Linkimport std.testimport std.iolet value: Option<int> = Some(7)io.writeLine("before")test.assertNone(value)io.writeLine("after")
before
Expected result
Expected result
Rejection during run. Nonzero exit.
TPZ4007stdlib-assert-none-some atmain.tpz:6:1
before
Source evidence
- compiler/crates/topaz_value/src/value/builtins/test.rs at
912a5e86e1f9· 101 - compiler/crates/topaz_value/src/value/builtins/test.rs at
912a5e86e1f9· 116 - compiler/crates/topaz_self_frontend/topaz/emitter/builtins.tpz at
912a5e86e1f9· 161 - compiler/crates/topaz_self_frontend/topaz/emitter/emit.tpz at
912a5e86e1f9· 1004 - compiler/crates/topaz_self_frontend/topaz/checker/expression_core.tpz at
f3807a34248e· 594 - compiler/crates/topaz_self_frontend/topaz/checker/call_facts.tpz at
f3807a34248e· 301 - compiler/crates/topaz_rt/src/closure.rs at
f3807a34248e· 1030 -
topaz.stdlib.contract.test-option-variantsatworking-tree - topaz.decision.test-assertions-and-golden.1 at
topaz.decisi