Skip to content
Topaz6.0 · Before release
Download

Search documentation

Specification 6.0 · Not released · Tested product 5.21.3

Use arrow keys to choose a result. Press Enter to open.

Type an API name, diagnostic number, rule, or project topic.

    Library

    std.test.assertNone

    Checks for an absent option value.

    assertNone<T>(value: Option<T>) -> ()
    Module
    std.test
    Receiver
    Not applicable
    Minimum arity
    1
    Maximum arity
    1

    Declaration and parameters

    Link

    Availability

    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

    Receiver

    Parameter constraints

    assertSome accepts an Option<T> and returns the T payload of Some(value). Passing None() raises TPZ4007.

    assertNone 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.

    Result

    The declared result type is ().

    Effects

    Failures

    Result and effects

    Link

    Return unit for an absent outer option. A present outer option raises TPZ4007 with its payload.

    Related entries

    Link

    std.test

    Assert presence or absence

    Link
    Ruletopaz.stdlib.contract.test-option-variants.rule

    Assert presence or absence

    assertSome accepts an Option<T> and returns the T payload of Some(value). Passing None() raises TPZ4007.

    assertNone 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

    Distinguish nested absence from an absent outer value

    Link
    main.tpzDistinguish nested absence from an absent outer valueOpen in Playground
    1. import std.test
    2. import std.io
    3. let present: Option<int> = Some(7)
    4. let absent: Option<int> = None()
    5. let nested: Option<Option<int>> = Some(None())
    6. let value = test.assertSome(present)
    7. let result: () = test.assertNone(absent)
    8. test.assertNone(test.assertSome(nested))
    9. io.writeLine("{value}/{result}")
    Expected outputexit 0
    7/()
    
    $ topaz run main.tpz · target product 5.21.3
    Expected result

    Expected result

    Execution completes. Exit code 0.

    Expected stdout
    1. 7/()
    Source evidence

    Fail assertSome on an absent value

    Link
    main.tpzFail assertSome on an absent valueOpen in Playground
    1. import std.test
    2. import std.io
    3. let value: Option<int> = None()
    4. io.writeLine("before")
    5. test.assertSome(value)
    6. io.writeLine("after")
    Expected outputNonzero exit
    before
    
    $ topaz run main.tpz · target product 5.21.3
    Expected result

    Expected result

    Rejection during run. Nonzero exit.

    • TPZ4007 stdlib-assert-some-none at main.tpz:6:1
    Expected stdout
    1. before
    Source evidence

    Fail assertNone with the present payload

    Link
    main.tpzFail assertNone with the present payloadOpen in Playground
    1. import std.test
    2. import std.io
    3. let value: Option<int> = Some(7)
    4. io.writeLine("before")
    5. test.assertNone(value)
    6. io.writeLine("after")
    Expected outputNonzero exit
    before
    
    $ topaz run main.tpz · target product 5.21.3
    Expected result

    Expected result

    Rejection during run. Nonzero exit.

    • TPZ4007 stdlib-assert-none-some at main.tpz:6:1
    Expected stdout
    1. before
    Source evidence

    Diagnostics

    Link

    Assertion failed

    Menu

    Download