Current section

Files

Jump to
dream_test src dream_test@matchers@equality.erl
Raw

src/dream_test@matchers@equality.erl

-module(dream_test@matchers@equality).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/dream_test/matchers/equality.gleam").
-export([equal/2, not_equal/2]).
-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(
" Equality matchers for dream_test.\n"
"\n"
" These matchers compare values using Gleam's structural equality.\n"
" They're re-exported through `dream_test/assertions/should`.\n"
"\n"
" ## Usage\n"
"\n"
" ```gleam\n"
" import dream_test/assertions/should.{should, equal, not_equal, or_fail_with}\n"
"\n"
" // Check equality\n"
" result\n"
" |> should()\n"
" |> equal(42)\n"
" |> or_fail_with(\"Should be 42\")\n"
"\n"
" // Check inequality\n"
" result\n"
" |> should()\n"
" |> not_equal(0)\n"
" |> or_fail_with(\"Should not be zero\")\n"
" ```\n"
).
-file("src/dream_test/matchers/equality.gleam", 112).
-spec inspect_value(any()) -> binary().
inspect_value(Value) ->
gleam@string:inspect(Value).
-file("src/dream_test/matchers/equality.gleam", 51).
-spec check_equal(FXM, FXM) -> dream_test@types:match_result(FXM).
check_equal(Actual, Expected) ->
case Actual =:= Expected of
true ->
{match_ok, Actual};
false ->
Payload = {equality_failure,
inspect_value(Actual),
inspect_value(Expected)},
{match_failed,
{assertion_failure,
<<"equal"/utf8>>,
<<""/utf8>>,
{some, Payload}}}
end.
-file("src/dream_test/matchers/equality.gleam", 44).
?DOC(
" Assert that a value equals the expected value.\n"
"\n"
" Uses Gleam's structural equality (`==`). Works with any type that\n"
" supports equality comparison.\n"
"\n"
" ## Example\n"
"\n"
" ```gleam\n"
" add(2, 3)\n"
" |> should()\n"
" |> equal(5)\n"
" |> or_fail_with(\"2 + 3 should equal 5\")\n"
" ```\n"
).
-spec equal(dream_test@types:match_result(FXJ), FXJ) -> dream_test@types:match_result(FXJ).
equal(Value_or_result, Expected) ->
case Value_or_result of
{match_failed, Failure} ->
{match_failed, Failure};
{match_ok, Actual} ->
check_equal(Actual, Expected)
end.
-file("src/dream_test/matchers/equality.gleam", 93).
-spec check_not_equal(FXR, FXR) -> dream_test@types:match_result(FXR).
check_not_equal(Actual, Unexpected) ->
case Actual /= Unexpected of
true ->
{match_ok, Actual};
false ->
Payload = {equality_failure,
inspect_value(Actual),
<<"not "/utf8, (inspect_value(Unexpected))/binary>>},
{match_failed,
{assertion_failure,
<<"not_equal"/utf8>>,
<<""/utf8>>,
{some, Payload}}}
end.
-file("src/dream_test/matchers/equality.gleam", 83).
?DOC(
" Assert that a value does not equal the unexpected value.\n"
"\n"
" Uses Gleam's structural inequality (`!=`).\n"
"\n"
" ## Example\n"
"\n"
" ```gleam\n"
" divide(10, 3)\n"
" |> should()\n"
" |> not_equal(3)\n"
" |> or_fail_with(\"10/3 should not equal 3 exactly\")\n"
" ```\n"
).
-spec not_equal(dream_test@types:match_result(FXO), FXO) -> dream_test@types:match_result(FXO).
not_equal(Value_or_result, Unexpected) ->
case Value_or_result of
{match_failed, Failure} ->
{match_failed, Failure};
{match_ok, Actual} ->
check_not_equal(Actual, Unexpected)
end.