Commit 55a47daa authored by Siebers, Michael's avatar Siebers, Michael
Browse files

updated errors from web_api -> irrelevance

parent 9d79deba
%! do_handle_irrelevant_file(+Parameters:dict, -AbsPath:atom) is semidet.
%
% True if the item associated with the absolute path given in Parameters
......@@ -8,17 +6,19 @@
% is not an atom or if the dict contains any other key.
%
% @error instantiation_error if Parameters is unbound
% @error type_error(dict, Dict) if Dict is no dict
% @error existence_error(key, abs_path, Dict) if Dict does not contain the key abs_path
% @error existence_error(key, abs_path, Dict) if Dict does not contain the
% key abs_path
% @error instantiation_error if the dict value under abs_path is unbound
% @error type_error(atom, AbsPath) if the dict value under abs_path is not an atom
% @error unknown_key(KeyName, Dict) if the dict contains any KeyName which is not abs_path
% @error implementation_error(Cause) if checking the irrelevance itself throws an error (Cause)
% @error key_type_error(abs_path, atom, AbsPath) if the dict value AbsPath under
% the key abs_path is not an atom
% @error unknown_key(KeyName, Dict) if the dict contains any KeyName which is
% not abs_path
% @error implementation_error(Cause) if checking the irrelevance itself throws
% an error (Cause)
do_handle_irrelevant_file(Parameters,AbsPath) :-
must_be(dict,Parameters), % might throw type_error(dict, Parameters)
% or instantiation_error
AbsPath = Parameters.abs_path,
must_be(atom,AbsPath),
get_dict_typed(Parameters, abs_path, atom, AbsPath),
( (get_dict(Key,Parameters,_), Key\= abs_path )
-> throw(error(unknown_key(Key,Parameters),_))
; true
......@@ -27,3 +27,5 @@ do_handle_irrelevant_file(Parameters,AbsPath) :-
E,
throw(error(implementation_error(E),_))
).
/**************************************
* *
* web_api -> irrelevance integration *
* *
**************************************/
/**************************
* *
* web_api -> irrelevance *
* *
**************************/
:- dynamic user:irrelevant/1.
:- begin_tests('web_api -> irrelevance').
/*********
* mocks *
*********/
......@@ -51,18 +52,22 @@ test(do_handle_irrelevant_file_fail,
]) :-
web_api:do_handle_irrelevant_file(_{abs_path:Path},_).
% do_handle_irrelevant_file(Dict, Path) throws error(instantiation_error,_)
% if Dict is unbound. Takes precedence over type_error, unknown_key,
% missing_key, key_instantiation_error, key_type_error, and implementation_error.
test(do_handle_irrelevant_file_instantiation,
[ setup(setup_irrelevance_throws(some_error)),
cleanup(cleanup_irrelevance_throws),
error(instantiation_error)
]) :-
web_api:do_handle_irrelevant_file(_Dict,_).
% do_handle_irrelevant_file(Dict, Path) throws error(type_error(dict, Dict),_)
% if Dict is no dict. Takes precedence over other errors.
test(do_handle_irrelevant_file_nodict,
[
forall(type_not_dict(OtherTypeValue)),
error(type_error(dict, OtherTypeValue))
]) :-
web_api:do_handle_irrelevant_file(OtherTypeValue,_).
test(do_handle_irrelevant_file_type,
[
forall(type_not_dict(OtherTypeValue)),
forall(type_not(dict, OtherTypeValue)),
error(type_error(dict, OtherTypeValue)),
setup(setup_irrelevance_throws(some_error)),
cleanup(cleanup_irrelevance_throws)
......@@ -76,13 +81,10 @@ test(do_handle_irrelevant_file_type,
% and implementation_error.
test(do_handle_irrelevant_file_missingkey,
[
forall(member(Dict,[t{},t{another_key:some_atom}])),
error(existence_error(key, abs_path, Dict))
]) :-
web_api:do_handle_irrelevant_file(Dict,_).
test(do_handle_irrelevant_file_missingkey,
[
forall(member(Dict,[t{},t{another_key:some_atom}])),
forall((
type_is(dict,Dict),
\+ get_dict(abs_path, Dict, _)
)),
setup(setup_irrelevance_throws(some_error)),
cleanup(cleanup_irrelevance_throws),
error(existence_error(key, abs_path, Dict))
......@@ -95,56 +97,37 @@ test(do_handle_irrelevant_file_missingkey,
% unknown_key, and implementation_error.
test(do_handle_irrelevant_file_instantiation,
[
forall(member(Dict,[t{abs_path:_},t{abs_path:_,another_key:some_atom}])),
error(instantiation_error)
]) :-
web_api:do_handle_irrelevant_file(Dict,_).
test(do_handle_irrelevant_file_instantiation,
[
forall(member(Dict,[t{abs_path:_},t{abs_path:_,another_key:some_atom}])),
forall((
type_is(dict, RandomDict),
put_dict(t{abs_path:_}, RandomDict, Dict)
)),
setup(setup_irrelevance_throws(some_error)),
cleanup(cleanup_irrelevance_throws),
error(instantiation_error)
error(key_instantiation_error(abs_path))
]) :-
web_api:do_handle_irrelevant_file(Dict,_).
% do_handle_irrelevant_file(Dict, Path) throws error(type_error(atom, AbsPath),_)
% if the dict value under abs_path is not an atom. Takes precedence over
% unknown_key and implementation_error.
% do_handle_irrelevant_file(Dict, Path) throws
% error(key_type_error(abs_path, atom, AbsPath),_) if the dict value under
% abs_path is not an atom. Takes precedence over unknown_key and
% implementation_error.
test(do_handle_irrelevant_file_type,
[
forall(
(
forall((
type_is(dict, RandomDict),
type_not_atom(OtherTypeValue),
(Dict=t{abs_path:OtherTypeValue}; Dict=t{abs_path:OtherTypeValue,another_key:some_atom})
)
),
error(type_error(atom, OtherTypeValue))
]) :-
web_api:do_handle_irrelevant_file(Dict,_).
test(do_handle_irrelevant_file_type,
[
forall(
(
member(OtherTypeValue, [1, "test", 7.3, some(term)]),
(Dict=t{abs_path:OtherTypeValue}; Dict=t{abs_path:OtherTypeValue,another_key:some_atom})
)
),
put_dict(t{abs_path:OtherTypeValue}, RandomDict, Dict)
)),
setup(setup_irrelevance_throws(some_error)),
cleanup(cleanup_irrelevance_throws),
error(type_error(atom, OtherTypeValue))
error(key_type_error(abs_path,atom, OtherTypeValue))
]) :-
web_api:do_handle_irrelevant_file(Dict,_).
% do_handle_irrelevant_file(Dict, Path) throws error(unknown_key(KeyName, Dict),_)
% if the dict contains any other key than abs_path. Takes precedence over implementation_error.
test(do_handle_irrelevant_file_unknown,
[
error(unknown_key(another_key, t{abs_path:some_atom,another_key:another_atom}))
]) :-
web_api:do_handle_irrelevant_file(t{abs_path:some_atom,another_key:another_atom},_).
test(do_handle_irrelevant_file_unknown,
[
error(unknown_key(another_key, t{abs_path:some_atom,another_key:another_atom})),
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment