You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

61 rivejä
1.4 KiB

  1. % This file is part of Jiffy released under the MIT license.
  2. % See the LICENSE file for more information.
  3. -module(jiffy_07_compound_tests).
  4. -include_lib("proper/include/proper.hrl").
  5. -include_lib("eunit/include/eunit.hrl").
  6. -include("jiffy_util.hrl").
  7. compound_success_test_() ->
  8. [gen(ok, Case) || Case <- cases(ok)].
  9. compound_failure_test_() ->
  10. [gen(error, Case) || Case <- cases(error)].
  11. gen(ok, {J, E}) ->
  12. gen(ok, {J, E, J});
  13. gen(ok, {J1, E, J2}) ->
  14. {msg("~s", [J1]), [
  15. {"Decode", ?_assertEqual(E, dec(J1))},
  16. {"Encode", ?_assertEqual(J2, enc(E))}
  17. ]};
  18. gen(error, J) ->
  19. {msg("Error: ~s", [J]), [
  20. ?_assertThrow({error, _}, dec(J))
  21. ]}.
  22. cases(ok) ->
  23. [
  24. {<<"[{}]">>, [{[]}]},
  25. {<<"{\"foo\":[123]}">>, {[{<<"foo">>, [123]}]}},
  26. {<<"{\"foo\":{\"bar\":true}}">>,
  27. {[{<<"foo">>, {[{<<"bar">>, true}]} }]} },
  28. {<<"{\"foo\":[],\"bar\":{\"baz\":true},\"alice\":\"bob\"}">>,
  29. {[
  30. {<<"foo">>, []},
  31. {<<"bar">>, {[{<<"baz">>, true}]}},
  32. {<<"alice">>, <<"bob">>}
  33. ]}
  34. },
  35. {<<"[-123,\"foo\",{\"bar\":[]},null]">>,
  36. [
  37. -123,
  38. <<"foo">>,
  39. {[{<<"bar">>, []}]},
  40. null
  41. ]
  42. }
  43. ];
  44. cases(error) ->
  45. [
  46. <<"[{}">>,
  47. <<"}]">>
  48. ].