-module(startest@expect). -compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). -define(FILEPATH, "src/startest/expect.gleam"). -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_not_start_with/2, string_to_end_with/2, string_to_not_end_with/2, list_to_contain/2, list_to_not_contain/2, to_throw/1, to_not_throw/1, to_loosely_equal/3]). -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(" Assertions to be used in tests.\n"). -file("src/startest/expect.gleam", 11). ?DOC(" Asserts that the given value is equal to the expected value.\n"). -spec to_equal(SYD, SYD) -> nil. to_equal(Actual, Expected) -> case Actual =:= Expected of true -> nil; false -> _pipe = {assertion_error, erlang:list_to_binary( [<<"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. -file("src/startest/expect.gleam", 30). ?DOC(" Asserts that the given value is not equal to the expected value.\n"). -spec to_not_equal(SYE, SYE) -> nil. to_not_equal(Actual, Expected) -> case Actual /= Expected of true -> nil; false -> _pipe = {assertion_error, erlang:list_to_binary( [<<"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. -file("src/startest/expect.gleam", 49). ?DOC(" Asserts that the given value is `True`.\n"). -spec to_be_true(boolean()) -> nil. to_be_true(Actual) -> _pipe = Actual, to_equal(_pipe, true). -file("src/startest/expect.gleam", 55). ?DOC(" Asserts that the given value is `False`.\n"). -spec to_be_false(boolean()) -> nil. to_be_false(Actual) -> _pipe = Actual, to_equal(_pipe, false). -file("src/startest/expect.gleam", 61). ?DOC(" Asserts that the given value is `Ok(_)`.\n"). -spec to_be_ok({ok, SYF} | {error, any()}) -> SYF. to_be_ok(Actual) -> case Actual of {ok, Value} -> Value; {error, _} -> _pipe = {assertion_error, erlang:list_to_binary( [<<"Expected "/utf8>>, gleam@string:inspect(Actual), <<" to be Ok"/utf8>>] ), gleam@string:inspect(Actual), <<"Ok(_)"/utf8>>}, startest@assertion_error:raise(_pipe) end. -file("src/startest/expect.gleam", 75). ?DOC(" Asserts that the given value is `Error(_)`.\n"). -spec to_be_error({ok, any()} | {error, SYK}) -> SYK. to_be_error(Actual) -> case Actual of {error, Error} -> Error; {ok, _} -> _pipe = {assertion_error, erlang:list_to_binary( [<<"Expected "/utf8>>, gleam@string:inspect(Actual), <<" to be Error"/utf8>>] ), gleam@string:inspect(Actual), <<"Error(_)"/utf8>>}, startest@assertion_error:raise(_pipe) end. -file("src/startest/expect.gleam", 89). ?DOC(" Asserts that the given value is `Some(_)`.\n"). -spec to_be_some(gleam@option:option(SYN)) -> SYN. to_be_some(Actual) -> case Actual of {some, Value} -> Value; none -> _pipe = {assertion_error, erlang:list_to_binary( [<<"Expected "/utf8>>, gleam@string:inspect(Actual), <<" to be Some"/utf8>>] ), gleam@string:inspect(Actual), <<"Some(_)"/utf8>>}, startest@assertion_error:raise(_pipe) end. -file("src/startest/expect.gleam", 103). ?DOC(" Asserts that the given value is `None`.\n"). -spec to_be_none(gleam@option:option(any())) -> nil. to_be_none(Actual) -> case Actual of none -> nil; {some, _} -> _pipe = {assertion_error, erlang:list_to_binary( [<<"Expected "/utf8>>, gleam@string:inspect(Actual), <<" to be None"/utf8>>] ), gleam@string:inspect(Actual), <<"None"/utf8>>}, startest@assertion_error:raise(_pipe) end. -file("src/startest/expect.gleam", 117). ?DOC(" Asserts that the given string contains the expected string.\n"). -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, erlang:list_to_binary( [<<"Expected "/utf8>>, gleam@string:inspect(Actual), <<" to contain "/utf8>>, gleam@string:inspect(Expected)] ), Actual, Expected}, startest@assertion_error:raise(_pipe) end. -file("src/startest/expect.gleam", 136). ?DOC(" Asserts that the given string does not contain the expected string.\n"). -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, erlang:list_to_binary( [<<"Expected "/utf8>>, gleam@string:inspect(Actual), <<" to not contain "/utf8>>, gleam@string:inspect(Expected)] ), Actual, Expected}, startest@assertion_error:raise(_pipe) end. -file("src/startest/expect.gleam", 155). ?DOC(" Asserts that the given string starts with the expected string.\n"). -spec string_to_start_with(binary(), binary()) -> nil. string_to_start_with(Actual, Expected) -> case gleam_stdlib:string_starts_with(Actual, Expected) of true -> nil; false -> _pipe = {assertion_error, erlang:list_to_binary( [<<"Expected "/utf8>>, gleam@string:inspect(Actual), <<" to start with "/utf8>>, gleam@string:inspect(Expected)] ), Actual, Expected}, startest@assertion_error:raise(_pipe) end. -file("src/startest/expect.gleam", 174). ?DOC(" Asserts that the given string does not start with the expected string.\n"). -spec string_to_not_start_with(binary(), binary()) -> nil. string_to_not_start_with(Actual, Expected) -> case gleam_stdlib:string_starts_with(Actual, Expected) of false -> nil; true -> _pipe = {assertion_error, erlang:list_to_binary( [<<"Expected "/utf8>>, gleam@string:inspect(Actual), <<" to not start with "/utf8>>, gleam@string:inspect(Expected)] ), Actual, Expected}, startest@assertion_error:raise(_pipe) end. -file("src/startest/expect.gleam", 193). ?DOC(" Asserts that the given string ends with the expected string.\n"). -spec string_to_end_with(binary(), binary()) -> nil. string_to_end_with(Actual, Expected) -> case gleam_stdlib:string_ends_with(Actual, Expected) of true -> nil; false -> _pipe = {assertion_error, erlang:list_to_binary( [<<"Expected "/utf8>>, gleam@string:inspect(Actual), <<" to end with "/utf8>>, gleam@string:inspect(Expected)] ), Actual, Expected}, startest@assertion_error:raise(_pipe) end. -file("src/startest/expect.gleam", 212). ?DOC(" Asserts that the given string does not end with the expected string.\n"). -spec string_to_not_end_with(binary(), binary()) -> nil. string_to_not_end_with(Actual, Expected) -> case gleam_stdlib:string_ends_with(Actual, Expected) of false -> nil; true -> _pipe = {assertion_error, erlang:list_to_binary( [<<"Expected "/utf8>>, gleam@string:inspect(Actual), <<" to not end with "/utf8>>, gleam@string:inspect(Expected)] ), Actual, Expected}, startest@assertion_error:raise(_pipe) end. -file("src/startest/expect.gleam", 231). ?DOC(" Asserts that the given list contains the expected element.\n"). -spec list_to_contain(list(SYR), SYR) -> nil. list_to_contain(Actual, Expected) -> case gleam@list:contains(Actual, Expected) of true -> nil; false -> _pipe = {assertion_error, erlang:list_to_binary( [<<"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. -file("src/startest/expect.gleam", 250). ?DOC(" Asserts that the given list does not contain the expected element.\n"). -spec list_to_not_contain(list(SYT), SYT) -> nil. list_to_not_contain(Actual, Expected) -> case gleam@list:contains(Actual, Expected) of false -> nil; true -> _pipe = {assertion_error, erlang:list_to_binary( [<<"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. -file("src/startest/expect.gleam", 269). ?DOC(" Asserts that the given function throws an error.\n"). -spec to_throw(fun(() -> any())) -> nil. to_throw(F) -> case exception_ffi:rescue(F) of {error, _} -> nil; {ok, Value} -> _pipe = {assertion_error, erlang:list_to_binary( [<<"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. -file("src/startest/expect.gleam", 283). ?DOC(" Asserts that the given function does not throw an error.\n"). -spec to_not_throw(fun(() -> SYW)) -> SYW. to_not_throw(F) -> case exception_ffi:rescue(F) of {ok, Value} -> Value; {error, Exception} -> _pipe = {assertion_error, erlang:list_to_binary( [<<"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. -file("src/startest/expect.gleam", 324). ?DOC( " Formats a `Float` value as a `String` in a way that is consistent\n" " across targets.\n" ). -spec format_float(float()) -> binary(). format_float(Value) -> Repr = gleam_stdlib:float_to_string(Value), case gleam_stdlib:contains_string(Repr, <<"."/utf8>>) of true -> Repr; false -> <> end. -file("src/startest/expect.gleam", 298). ?DOC( " Asserts that the given `Float` is equal to the expected `Float` within the\n" " provided tolerance.\n" ). -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, erlang:list_to_binary( [<<"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.