-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([be_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 and are\n" " re-exported through `dream_test/matchers`.\n" "\n" " ## Example\n" "\n" " ```gleam\n" " 2 + 3\n" " |> should\n" " |> be_equal(5)\n" " |> or_fail_with(\"2 + 3 should equal 5\")\n" " ```\n" ). -file("src/dream_test/matchers/equality.gleam", 128). -spec inspect_value(any()) -> binary(). inspect_value(Value) -> gleam@string:inspect(Value). -file("src/dream_test/matchers/equality.gleam", 56). -spec check_equal(HMB, HMB) -> dream_test@types:match_result(HMB). 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, <<"be_equal"/utf8>>, <<""/utf8>>, {some, Payload}}} end. -file("src/dream_test/matchers/equality.gleam", 46). ?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" " 2 + 3\n" " |> should\n" " |> be_equal(5)\n" " |> or_fail_with(\"2 + 3 should equal 5\")\n" " ```\n" "\n" " ## Parameters\n" "\n" " - `value_or_result`: the `MatchResult(a)` produced by `should` (or a previous matcher)\n" " - `expected`: the value you expect the actual value to equal\n" "\n" " ## Returns\n" "\n" " A `MatchResult(a)`:\n" " - On success, preserves the original value for further chaining.\n" " - On failure, the chain becomes failed and later matchers are skipped.\n" ). -spec be_equal(dream_test@types:match_result(HLY), HLY) -> dream_test@types:match_result(HLY). be_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", 109). -spec check_not_equal(HMG, HMG) -> dream_test@types:match_result(HMG). 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", 99). ?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" " 10 + 3\n" " |> should\n" " |> not_equal(3)\n" " |> or_fail_with(\"10 + 3 should not equal 3\")\n" " ```\n" "\n" " ## Parameters\n" "\n" " - `value_or_result`: the `MatchResult(a)` produced by `should` (or a previous matcher)\n" " - `unexpected`: the value you expect the actual value to *not* equal\n" "\n" " ## Returns\n" "\n" " A `MatchResult(a)`:\n" " - On success, preserves the original value for further chaining.\n" " - On failure, the chain becomes failed and later matchers are skipped.\n" ). -spec not_equal(dream_test@types:match_result(HMD), HMD) -> dream_test@types:match_result(HMD). 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.