-module(dream_test@types). -compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]). -define(FILEPATH, "src/dream_test/types.gleam"). -export([to_assertion_result/1, status_from_failures/1]). -export_type([status/0, test_kind/0, failure_payload/0, assertion_failure/0, assertion_result/0, match_result/1, module_coverage/0, coverage_summary/0, test_result/0, single_test_config/0, test_case/0, test_suite/0, test_suite_item/0]). -if(?OTP_RELEASE >= 27). -define(MODULEDOC(Str), -moduledoc(Str)). -define(DOC(Str), -doc(Str)). -else. -define(MODULEDOC(Str), -compile([])). -define(DOC(Str), -compile([])). -endif. ?MODULEDOC( " Core types for dream_test.\n" "\n" " This module defines the data structures used throughout the framework.\n" " Most users won't need to interact with these types directly—they're used\n" " internally by the DSL, runner, and reporters.\n" "\n" " ## Type Overview\n" "\n" " | Type | Purpose |\n" " |--------------------|--------------------------------------------------|\n" " | `Status` | Test outcome (Passed, Failed, etc.) |\n" " | `TestKind` | Type of test (Unit, Integration, Gherkin) |\n" " | `TestResult` | Complete result of running a test |\n" " | `AssertionResult` | Pass/fail result of an assertion chain |\n" " | `MatchResult(a)` | Intermediate result during assertion chaining |\n" " | `AssertionFailure` | Details about a failed assertion |\n" "\n" " ## For Custom Matcher Authors\n" "\n" " If you're writing custom matchers, you'll work with `MatchResult(a)`:\n" "\n" " ```gleam\n" " import dream_test/types.{type MatchResult, MatchOk, MatchFailed, AssertionFailure}\n" "\n" " pub fn be_positive(result: MatchResult(Int)) -> MatchResult(Int) {\n" " case result {\n" " MatchFailed(f) -> MatchFailed(f)\n" " MatchOk(n) -> check_positive(n)\n" " }\n" " }\n" "\n" " fn check_positive(n: Int) -> MatchResult(Int) {\n" " case n > 0 {\n" " True -> MatchOk(n)\n" " False -> MatchFailed(AssertionFailure(...))\n" " }\n" " }\n" " ```\n" ). -type status() :: passed | failed | skipped | pending | timed_out | setup_failed. -type test_kind() :: unit | integration | {gherkin_scenario, binary()}. -type failure_payload() :: {equality_failure, binary(), binary()} | {boolean_failure, boolean(), boolean()} | {option_failure, binary(), boolean()} | {result_failure, binary(), boolean()} | {collection_failure, binary(), binary(), binary()} | {comparison_failure, binary(), binary(), binary()} | {string_match_failure, binary(), binary(), binary()} | {custom_matcher_failure, binary(), binary()}. -type assertion_failure() :: {assertion_failure, binary(), binary(), gleam@option:option(failure_payload())}. -type assertion_result() :: assertion_ok | {assertion_failed, assertion_failure()} | assertion_skipped. -type match_result(FPB) :: {match_ok, FPB} | {match_failed, assertion_failure()}. -type module_coverage() :: {module_coverage, binary(), float(), integer(), integer()}. -type coverage_summary() :: {coverage_summary, list(module_coverage())}. -type test_result() :: {test_result, binary(), list(binary()), status(), integer(), list(binary()), list(assertion_failure()), test_kind()}. -type single_test_config() :: {single_test_config, binary(), list(binary()), list(binary()), test_kind(), fun(() -> assertion_result()), gleam@option:option(integer()), list(fun(() -> assertion_result())), list(fun(() -> assertion_result()))}. -type test_case() :: {test_case, single_test_config()}. -type test_suite() :: {test_suite, binary(), list(binary()), list(fun(() -> assertion_result())), list(fun(() -> assertion_result())), list(test_suite_item())}. -type test_suite_item() :: {suite_test, test_case()} | {suite_group, test_suite()}. -file("src/dream_test/types.gleam", 225). ?DOC( " Convert a MatchResult to an AssertionResult.\n" "\n" " This discards the value and returns just the pass/fail status.\n" " Used internally by `or_fail_with`.\n" "\n" " ## Example\n" "\n" " ```gleam\n" " let match_result = MatchOk(42)\n" " let assertion_result = to_assertion_result(match_result)\n" " // assertion_result == AssertionOk\n" " ```\n" ). -spec to_assertion_result(match_result(any())) -> assertion_result(). to_assertion_result(Result) -> case Result of {match_ok, _} -> assertion_ok; {match_failed, Failure} -> {assertion_failed, Failure} end. -file("src/dream_test/types.gleam", 446). ?DOC( " Derive a Status from a list of failures.\n" "\n" " Returns `Passed` if there are no failures, `Failed` otherwise.\n" "\n" " ## Example\n" "\n" " ```gleam\n" " status_from_failures([]) // -> Passed\n" " status_from_failures([some_failure]) // -> Failed\n" " ```\n" ). -spec status_from_failures(list(assertion_failure())) -> status(). status_from_failures(Failures) -> case Failures of [] -> passed; _ -> failed end.