Current section
Files
Jump to
Current section
Files
src/dream_test@matchers@collection.erl
-module(dream_test@matchers@collection).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/dream_test/matchers/collection.gleam").
-export([contain/2, not_contain/2, have_length/2, be_empty/1]).
-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(
" Collection matchers for dream_test.\n"
"\n"
" These matchers work with `List(a)` values and are re-exported through\n"
" `dream_test/matchers`.\n"
"\n"
" Use them to assert collection properties like length, emptiness, and\n"
" membership.\n"
"\n"
" ## Example\n"
"\n"
" ```gleam\n"
" [1, 2, 3]\n"
" |> should\n"
" |> have_length(3)\n"
" |> or_fail_with(\"expected list length 3\")\n"
" ```\n"
).
-file("src/dream_test/matchers/collection.gleam", 61).
-spec check_contains(list(HFP), HFP) -> dream_test@types:match_result(list(HFP)).
check_contains(Actual_list, Expected_item) ->
case gleam@list:contains(Actual_list, Expected_item) of
true ->
{match_ok, Actual_list};
false ->
Payload = {collection_failure,
gleam@string:inspect(Actual_list),
gleam@string:inspect(Expected_item),
<<"contain"/utf8>>},
{match_failed,
{assertion_failure,
<<"contain"/utf8>>,
<<""/utf8>>,
{some, Payload}}}
end.
-file("src/dream_test/matchers/collection.gleam", 51).
?DOC(
" Assert that a list contains a specific item.\n"
"\n"
" Use this when you want to assert membership while preserving the original\n"
" list for further checks.\n"
"\n"
" ## Example\n"
"\n"
" ```gleam\n"
" [1, 2, 3]\n"
" |> should\n"
" |> contain(2)\n"
" |> or_fail_with(\"expected list to contain 2\")\n"
" ```\n"
"\n"
" ## Parameters\n"
"\n"
" - `value_or_result`: the `MatchResult(List(a))` produced by `should` (or a previous matcher)\n"
" - `expected_item`: the item that must be present in the list\n"
"\n"
" ## Returns\n"
"\n"
" A `MatchResult(List(a))`:\n"
" - On success, preserves the list for further chaining.\n"
" - On failure, the chain becomes failed and later matchers are skipped.\n"
).
-spec contain(dream_test@types:match_result(list(HFK)), HFK) -> dream_test@types:match_result(list(HFK)).
contain(Value_or_result, Expected_item) ->
case Value_or_result of
{match_failed, Failure} ->
{match_failed, Failure};
{match_ok, Actual_list} ->
check_contains(Actual_list, Expected_item)
end.
-file("src/dream_test/matchers/collection.gleam", 119).
-spec check_not_contains(list(HFY), HFY) -> dream_test@types:match_result(list(HFY)).
check_not_contains(Actual_list, Unexpected_item) ->
case gleam@list:contains(Actual_list, Unexpected_item) of
false ->
{match_ok, Actual_list};
true ->
Payload = {collection_failure,
gleam@string:inspect(Actual_list),
<<"not "/utf8, (gleam@string:inspect(Unexpected_item))/binary>>,
<<"not_contain"/utf8>>},
{match_failed,
{assertion_failure,
<<"not_contain"/utf8>>,
<<""/utf8>>,
{some, Payload}}}
end.
-file("src/dream_test/matchers/collection.gleam", 109).
?DOC(
" Assert that a list does not contain a specific item.\n"
"\n"
" Use this when you want to assert absence while preserving the original list\n"
" for further checks.\n"
"\n"
" ## Example\n"
"\n"
" ```gleam\n"
" [\"a\", \"b\", \"c\"]\n"
" |> should\n"
" |> not_contain(\"d\")\n"
" |> or_fail_with(\"expected list to not contain \\\"d\\\"\")\n"
" ```\n"
"\n"
" ## Parameters\n"
"\n"
" - `value_or_result`: the `MatchResult(List(a))` produced by `should` (or a previous matcher)\n"
" - `unexpected_item`: the item that must *not* be present in the list\n"
"\n"
" ## Returns\n"
"\n"
" A `MatchResult(List(a))`:\n"
" - On success, preserves the list for further chaining.\n"
" - On failure, the chain becomes failed and later matchers are skipped.\n"
).
-spec not_contain(dream_test@types:match_result(list(HFT)), HFT) -> dream_test@types:match_result(list(HFT)).
not_contain(Value_or_result, Unexpected_item) ->
case Value_or_result of
{match_failed, Failure} ->
{match_failed, Failure};
{match_ok, Actual_list} ->
check_not_contains(Actual_list, Unexpected_item)
end.
-file("src/dream_test/matchers/collection.gleam", 177).
-spec check_length(list(HGH), integer()) -> dream_test@types:match_result(list(HGH)).
check_length(Actual_list, Expected_length) ->
Actual_length = erlang:length(Actual_list),
case Actual_length =:= Expected_length of
true ->
{match_ok, Actual_list};
false ->
Payload = {collection_failure,
<<"list with length "/utf8,
(erlang:integer_to_binary(Actual_length))/binary>>,
<<"list with length "/utf8,
(erlang:integer_to_binary(Expected_length))/binary>>,
<<"have_length"/utf8>>},
{match_failed,
{assertion_failure,
<<"have_length"/utf8>>,
<<""/utf8>>,
{some, Payload}}}
end.
-file("src/dream_test/matchers/collection.gleam", 167).
?DOC(
" Assert that a list has a specific length.\n"
"\n"
" Use this when you need to assert exact list length while preserving the list\n"
" for further checks.\n"
"\n"
" ## Example\n"
"\n"
" ```gleam\n"
" [1, 2, 3]\n"
" |> should\n"
" |> have_length(3)\n"
" |> or_fail_with(\"expected list length 3\")\n"
" ```\n"
"\n"
" ## Parameters\n"
"\n"
" - `value_or_result`: the `MatchResult(List(a))` produced by `should` (or a previous matcher)\n"
" - `expected_length`: the exact length the list must have\n"
"\n"
" ## Returns\n"
"\n"
" A `MatchResult(List(a))`:\n"
" - On success, preserves the list for further chaining.\n"
" - On failure, the chain becomes failed and later matchers are skipped.\n"
).
-spec have_length(dream_test@types:match_result(list(HGC)), integer()) -> dream_test@types:match_result(list(HGC)).
have_length(Value_or_result, Expected_length) ->
case Value_or_result of
{match_failed, Failure} ->
{match_failed, Failure};
{match_ok, Actual_list} ->
check_length(Actual_list, Expected_length)
end.
-file("src/dream_test/matchers/collection.gleam", 235).
-spec check_is_empty(list(HGQ)) -> dream_test@types:match_result(list(HGQ)).
check_is_empty(Actual_list) ->
case Actual_list of
[] ->
{match_ok, Actual_list};
_ ->
Payload = {collection_failure,
gleam@string:inspect(Actual_list),
<<"[]"/utf8>>,
<<"be_empty"/utf8>>},
{match_failed,
{assertion_failure,
<<"be_empty"/utf8>>,
<<""/utf8>>,
{some, Payload}}}
end.
-file("src/dream_test/matchers/collection.gleam", 226).
?DOC(
" Assert that a list is empty.\n"
"\n"
" Use this when you want to assert there are no values while preserving the\n"
" list for further checks.\n"
"\n"
" ## Example\n"
"\n"
" ```gleam\n"
" []\n"
" |> should\n"
" |> be_empty()\n"
" |> or_fail_with(\"expected empty list\")\n"
" ```\n"
"\n"
" ## Parameters\n"
"\n"
" - `value_or_result`: the `MatchResult(List(a))` produced by `should` (or a previous matcher)\n"
"\n"
" ## Returns\n"
"\n"
" A `MatchResult(List(a))`:\n"
" - On success, preserves the list for further chaining.\n"
" - On failure, the chain becomes failed and later matchers are skipped.\n"
).
-spec be_empty(dream_test@types:match_result(list(HGL))) -> dream_test@types:match_result(list(HGL)).
be_empty(Value_or_result) ->
case Value_or_result of
{match_failed, Failure} ->
{match_failed, Failure};
{match_ok, Actual_list} ->
check_is_empty(Actual_list)
end.