Перейти к содержимому
Топаз6.0 · До релиза
Загрузка →

Поиск в документации

Спецификация 6.0

Выберите результат стрелками и нажмите Enter, чтобы открыть его.

Введите имя API, номер диагностики, правило или тему проекта.

    Библиотека

    std.test.assertSome

    Checks for Some and exposes its value.

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

    Получатель

    Ограничения параметров

    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.

    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.

    Результат

    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

    Ссылка

    std.test →

    Assert presence or absence

    Ссылка
    Правилоtopaz.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.

    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

    Ссылка
    main.tpzDistinguish nested absence from an absent outer valueОткрыть песочницу →
    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}")
    Ожидаемый выводКод завершения 0
    7/()
    
    $ topaz run main.tpz · Целевой продукт 5.21.3
    Ожидаемый результат

    Ожидаемый результат

    Выполнение завершается. Код завершения 0.

    Ожидаемый стандартный вывод
    1. 7/()

    Fail assertSome on an absent value

    Ссылка
    main.tpzFail assertSome on an absent valueОткрыть песочницу →
    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")
    Ожидаемый выводНенулевой код завершения
    before
    
    $ topaz run main.tpz · Целевой продукт 5.21.3
    Ожидаемый результат

    Ожидаемый результат

    Этап отклонения run. Ненулевой код завершения.

    Ожидаемый стандартный вывод
    1. before

    Fail assertNone with the present payload

    Ссылка
    main.tpzFail assertNone with the present payloadОткрыть песочницу →
    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")
    Ожидаемый выводНенулевой код завершения
    before
    
    $ topaz run main.tpz · Целевой продукт 5.21.3
    Ожидаемый результат

    Ожидаемый результат

    Этап отклонения run. Ненулевой код завершения.

    Ожидаемый стандартный вывод
    1. before

    Diagnostics

    Ссылка

    Assertion failed →

    Меню

    Загрузка →