-module(dream_test@matchers@string). -compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]). -define(FILEPATH, "src/dream_test/matchers/string.gleam"). -export([start_with/2, end_with/2, contain_string/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( " String matchers for dream_test.\n" "\n" " These matchers work with strings.\n" " They're re-exported through `dream_test/assertions/should`.\n" "\n" " ## Usage\n" "\n" " ```gleam\n" " import dream_test/assertions/should.{\n" " should, start_with, end_with, contain_string, or_fail_with,\n" " }\n" "\n" " greeting\n" " |> should()\n" " |> start_with(\"Hello\")\n" " |> or_fail_with(\"Greeting should start with Hello\")\n" "\n" " filename\n" " |> should()\n" " |> end_with(\".gleam\")\n" " |> or_fail_with(\"Should be a Gleam file\")\n" "\n" " log_message\n" " |> should()\n" " |> contain_string(\"error\")\n" " |> or_fail_with(\"Log should mention error\")\n" " ```\n" ). -file("src/dream_test/matchers/string.gleam", 56). -spec check_starts_with(binary(), binary()) -> dream_test@types:match_result(binary()). check_starts_with(Actual, Prefix) -> case gleam_stdlib:string_starts_with(Actual, Prefix) of true -> {match_ok, Actual}; false -> Payload = {string_match_failure, Actual, Prefix, <<"start_with"/utf8>>}, {match_failed, {assertion_failure, <<"start_with"/utf8>>, <<""/utf8>>, {some, Payload}}} end. -file("src/dream_test/matchers/string.gleam", 46). ?DOC( " Assert that a string starts with a prefix.\n" "\n" " ## Example\n" "\n" " ```gleam\n" " greeting\n" " |> should()\n" " |> start_with(\"Hello\")\n" " |> or_fail_with(\"Greeting should start with Hello\")\n" " ```\n" ). -spec start_with(dream_test@types:match_result(binary()), binary()) -> dream_test@types:match_result(binary()). start_with(Value_or_result, Prefix) -> case Value_or_result of {match_failed, Failure} -> {match_failed, Failure}; {match_ok, Actual} -> check_starts_with(Actual, Prefix) end. -file("src/dream_test/matchers/string.gleam", 97). -spec check_ends_with(binary(), binary()) -> dream_test@types:match_result(binary()). check_ends_with(Actual, Suffix) -> case gleam_stdlib:string_ends_with(Actual, Suffix) of true -> {match_ok, Actual}; false -> Payload = {string_match_failure, Actual, Suffix, <<"end_with"/utf8>>}, {match_failed, {assertion_failure, <<"end_with"/utf8>>, <<""/utf8>>, {some, Payload}}} end. -file("src/dream_test/matchers/string.gleam", 87). ?DOC( " Assert that a string ends with a suffix.\n" "\n" " ## Example\n" "\n" " ```gleam\n" " filename\n" " |> should()\n" " |> end_with(\".gleam\")\n" " |> or_fail_with(\"File should be a Gleam file\")\n" " ```\n" ). -spec end_with(dream_test@types:match_result(binary()), binary()) -> dream_test@types:match_result(binary()). end_with(Value_or_result, Suffix) -> case Value_or_result of {match_failed, Failure} -> {match_failed, Failure}; {match_ok, Actual} -> check_ends_with(Actual, Suffix) end. -file("src/dream_test/matchers/string.gleam", 138). -spec check_contains_string(binary(), binary()) -> dream_test@types:match_result(binary()). check_contains_string(Actual, Substring) -> case gleam_stdlib:contains_string(Actual, Substring) of true -> {match_ok, Actual}; false -> Payload = {string_match_failure, Actual, Substring, <<"contain_string"/utf8>>}, {match_failed, {assertion_failure, <<"contain_string"/utf8>>, <<""/utf8>>, {some, Payload}}} end. -file("src/dream_test/matchers/string.gleam", 128). ?DOC( " Assert that a string contains a substring.\n" "\n" " ## Example\n" "\n" " ```gleam\n" " log_message\n" " |> should()\n" " |> contain_string(\"error\")\n" " |> or_fail_with(\"Log should mention error\")\n" " ```\n" ). -spec contain_string(dream_test@types:match_result(binary()), binary()) -> dream_test@types:match_result(binary()). contain_string(Value_or_result, Substring) -> case Value_or_result of {match_failed, Failure} -> {match_failed, Failure}; {match_ok, Actual} -> check_contains_string(Actual, Substring) end.