浏览代码

use macro to show where unit tests fail

pull/152/head
Pierre Fenoll 7 年前
父节点
当前提交
40a0ff2996
共有 1 个文件被更改,包括 41 次插入41 次删除
  1. +41
    -41
      test/jiffy_12_error_tests.erl

+ 41
- 41
test/jiffy_12_error_tests.erl 查看文件

@ -6,43 +6,48 @@
-include_lib("eunit/include/eunit.hrl"). -include_lib("eunit/include/eunit.hrl").
-define(ENC_ERROR(Type, Obj, Case),
?_assertEqual({error, {Type, Obj}}, (catch jiffy:encode(Case)))).
enc_invalid_ejson_test_() -> enc_invalid_ejson_test_() ->
Type = invalid_ejson, Type = invalid_ejson,
Ref = make_ref(), Ref = make_ref(),
{"invalid_ejson", [ {"invalid_ejson", [
{"Basic", enc_error(Type, Ref, Ref)},
{"Nested", enc_error(Type, {Ref, Ref}, {Ref, Ref})}
{"the atom 'undefined'", ?ENC_ERROR(Type, undefined, undefined)},
{"Basic", ?ENC_ERROR(Type, Ref, Ref)},
{"Nested", ?ENC_ERROR(Type, {Ref, Ref}, {Ref, Ref})}
]}. ]}.
enc_invalid_string_test_() -> enc_invalid_string_test_() ->
Type = invalid_string, Type = invalid_string,
{"invalid_string", [ {"invalid_string", [
{"Bare strign", enc_error(Type, <<143>>, <<143>>)},
{"List element", enc_error(Type, <<143>>, [<<143>>])},
{"Bad obj value", enc_error(Type, <<143>>, {[{foo, <<143>>}]})}
{"Bare strign", ?ENC_ERROR(Type, <<143>>, <<143>>)},
{"List element", ?ENC_ERROR(Type, <<143>>, [<<143>>])},
{"Bad obj value", ?ENC_ERROR(Type, <<143>>, {[{foo, <<143>>}]})}
]}. ]}.
enc_invalid_object_test_() -> enc_invalid_object_test_() ->
Type = invalid_object, Type = invalid_object,
Ref = make_ref(), Ref = make_ref(),
{"invalid_object", [ {"invalid_object", [
{"Number", enc_error(Type, {1}, {1})},
{"Ref", enc_error(Type, {Ref}, {Ref})},
{"Tuple", enc_error(Type, {{[]}}, {{[]}})},
{"Atom", enc_error(Type, {foo}, {foo})}
{"Number", ?ENC_ERROR(Type, {1}, {1})},
{"Ref", ?ENC_ERROR(Type, {Ref}, {Ref})},
{"Tuple", ?ENC_ERROR(Type, {{[]}}, {{[]}})},
{"Atom", ?ENC_ERROR(Type, {foo}, {foo})}
]}. ]}.
enc_invalid_object_member_test_() -> enc_invalid_object_member_test_() ->
Type = invalid_object_member, Type = invalid_object_member,
{"invalid_object_member", [ {"invalid_object_member", [
{"Basic", enc_error(Type, foo, {[foo]})},
{"Basic", enc_error(Type, foo, {[{bar, baz}, foo]})},
{"Nested", enc_error(Type, foo, {[{bar,{[foo]}}]})},
{"Nested", enc_error(Type, foo, {[{bar,{[{baz, 1}, foo]}}]})},
{"In List", enc_error(Type, foo, [{[foo]}])},
{"In List", enc_error(Type, foo, [{[{bang, true}, foo]}])}
{"Basic", ?ENC_ERROR(Type, foo, {[foo]})},
{"Basic", ?ENC_ERROR(Type, foo, {[{bar, baz}, foo]})},
{"Nested", ?ENC_ERROR(Type, foo, {[{bar,{[foo]}}]})},
{"Nested", ?ENC_ERROR(Type, foo, {[{bar,{[{baz, 1}, foo]}}]})},
{"In List", ?ENC_ERROR(Type, foo, [{[foo]}])},
{"In List", ?ENC_ERROR(Type, foo, [{[{bang, true}, foo]}])}
]}. ]}.
@ -51,18 +56,18 @@ enc_invalid_object_member_arity_test_() ->
E1 = {foo}, E1 = {foo},
E2 = {x, y, z}, E2 = {x, y, z},
{"invalid_object_member", [ {"invalid_object_member", [
{"Basic", enc_error(Type, E1, {[E1]})},
{"Basic", enc_error(Type, E2, {[E2]})},
{"Basic", enc_error(Type, E1, {[{bar, baz}, E1]})},
{"Basic", enc_error(Type, E2, {[{bar, baz}, E2]})},
{"Nested", enc_error(Type, E1, {[{bar,{[E1]}}]})},
{"Nested", enc_error(Type, E2, {[{bar,{[E2]}}]})},
{"Nested", enc_error(Type, E1, {[{bar,{[{baz, 1}, E1]}}]})},
{"Nested", enc_error(Type, E2, {[{bar,{[{baz, 1}, E2]}}]})},
{"In List", enc_error(Type, E1, [{[E1]}])},
{"In List", enc_error(Type, E2, [{[E2]}])},
{"In List", enc_error(Type, E1, [{[{bang, true}, E1]}])},
{"In List", enc_error(Type, E2, [{[{bang, true}, E2]}])}
{"Basic", ?ENC_ERROR(Type, E1, {[E1]})},
{"Basic", ?ENC_ERROR(Type, E2, {[E2]})},
{"Basic", ?ENC_ERROR(Type, E1, {[{bar, baz}, E1]})},
{"Basic", ?ENC_ERROR(Type, E2, {[{bar, baz}, E2]})},
{"Nested", ?ENC_ERROR(Type, E1, {[{bar,{[E1]}}]})},
{"Nested", ?ENC_ERROR(Type, E2, {[{bar,{[E2]}}]})},
{"Nested", ?ENC_ERROR(Type, E1, {[{bar,{[{baz, 1}, E1]}}]})},
{"Nested", ?ENC_ERROR(Type, E2, {[{bar,{[{baz, 1}, E2]}}]})},
{"In List", ?ENC_ERROR(Type, E1, [{[E1]}])},
{"In List", ?ENC_ERROR(Type, E2, [{[E2]}])},
{"In List", ?ENC_ERROR(Type, E1, [{[{bang, true}, E1]}])},
{"In List", ?ENC_ERROR(Type, E2, [{[{bang, true}, E2]}])}
]}. ]}.
@ -70,18 +75,13 @@ enc_invalid_object_member_key_test_() ->
Type = invalid_object_member_key, Type = invalid_object_member_key,
E1 = {1, true}, E1 = {1, true},
{"invalid_object_member_key", [ {"invalid_object_member_key", [
{"Bad string", enc_error(Type, <<143>>, {[{<<143>>, true}]})},
{"Basic", enc_error(Type, 1, {[{1, true}]})},
{"Basic", enc_error(Type, [1], {[{[1], true}]})},
{"Basic", enc_error(Type, {[{foo,bar}]}, {[{{[{foo,bar}]}, true}]})},
{"Second", enc_error(Type, 1, {[{bar, baz}, E1]})},
{"Nested", enc_error(Type, 1, {[{bar,{[E1]}}]})},
{"Nested", enc_error(Type, 1, {[{bar,{[{baz, 1}, E1]}}]})},
{"In List", enc_error(Type, 1, [{[E1]}])},
{"In List", enc_error(Type, 1, [{[{bang, true}, E1]}])}
{"Bad string", ?ENC_ERROR(Type, <<143>>, {[{<<143>>, true}]})},
{"Basic", ?ENC_ERROR(Type, 1, {[{1, true}]})},
{"Basic", ?ENC_ERROR(Type, [1], {[{[1], true}]})},
{"Basic", ?ENC_ERROR(Type, {[{foo,bar}]}, {[{{[{foo,bar}]}, true}]})},
{"Second", ?ENC_ERROR(Type, 1, {[{bar, baz}, E1]})},
{"Nested", ?ENC_ERROR(Type, 1, {[{bar,{[E1]}}]})},
{"Nested", ?ENC_ERROR(Type, 1, {[{bar,{[{baz, 1}, E1]}}]})},
{"In List", ?ENC_ERROR(Type, 1, [{[E1]}])},
{"In List", ?ENC_ERROR(Type, 1, [{[{bang, true}, E1]}])}
]}. ]}.
enc_error(Type, Obj, Case) ->
?_assertEqual({error, {Type, Obj}}, (catch jiffy:encode(Case))).

正在加载...
取消
保存