Packages

A library for programatically building and running test cases

Current section

Files

Jump to
testbldr src testbldr@should.erl
Raw

src/testbldr@should.erl

-module(testbldr@should).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function]).
-export([be_true/1, be_false/1, be_ok/1, be_error/1, equal/2, not_equal/2]).
-spec be_true(boolean()) -> testbldr@pieces:test_outcome().
be_true(A) ->
case A of
true ->
pass;
false ->
{fail, <<"\nExpected True, got False\n"/utf8>>}
end.
-spec be_false(boolean()) -> testbldr@pieces:test_outcome().
be_false(A) ->
case A of
false ->
pass;
true ->
{fail, <<"\nExpected False, got True\n"/utf8>>}
end.
-spec be_ok({ok, any()} | {error, any()}) -> testbldr@pieces:test_outcome().
be_ok(A) ->
case A of
{ok, _} ->
pass;
{error, _} ->
{fail,
<<<<"\nExpected Ok, Got Error: "/utf8,
(gleam@string:inspect(A))/binary>>/binary,
"\n"/utf8>>}
end.
-spec be_error({ok, any()} | {error, any()}) -> testbldr@pieces:test_outcome().
be_error(A) ->
case A of
{ok, _} ->
{fail,
<<<<"\nExpected Error, Got Ok: "/utf8,
(gleam@string:inspect(A))/binary>>/binary,
"\n"/utf8>>};
{error, _} ->
pass
end.
-spec bin_op_msg(any(), binary(), any()) -> binary().
bin_op_msg(Lhs, Op, Rhs) ->
<<<<<<<<<<<<"\nlhs: "/utf8, (gleam@string:inspect(Lhs))/binary>>/binary,
"\nrhs: "/utf8>>/binary,
(gleam@string:inspect(Rhs))/binary>>/binary,
"\nassertion lhs "/utf8>>/binary,
Op/binary>>/binary,
" rhs failed\n"/utf8>>.
-spec equal(GKG, GKG) -> testbldr@pieces:test_outcome().
equal(A, B) ->
case A =:= B of
true ->
pass;
false ->
{fail, bin_op_msg(A, <<"=="/utf8>>, B)}
end.
-spec not_equal(GKI, GKI) -> testbldr@pieces:test_outcome().
not_equal(A, B) ->
case A /= B of
true ->
pass;
false ->
{fail, bin_op_msg(A, <<"!="/utf8>>, B)}
end.