Current section
Files
Jump to
Current section
Files
src/dream_test@matchers@comparison.erl
-module(dream_test@matchers@comparison).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/dream_test/matchers/comparison.gleam").
-export([be_greater_than/2, be_less_than/2, be_at_least/2, be_at_most/2, be_between/3, be_in_range/3, be_greater_than_float/2, be_less_than_float/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(
" Comparison matchers for dream_test.\n"
"\n"
" These matchers compare numeric values and are re-exported through\n"
" `dream_test/matchers`.\n"
"\n"
" Use them to assert ordering relationships (greater-than, less-than, in a\n"
" range, etc.) while preserving the numeric value for further chaining.\n"
"\n"
" ## Example\n"
"\n"
" ```gleam\n"
" 10\n"
" |> should\n"
" |> be_greater_than(0)\n"
" |> or_fail_with(\"expected 10 to be greater than 0\")\n"
" ```\n"
).
-file("src/dream_test/matchers/comparison.gleam", 55).
-spec check_greater_than(integer(), integer()) -> dream_test@types:match_result(integer()).
check_greater_than(Actual, Threshold) ->
case Actual > Threshold of
true ->
{match_ok, Actual};
false ->
Payload = {comparison_failure,
erlang:integer_to_binary(Actual),
<<"> "/utf8, (erlang:integer_to_binary(Threshold))/binary>>,
<<"be_greater_than"/utf8>>},
{match_failed,
{assertion_failure,
<<"be_greater_than"/utf8>>,
<<""/utf8>>,
{some, Payload}}}
end.
-file("src/dream_test/matchers/comparison.gleam", 45).
?DOC(
" Assert that an integer is greater than a threshold.\n"
"\n"
" ## Parameters\n"
"\n"
" - `value_or_result`: the `MatchResult(Int)` produced by `should` (or a previous matcher)\n"
" - `threshold`: the value the actual integer must be greater than\n"
"\n"
" ## Returns\n"
"\n"
" A `MatchResult(Int)` preserving the integer for further chaining.\n"
"\n"
" ## Example\n"
"\n"
" ```gleam\n"
" 10\n"
" |> should\n"
" |> be_greater_than(0)\n"
" |> or_fail_with(\"expected 10 to be greater than 0\")\n"
" ```\n"
).
-spec be_greater_than(dream_test@types:match_result(integer()), integer()) -> dream_test@types:match_result(integer()).
be_greater_than(Value_or_result, Threshold) ->
case Value_or_result of
{match_failed, Failure} ->
{match_failed, Failure};
{match_ok, Actual} ->
check_greater_than(Actual, Threshold)
end.
-file("src/dream_test/matchers/comparison.gleam", 105).
-spec check_less_than(integer(), integer()) -> dream_test@types:match_result(integer()).
check_less_than(Actual, Threshold) ->
case Actual < Threshold of
true ->
{match_ok, Actual};
false ->
Payload = {comparison_failure,
erlang:integer_to_binary(Actual),
<<"< "/utf8, (erlang:integer_to_binary(Threshold))/binary>>,
<<"be_less_than"/utf8>>},
{match_failed,
{assertion_failure,
<<"be_less_than"/utf8>>,
<<""/utf8>>,
{some, Payload}}}
end.
-file("src/dream_test/matchers/comparison.gleam", 95).
?DOC(
" Assert that an integer is less than a threshold.\n"
"\n"
" ## Parameters\n"
"\n"
" - `value_or_result`: the `MatchResult(Int)` produced by `should` (or a previous matcher)\n"
" - `threshold`: the value the actual integer must be less than\n"
"\n"
" ## Returns\n"
"\n"
" A `MatchResult(Int)` preserving the integer for further chaining.\n"
"\n"
" ## Example\n"
"\n"
" ```gleam\n"
" 10\n"
" |> should\n"
" |> be_less_than(100)\n"
" |> or_fail_with(\"expected 10 to be less than 100\")\n"
" ```\n"
).
-spec be_less_than(dream_test@types:match_result(integer()), integer()) -> dream_test@types:match_result(integer()).
be_less_than(Value_or_result, Threshold) ->
case Value_or_result of
{match_failed, Failure} ->
{match_failed, Failure};
{match_ok, Actual} ->
check_less_than(Actual, Threshold)
end.
-file("src/dream_test/matchers/comparison.gleam", 155).
-spec check_at_least(integer(), integer()) -> dream_test@types:match_result(integer()).
check_at_least(Actual, Minimum) ->
case Actual >= Minimum of
true ->
{match_ok, Actual};
false ->
Payload = {comparison_failure,
erlang:integer_to_binary(Actual),
<<">= "/utf8, (erlang:integer_to_binary(Minimum))/binary>>,
<<"be_at_least"/utf8>>},
{match_failed,
{assertion_failure,
<<"be_at_least"/utf8>>,
<<""/utf8>>,
{some, Payload}}}
end.
-file("src/dream_test/matchers/comparison.gleam", 145).
?DOC(
" Assert that an integer is at least a minimum value (>=).\n"
"\n"
" ## Parameters\n"
"\n"
" - `value_or_result`: the `MatchResult(Int)` produced by `should` (or a previous matcher)\n"
" - `minimum`: the minimum allowed value (inclusive)\n"
"\n"
" ## Returns\n"
"\n"
" A `MatchResult(Int)` preserving the integer for further chaining.\n"
"\n"
" ## Example\n"
"\n"
" ```gleam\n"
" 10\n"
" |> should\n"
" |> be_at_least(10)\n"
" |> or_fail_with(\"expected 10 to be at least 10\")\n"
" ```\n"
).
-spec be_at_least(dream_test@types:match_result(integer()), integer()) -> dream_test@types:match_result(integer()).
be_at_least(Value_or_result, Minimum) ->
case Value_or_result of
{match_failed, Failure} ->
{match_failed, Failure};
{match_ok, Actual} ->
check_at_least(Actual, Minimum)
end.
-file("src/dream_test/matchers/comparison.gleam", 205).
-spec check_at_most(integer(), integer()) -> dream_test@types:match_result(integer()).
check_at_most(Actual, Maximum) ->
case Actual =< Maximum of
true ->
{match_ok, Actual};
false ->
Payload = {comparison_failure,
erlang:integer_to_binary(Actual),
<<"<= "/utf8, (erlang:integer_to_binary(Maximum))/binary>>,
<<"be_at_most"/utf8>>},
{match_failed,
{assertion_failure,
<<"be_at_most"/utf8>>,
<<""/utf8>>,
{some, Payload}}}
end.
-file("src/dream_test/matchers/comparison.gleam", 195).
?DOC(
" Assert that an integer is at most a maximum value (<=).\n"
"\n"
" ## Parameters\n"
"\n"
" - `value_or_result`: the `MatchResult(Int)` produced by `should` (or a previous matcher)\n"
" - `maximum`: the maximum allowed value (inclusive)\n"
"\n"
" ## Returns\n"
"\n"
" A `MatchResult(Int)` preserving the integer for further chaining.\n"
"\n"
" ## Example\n"
"\n"
" ```gleam\n"
" 10\n"
" |> should\n"
" |> be_at_most(10)\n"
" |> or_fail_with(\"expected 10 to be at most 10\")\n"
" ```\n"
).
-spec be_at_most(dream_test@types:match_result(integer()), integer()) -> dream_test@types:match_result(integer()).
be_at_most(Value_or_result, Maximum) ->
case Value_or_result of
{match_failed, Failure} ->
{match_failed, Failure};
{match_ok, Actual} ->
check_at_most(Actual, Maximum)
end.
-file("src/dream_test/matchers/comparison.gleam", 259).
-spec check_between(integer(), integer(), integer()) -> dream_test@types:match_result(integer()).
check_between(Actual, Min, Max) ->
case (Actual > Min) andalso (Actual < Max) of
true ->
{match_ok, Actual};
false ->
Payload = {comparison_failure,
erlang:integer_to_binary(Actual),
<<<<(erlang:integer_to_binary(Min))/binary, " < value < "/utf8>>/binary,
(erlang:integer_to_binary(Max))/binary>>,
<<"be_between"/utf8>>},
{match_failed,
{assertion_failure,
<<"be_between"/utf8>>,
<<""/utf8>>,
{some, Payload}}}
end.
-file("src/dream_test/matchers/comparison.gleam", 248).
?DOC(
" Assert that an integer is between two values (exclusive).\n"
"\n"
" The value must be strictly greater than `min` and strictly less than `max`.\n"
"\n"
" ## Parameters\n"
"\n"
" - `value_or_result`: the `MatchResult(Int)` produced by `should` (or a previous matcher)\n"
" - `min`: lower bound (exclusive)\n"
" - `max`: upper bound (exclusive)\n"
"\n"
" ## Returns\n"
"\n"
" A `MatchResult(Int)` preserving the integer for further chaining.\n"
"\n"
" ## Example\n"
"\n"
" ```gleam\n"
" 5\n"
" |> should\n"
" |> be_between(1, 10)\n"
" |> or_fail_with(\"expected 5 to be between 1 and 10\")\n"
" ```\n"
).
-spec be_between(dream_test@types:match_result(integer()), integer(), integer()) -> dream_test@types:match_result(integer()).
be_between(Value_or_result, Min, Max) ->
case Value_or_result of
{match_failed, Failure} ->
{match_failed, Failure};
{match_ok, Actual} ->
check_between(Actual, Min, Max)
end.
-file("src/dream_test/matchers/comparison.gleam", 313).
-spec check_in_range(integer(), integer(), integer()) -> dream_test@types:match_result(integer()).
check_in_range(Actual, Min, Max) ->
case (Actual >= Min) andalso (Actual =< Max) of
true ->
{match_ok, Actual};
false ->
Payload = {comparison_failure,
erlang:integer_to_binary(Actual),
<<<<(erlang:integer_to_binary(Min))/binary,
" <= value <= "/utf8>>/binary,
(erlang:integer_to_binary(Max))/binary>>,
<<"be_in_range"/utf8>>},
{match_failed,
{assertion_failure,
<<"be_in_range"/utf8>>,
<<""/utf8>>,
{some, Payload}}}
end.
-file("src/dream_test/matchers/comparison.gleam", 302).
?DOC(
" Assert that an integer is within a range (inclusive).\n"
"\n"
" The value must be >= `min` and <= `max`.\n"
"\n"
" ## Parameters\n"
"\n"
" - `value_or_result`: the `MatchResult(Int)` produced by `should` (or a previous matcher)\n"
" - `min`: lower bound (inclusive)\n"
" - `max`: upper bound (inclusive)\n"
"\n"
" ## Returns\n"
"\n"
" A `MatchResult(Int)` preserving the integer for further chaining.\n"
"\n"
" ## Example\n"
"\n"
" ```gleam\n"
" 10\n"
" |> should\n"
" |> be_in_range(0, 100)\n"
" |> or_fail_with(\"expected 10 to be in range 0..100\")\n"
" ```\n"
).
-spec be_in_range(
dream_test@types:match_result(integer()),
integer(),
integer()
) -> dream_test@types:match_result(integer()).
be_in_range(Value_or_result, Min, Max) ->
case Value_or_result of
{match_failed, Failure} ->
{match_failed, Failure};
{match_ok, Actual} ->
check_in_range(Actual, Min, Max)
end.
-file("src/dream_test/matchers/comparison.gleam", 363).
-spec check_greater_than_float(float(), float()) -> dream_test@types:match_result(float()).
check_greater_than_float(Actual, Threshold) ->
case Actual > Threshold of
true ->
{match_ok, Actual};
false ->
Payload = {comparison_failure,
gleam_stdlib:float_to_string(Actual),
<<"> "/utf8, (gleam_stdlib:float_to_string(Threshold))/binary>>,
<<"be_greater_than_float"/utf8>>},
{match_failed,
{assertion_failure,
<<"be_greater_than_float"/utf8>>,
<<""/utf8>>,
{some, Payload}}}
end.
-file("src/dream_test/matchers/comparison.gleam", 353).
?DOC(
" Assert that a float is greater than a threshold.\n"
"\n"
" ## Parameters\n"
"\n"
" - `value_or_result`: the `MatchResult(Float)` produced by `should` (or a previous matcher)\n"
" - `threshold`: the value the actual float must be greater than\n"
"\n"
" ## Returns\n"
"\n"
" A `MatchResult(Float)` preserving the float for further chaining.\n"
"\n"
" ## Example\n"
"\n"
" ```gleam\n"
" 0.5\n"
" |> should\n"
" |> be_greater_than_float(0.0)\n"
" |> or_fail_with(\"expected 0.5 to be greater than 0.0\")\n"
" ```\n"
).
-spec be_greater_than_float(dream_test@types:match_result(float()), float()) -> dream_test@types:match_result(float()).
be_greater_than_float(Value_or_result, Threshold) ->
case Value_or_result of
{match_failed, Failure} ->
{match_failed, Failure};
{match_ok, Actual} ->
check_greater_than_float(Actual, Threshold)
end.
-file("src/dream_test/matchers/comparison.gleam", 416).
-spec check_less_than_float(float(), float()) -> dream_test@types:match_result(float()).
check_less_than_float(Actual, Threshold) ->
case Actual < Threshold of
true ->
{match_ok, Actual};
false ->
Payload = {comparison_failure,
gleam_stdlib:float_to_string(Actual),
<<"< "/utf8, (gleam_stdlib:float_to_string(Threshold))/binary>>,
<<"be_less_than_float"/utf8>>},
{match_failed,
{assertion_failure,
<<"be_less_than_float"/utf8>>,
<<""/utf8>>,
{some, Payload}}}
end.
-file("src/dream_test/matchers/comparison.gleam", 406).
?DOC(
" Assert that a float is less than a threshold.\n"
"\n"
" ## Parameters\n"
"\n"
" - `value_or_result`: the `MatchResult(Float)` produced by `should` (or a previous matcher)\n"
" - `threshold`: the value the actual float must be less than\n"
"\n"
" ## Returns\n"
"\n"
" A `MatchResult(Float)` preserving the float for further chaining.\n"
"\n"
" ## Example\n"
"\n"
" ```gleam\n"
" 0.5\n"
" |> should\n"
" |> be_less_than_float(1.0)\n"
" |> or_fail_with(\"expected 0.5 to be less than 1.0\")\n"
" ```\n"
).
-spec be_less_than_float(dream_test@types:match_result(float()), float()) -> dream_test@types:match_result(float()).
be_less_than_float(Value_or_result, Threshold) ->
case Value_or_result of
{match_failed, Failure} ->
{match_failed, Failure};
{match_ok, Actual} ->
check_less_than_float(Actual, Threshold)
end.