본문으로 건너뛰기
토파즈6.0 · 출시 전
다운로드 →

문서 검색

명세 6.0

방향키로 결과를 고르고 Enter를 눌러 여세요.

API 이름, 진단 번호, 규칙 또는 프로젝트 주제를 입력하세요.

    라이브러리

    std.test.assertOk

    Checks for an Ok result and exposes its value.

    assertOk<T, E>(value: Result<T, E>) -> T
    수신자
    해당 없음
    최소 인자 수
    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.

    수신자

    매개변수 제약

    assertOk accepts a Result<T, E>. It returns the T payload of Ok(value). An Err(error) raises TPZ4007.

    assertErr accepts a Result<T, E>. It returns the E payload of Err(error). An Ok(value) raises TPZ4007.

    The returned payload is unchanged. No conversion, recursive unwrapping, or equality comparison occurs. A nested Err inside an outer Ok still satisfies assertOk.

    The argument is evaluated once before its outer constructor is inspected. Success prints nothing. Failure reports the assertion call and stops the current test without running its next statement. Earlier effects remain visible.

    The failure messages identify the unexpected constructor and its ordinarily rendered payload.

    assertOk failed: got Err({error})
    assertErr failed: got Ok({value})

    These helpers express a test expectation. Match the Result in ordinary code when either constructor is part of normal control flow.

    결과

    The declared result type is T.

    효과

    실패

    Result and effects

    링크

    Return the payload of an outer Ok unchanged. An outer Err raises TPZ4007 with its error.

    Related entries

    링크

    std.test →

    Assert a Result constructor and return its payload

    링크
    규칙topaz.stdlib.contract.test-result-variants.rule

    Assert a Result constructor and return its payload

    assertOk accepts a Result<T, E>. It returns the T payload of Ok(value). An Err(error) raises TPZ4007.

    assertErr accepts a Result<T, E>. It returns the E payload of Err(error). An Ok(value) raises TPZ4007.

    The returned payload is unchanged. No conversion, recursive unwrapping, or equality comparison occurs. A nested Err inside an outer Ok still satisfies assertOk.

    The argument is evaluated once before its outer constructor is inspected. Success prints nothing. Failure reports the assertion call and stops the current test without running its next statement. Earlier effects remain visible.

    The failure messages identify the unexpected constructor and its ordinarily rendered payload.

    assertOk failed: got Err({error})
    assertErr failed: got Ok({value})

    These helpers express a test expectation. Match the Result in ordinary code when either constructor is part of normal control flow.

    이유

    Inspecting the outer constructor preserves the distinction between an expected failure value and a failed test. Returning the payload lets later assertions examine its contents without repeating the match.

    Extract both Result payloads and preserve a nested Err

    링크
    main.tpzExtract both Result payloads and preserve a nested Err플레이그라운드 열기 →
    1. import std.test
    2. import std.io
    3. let okValue: Result<int, string> = Ok(7)
    4. let errValue: Result<int, string> = Err("bad")
    5. let nested: Result<Result<int, string>, string> = Ok(Err("inner"))
    6. let value = test.assertOk(okValue)
    7. let error = test.assertErr(errValue)
    8. let inner: Result<int, string> = test.assertOk(nested)
    9. let nestedError = test.assertErr(inner)
    10. io.writeLine("{value}/{error}/{nestedError}")
    기대 출력종료 코드 0
    7/bad/inner
    
    $ topaz run main.tpz · 대상 제품 5.21.3
    기대 결과

    기대 결과

    실행을 마칩니다. 종료 코드 0.

    기대 표준 출력
    1. 7/bad/inner

    Fail assertOk with the rendered error

    링크
    main.tpzFail assertOk with the rendered error플레이그라운드 열기 →
    1. import std.test
    2. import std.io
    3. let value: Result<int, string> = Err("bad")
    4. io.writeLine("before")
    5. test.assertOk(value)
    6. io.writeLine("after")
    기대 출력0이 아닌 종료 코드
    before
    
    $ topaz run main.tpz · 대상 제품 5.21.3
    기대 결과

    기대 결과

    거절 단계 run. 종료 코드가 0이 아닙니다.

    기대 표준 출력
    1. before

    Fail assertErr with the rendered value

    링크
    main.tpzFail assertErr with the rendered value플레이그라운드 열기 →
    1. import std.test
    2. import std.io
    3. let value: Result<int, string> = Ok(7)
    4. io.writeLine("before")
    5. test.assertErr(value)
    6. io.writeLine("after")
    기대 출력0이 아닌 종료 코드
    before
    
    $ topaz run main.tpz · 대상 제품 5.21.3
    기대 결과

    기대 결과

    거절 단계 run. 종료 코드가 0이 아닙니다.

    기대 표준 출력
    1. before

    Diagnostics

    링크

    Assertion failed →

    메뉴

    다운로드 →