-module(startest@expect). -compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). -export([to_equal/2, to_not_equal/2, to_be_true/1, to_be_false/1, to_be_ok/1, to_be_error/1, to_be_some/1, to_be_none/1, string_to_contain/2, string_to_not_contain/2, string_to_start_with/2, string_to_end_with/2, list_to_contain/2, list_to_not_contain/2, to_throw/1, to_not_throw/1, to_loosely_equal/3]). -spec to_equal(SPD, SPD) -> nil. to_equal(Actual, Expected) -> case Actual =:= Expected of true -> nil; false -> _pipe = {assertion_error, gleam@string:concat( [<<"Expected "/utf8>>, gleam@string:inspect(Actual), <<" to equal "/utf8>>, gleam@string:inspect(Expected)] ), gleam@string:inspect(Actual), gleam@string:inspect(Expected)}, startest@assertion_error:raise(_pipe) end. -spec to_not_equal(SPE, SPE) -> nil. to_not_equal(Actual, Expected) -> case Actual /= Expected of true -> nil; false -> _pipe = {assertion_error, gleam@string:concat( [<<"Expected "/utf8>>, gleam@string:inspect(Actual), <<" to not equal "/utf8>>, gleam@string:inspect(Expected)] ), gleam@string:inspect(Actual), gleam@string:inspect(Expected)}, startest@assertion_error:raise(_pipe) end. -spec to_be_true(boolean()) -> nil. to_be_true(Actual) -> _pipe = Actual, to_equal(_pipe, true). -spec to_be_false(boolean()) -> nil. to_be_false(Actual) -> _pipe = Actual, to_equal(_pipe, false). -spec to_be_ok({ok, SPF} | {error, any()}) -> SPF. to_be_ok(Actual) -> case Actual of {ok, Value} -> Value; {error, _} -> _pipe = {assertion_error, gleam@string:concat( [<<"Expected "/utf8>>, gleam@string:inspect(Actual), <<" to be Ok"/utf8>>] ), gleam@string:inspect(Actual), <<"Ok(_)"/utf8>>}, startest@assertion_error:raise(_pipe) end. -spec to_be_error({ok, any()} | {error, SPK}) -> SPK. to_be_error(Actual) -> case Actual of {error, Error} -> Error; {ok, _} -> _pipe = {assertion_error, gleam@string:concat( [<<"Expected "/utf8>>, gleam@string:inspect(Actual), <<" to be Error"/utf8>>] ), gleam@string:inspect(Actual), <<"Error(_)"/utf8>>}, startest@assertion_error:raise(_pipe) end. -spec to_be_some(gleam@option:option(SPN)) -> SPN. to_be_some(Actual) -> case Actual of {some, Value} -> Value; none -> _pipe = {assertion_error, gleam@string:concat( [<<"Expected "/utf8>>, gleam@string:inspect(Actual), <<" to be Some"/utf8>>] ), gleam@string:inspect(Actual), <<"Some(_)"/utf8>>}, startest@assertion_error:raise(_pipe) end. -spec to_be_none(gleam@option:option(any())) -> nil. to_be_none(Actual) -> case Actual of none -> nil; {some, _} -> _pipe = {assertion_error, gleam@string:concat( [<<"Expected "/utf8>>, gleam@string:inspect(Actual), <<" to be None"/utf8>>] ), gleam@string:inspect(Actual), <<"None"/utf8>>}, startest@assertion_error:raise(_pipe) end. -spec string_to_contain(binary(), binary()) -> nil. string_to_contain(Actual, Expected) -> case gleam_stdlib:contains_string(Actual, Expected) of true -> nil; false -> _pipe = {assertion_error, gleam@string:concat( [<<"Expected "/utf8>>, gleam@string:inspect(Actual), <<" to contain "/utf8>>, gleam@string:inspect(Expected)] ), Actual, Expected}, startest@assertion_error:raise(_pipe) end. -spec string_to_not_contain(binary(), binary()) -> nil. string_to_not_contain(Actual, Expected) -> case gleam_stdlib:contains_string(Actual, Expected) of false -> nil; true -> _pipe = {assertion_error, gleam@string:concat( [<<"Expected "/utf8>>, gleam@string:inspect(Actual), <<" to not contain "/utf8>>, gleam@string:inspect(Expected)] ), Actual, Expected}, startest@assertion_error:raise(_pipe) end. -spec string_to_start_with(binary(), binary()) -> nil. string_to_start_with(Actual, Expected) -> case gleam@string:starts_with(Actual, Expected) of true -> nil; false -> _pipe = {assertion_error, gleam@string:concat( [<<"Expected "/utf8>>, gleam@string:inspect(Actual), <<" to start with "/utf8>>, gleam@string:inspect(Expected)] ), Actual, Expected}, startest@assertion_error:raise(_pipe) end. -spec string_to_end_with(binary(), binary()) -> nil. string_to_end_with(Actual, Expected) -> case gleam@string:ends_with(Actual, Expected) of true -> nil; false -> _pipe = {assertion_error, gleam@string:concat( [<<"Expected "/utf8>>, gleam@string:inspect(Actual), <<" to end with "/utf8>>, gleam@string:inspect(Expected)] ), Actual, Expected}, startest@assertion_error:raise(_pipe) end. -spec list_to_contain(list(SPR), SPR) -> nil. list_to_contain(Actual, Expected) -> case gleam@list:contains(Actual, Expected) of true -> nil; false -> _pipe = {assertion_error, gleam@string:concat( [<<"Expected "/utf8>>, gleam@string:inspect(Actual), <<" to contain "/utf8>>, gleam@string:inspect(Expected)] ), gleam@string:inspect(Actual), gleam@string:inspect(Expected)}, startest@assertion_error:raise(_pipe) end. -spec list_to_not_contain(list(SPT), SPT) -> nil. list_to_not_contain(Actual, Expected) -> case gleam@list:contains(Actual, Expected) of false -> nil; true -> _pipe = {assertion_error, gleam@string:concat( [<<"Expected "/utf8>>, gleam@string:inspect(Actual), <<" to not contain "/utf8>>, gleam@string:inspect(Expected)] ), gleam@string:inspect(Actual), gleam@string:inspect(Expected)}, startest@assertion_error:raise(_pipe) end. -spec to_throw(fun(() -> any())) -> nil. to_throw(F) -> case exception_ffi:rescue(F) of {error, _} -> nil; {ok, Value} -> _pipe = {assertion_error, gleam@string:concat( [<<"Expected "/utf8>>, gleam@string:inspect(F), <<" to throw an error"/utf8>>] ), gleam@string:inspect(Value), gleam@string:inspect(nil)}, startest@assertion_error:raise(_pipe) end. -spec to_not_throw(fun(() -> SPW)) -> SPW. to_not_throw(F) -> case exception_ffi:rescue(F) of {ok, Value} -> Value; {error, Exception} -> _pipe = {assertion_error, gleam@string:concat( [<<"Expected "/utf8>>, gleam@string:inspect(F), <<" to not throw an error"/utf8>>] ), gleam@string:inspect(nil), gleam@string:inspect(Exception)}, startest@assertion_error:raise(_pipe) end. -spec format_float(float()) -> binary(). format_float(Value) -> Repr = gleam@float:to_string(Value), case gleam_stdlib:contains_string(Repr, <<"."/utf8>>) of true -> Repr; false -> <> end. -spec to_loosely_equal(float(), float(), float()) -> nil. to_loosely_equal(Actual, Expected, Tolerance) -> case gleam@float:loosely_equals(Actual, Expected, Tolerance) of true -> nil; false -> _pipe = {assertion_error, gleam@string:concat( [<<"Expected "/utf8>>, format_float(Actual), <<" to loosely equal "/utf8>>, format_float(Expected), <<" with a tolerance of "/utf8>>, format_float(Tolerance)] ), format_float(Actual), <<<<(format_float(Expected))/binary, " ± "/utf8>>/binary, (format_float(Tolerance))/binary>>}, startest@assertion_error:raise(_pipe) end.