forked from radiospiel/eep0018
/
issue_001.erl
39 lines (34 loc) · 1.8 KB
/
issue_001.erl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
-module(issue_001).
-include_lib("eunit/include/eunit.hrl").
issue_001_test_() ->
[
% reported cases.
% This calls returns a proper result:
?_assertEqual(
{ok, {[ {<<"algorithm">>, <<"HMAC-SHA256">>}, {<<"credits">>, {[ {<<"buyer">>, 100000000000000} ]} } ]} },
json:decode(<<"{\"algorithm\":\"HMAC-SHA256\",\"credits\":{\"buyer\":100000000000000}}">>)
),
?_assertEqual(
{ok, {[ {<<"algorithm">>, <<"HMAC-SHA256">>}, {<<"credits">>, {[ {<<"buyer">>, 1000000000}, {<<"receiver">>, 100000000} ]} } ]} },
json:decode(<<"{\"algorithm\":\"HMAC-SHA256\",\"credits\":{\"buyer\":1000000000, \"receiver\":100000000}}">>)
),
?_assertEqual(
{ok, {[ {<<"algorithm">>, <<"HMAC-SHA256">>}, {<<"credits">>, {[ {<<"buyer">>, 1000000000}, {<<"receiver">>,10000000000000000000000} ]} } ]} },
json:decode(<<"{\"algorithm\":\"HMAC-SHA256\",\"credits\":{\"buyer\":1000000000, \"receiver\":10000000000000000000000}}">>)
),
% But this one returns an {error,{69,invalid_internal_no_key_set}}:
?_assertEqual(
{ok, {[ {<<"algorithm">>, <<"HMAC-SHA256">>}, {<<"credits">>, {[ {<<"buyer">>, 10000000000}, {<<"receiver">>, 100000000} ]} } ]} },
json:decode(<<"{\"algorithm\":\"HMAC-SHA256\",\"credits\":{\"buyer\":10000000000, \"receiver\":100000000}}">>)
),
% simple case.
?_assertEqual(
{ok, {[{<<"x">>, 123456789012345678901234567890}, {<<"y">>, 0}]}},
json:decode(<<"{\"x\":123456789012345678901234567890,\"y\":0}">>)
),
?_assertEqual(
{ok, {[{<<"a">>, 113456789012345678901234567890}, {<<"b">>,{[{<<"x">>, 123456789012345678901234567890}, {<<"y">>, 20}]}}, {<<"c">>, 30}]} },
json:decode(<<"{\"a\":113456789012345678901234567890,\"b\":{\"x\":123456789012345678901234567890,\"y\":20},\"c\":30}">>)
),
?_assert(true)
].