Skip to content

Commit

Permalink
normalize set errors. breaking change
Browse files Browse the repository at this point in the history
  • Loading branch information
andreineculau committed Dec 9, 2015
1 parent 9298535 commit 40c2613
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 14 deletions.
12 changes: 7 additions & 5 deletions src/katt_validate_type.erl
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ validate_set( ParentKey
, _Callbacks
, Errors
) ->
[ {unexpected, ParentKey ++ "/" ++ Key}
|| {Key, _Value} <- Actual
[ {unexpected, {ParentKey ++ "/" ++ AKey, undefined, AValue}}
|| {AKey, AValue} <- Actual
] ++ Errors;
%% All actual elements have been consumed,
%% and there are still expected elements
Expand All @@ -103,8 +103,8 @@ validate_set( ParentKey
, _Callbacks
, Errors
) ->
[ {not_contains, ParentKey ++ "/" ++ Key}
|| {Key, _Value} <- Expected
[ {not_contains, {ParentKey ++ "/" ++ EKey, EValue, undefined}}
|| {EKey, EValue} <- Expected
] ++ Errors;
%% There is at least one expected and one actual element
validate_set( ParentKey
Expand All @@ -126,7 +126,9 @@ validate_set( ParentKey
, Actual),
case Split of
{Actual, []} ->
Errors1 = [{not_contains, ParentKey ++ "/" ++ EKey}] ++ Errors,
Errors1 =
[{not_contains, {ParentKey ++ "/" ++ EKey, EValue, undefined}}] ++
Errors,
validate_set(ParentKey, ERest, Actual, Unexpected, Callbacks, Errors1);
{ARest1, [{_AKey, AValue}|ARest2]} ->
ARest = ARest1 ++ ARest2,
Expand Down
14 changes: 9 additions & 5 deletions test/katt_run_validate_type_set_tests.erl
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,14 @@ katt_run_with_set_comparison_strict_fails() ->
, _
, _
, [ {_, _, _, _, {fail, [ { unexpected
, "/body/set_of_objects/{{set}}/0"
}
, { "/body/set_of_objects/{{set}}/0"
, undefined
, {struct, [{"number", 2}]}
}}
]}}
]
}
, katt:run(Scenario)
, katt:run(Scenario) %% ?debugFmt("~p", [katt:run(Scenario)])
).
katt_run_with_set_comparison_unlimited() ->
Scenario = "/mock/set_comparison_unlimited.apib",
Expand All @@ -95,8 +97,10 @@ katt_run_with_set_comparison_unlimited_fails() ->
, _
, _
, [ {_, _, _, _, {fail, [ { not_contains
, "/body/set_of_objects/{{set}}/2"
}
, { "/body/set_of_objects/{{set}}/2"
, {struct, [{"number", 3}]}
, undefined
}}
]}}
]
}
Expand Down
8 changes: 4 additions & 4 deletions test/katt_validate_type_tests.erl
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ pass_when_expected_contained_by_actual_test() ->
))
).
fail_when_expected_contained_by_actual_and_unexpected_test() ->
?assertMatch( [{unexpected, "/2"}]
?assertMatch( [{unexpected, {"/2", undefined, ?OBJECT_3}}]
, filter_errors(compare_as_set( [ {"0", ?OBJECT_1}
, {"1", ?OBJECT_2}
, ?UNEXPECTED_OBJECT
Expand All @@ -149,9 +149,9 @@ fail_when_expected_contained_by_actual_and_unexpected_test() ->
).

fail_with_3_reasons_test() ->
?assertMatch( [ {unexpected, "/0"}
, {unexpected, "/1"}
, {not_contains, "/0"}
?assertMatch( [ {unexpected, {"/0", undefined, ?OBJECT_2}}
, {unexpected, {"/1", undefined, ?OBJECT_3}}
, {not_contains, {"/0", ?OBJECT_1, undefined}}
]
, filter_errors(compare_as_set( [ {"0", ?OBJECT_1}
, ?UNEXPECTED_OBJECT
Expand Down

0 comments on commit 40c2613

Please sign in to comment.