Current section

Files

Jump to
startest src startest@assertion_error.erl
Raw

src/startest@assertion_error.erl

-module(startest@assertion_error).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]).
-export([raise/1]).
-export_type([assertion_error/0, rescued_assertion_error/0]).
-type assertion_error() :: {assertion_error, binary(), binary(), binary()}.
-type rescued_assertion_error() :: {rescued_assertion_error, binary()}.
-spec show_diff(binary(), binary()) -> binary().
show_diff(Actual, Expected) ->
gleam@string:concat(
[gleam_community@ansi:green(<<"- Expected"/utf8>>),
<<"\n"/utf8>>,
gleam_community@ansi:red(<<"+ Received"/utf8>>),
<<"\n\n"/utf8>>,
gleam_community@ansi:green(<<"- "/utf8, Expected/binary>>),
<<"\n"/utf8>>,
gleam_community@ansi:red(<<"+ "/utf8, Actual/binary>>)]
).
-spec raise(assertion_error()) -> any().
raise(Error) ->
Blank_line = <<"\n\n"/utf8>>,
erlang:error(#{gleam_error => panic,
message => gleam@string:concat(
[erlang:element(2, Error),
Blank_line,
show_diff(
erlang:element(3, Error),
erlang:element(4, Error)
)]
),
module => <<"startest/assertion_error"/utf8>>,
function => <<"raise"/utf8>>,
line => 18}).