-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 lists.\n" " They're re-exported through `dream_test/assertions/should`.\n" "\n" " ## Usage\n" "\n" " ```gleam\n" " import dream_test/assertions/should.{\n" " should, contain, not_contain, have_length, be_empty, or_fail_with,\n" " }\n" "\n" " // Check if list contains an item\n" " users\n" " |> should()\n" " |> contain(alice)\n" " |> or_fail_with(\"Users should include Alice\")\n" "\n" " // Check list length\n" " get_results()\n" " |> should()\n" " |> have_length(3)\n" " |> or_fail_with(\"Should have 3 results\")\n" " ```\n" ). -file("src/dream_test/matchers/collection.gleam", 55). -spec check_contains(list(FRA), FRA) -> dream_test@types:match_result(list(FRA)). 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", 45). ?DOC( " Assert that a list contains a specific item.\n" "\n" " ## Example\n" "\n" " ```gleam\n" " [1, 2, 3]\n" " |> should()\n" " |> contain(2)\n" " |> or_fail_with(\"List should contain 2\")\n" " ```\n" ). -spec contain(dream_test@types:match_result(list(FQV)), FQV) -> dream_test@types:match_result(list(FQV)). 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", 99). -spec check_not_contains(list(FRJ), FRJ) -> dream_test@types:match_result(list(FRJ)). 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", 89). ?DOC( " Assert that a list does not contain a specific item.\n" "\n" " ## Example\n" "\n" " ```gleam\n" " [\"a\", \"b\", \"c\"]\n" " |> should()\n" " |> not_contain(\"d\")\n" " |> or_fail_with(\"List should not contain 'd'\")\n" " ```\n" ). -spec not_contain(dream_test@types:match_result(list(FRE)), FRE) -> dream_test@types:match_result(list(FRE)). 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", 143). -spec check_length(list(FRS), integer()) -> dream_test@types:match_result(list(FRS)). 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", 133). ?DOC( " Assert that a list has a specific length.\n" "\n" " ## Example\n" "\n" " ```gleam\n" " get_users()\n" " |> should()\n" " |> have_length(3)\n" " |> or_fail_with(\"Should have 3 users\")\n" " ```\n" ). -spec have_length(dream_test@types:match_result(list(FRN)), integer()) -> dream_test@types:match_result(list(FRN)). 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", 186). -spec check_is_empty(list(FSB)) -> dream_test@types:match_result(list(FSB)). 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", 179). ?DOC( " Assert that a list is empty.\n" "\n" " ## Example\n" "\n" " ```gleam\n" " get_errors()\n" " |> should()\n" " |> be_empty()\n" " |> or_fail_with(\"Should have no errors\")\n" " ```\n" ). -spec be_empty(dream_test@types:match_result(list(FRW))) -> dream_test@types:match_result(list(FRW)). 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.