coerce character
It's really just an integer... Should we flatten it to an integer instead? I don't know.
This commit is contained in:
parent
d3fb598506
commit
68a0c3d623
13
src/hz.erl
13
src/hz.erl
@ -1541,7 +1541,7 @@ opaque_type(Params, Pair) when is_map(Pair) ->
|
|||||||
opaque_type_name(<<"int">>) -> integer;
|
opaque_type_name(<<"int">>) -> integer;
|
||||||
opaque_type_name(<<"bool">>) -> boolean;
|
opaque_type_name(<<"bool">>) -> boolean;
|
||||||
opaque_type_name(<<"bits">>) -> bits;
|
opaque_type_name(<<"bits">>) -> bits;
|
||||||
opaque_type_name(<<"char">>) -> integer;
|
opaque_type_name(<<"char">>) -> char;
|
||||||
opaque_type_name(<<"string">>) -> string;
|
opaque_type_name(<<"string">>) -> string;
|
||||||
opaque_type_name(<<"address">>) -> address;
|
opaque_type_name(<<"address">>) -> address;
|
||||||
opaque_type_name(<<"hash">>) -> hash;
|
opaque_type_name(<<"hash">>) -> hash;
|
||||||
@ -1848,6 +1848,8 @@ coerce({O, N, string}, Str, Direction) ->
|
|||||||
StrBin ->
|
StrBin ->
|
||||||
{ok, StrBin}
|
{ok, StrBin}
|
||||||
end;
|
end;
|
||||||
|
coerce({_, _, char}, Val, _Direction) when is_integer(Val) ->
|
||||||
|
{ok, Val};
|
||||||
coerce({O, N, {bytes, [Count]}}, Bytes, _Direction) when is_bitstring(Bytes) ->
|
coerce({O, N, {bytes, [Count]}}, Bytes, _Direction) when is_bitstring(Bytes) ->
|
||||||
coerce_bytes(O, N, Count, Bytes);
|
coerce_bytes(O, N, Count, Bytes);
|
||||||
coerce({_, _, bits}, {bits, Num}, from_fate) ->
|
coerce({_, _, bits}, {bits, Num}, from_fate) ->
|
||||||
@ -2536,10 +2538,14 @@ coerce_bytes_test() ->
|
|||||||
{ok, Type} = annotate_type({tuple, [{bytes, [4]}, {bytes, [any]}]}, #{}),
|
{ok, Type} = annotate_type({tuple, [{bytes, [4]}, {bytes, [any]}]}, #{}),
|
||||||
try_coerce(Type, {<<"abcd">>, <<"efghi">>}, {tuple, {<<"abcd">>, <<"efghi">>}}).
|
try_coerce(Type, {<<"abcd">>, <<"efghi">>}, {tuple, {<<"abcd">>, <<"efghi">>}}).
|
||||||
|
|
||||||
bits_test() ->
|
coerce_bits_test() ->
|
||||||
{ok, Type} = annotate_type(bits, #{}),
|
{ok, Type} = annotate_type(bits, #{}),
|
||||||
try_coerce(Type, 5, {bits, 5}).
|
try_coerce(Type, 5, {bits, 5}).
|
||||||
|
|
||||||
|
coerce_char_test() ->
|
||||||
|
{ok, Type} = annotate_type(char, #{}),
|
||||||
|
try_coerce(Type, $?, $?).
|
||||||
|
|
||||||
|
|
||||||
%%% Complex AACI paramter and namespace tests
|
%%% Complex AACI paramter and namespace tests
|
||||||
|
|
||||||
@ -2635,6 +2641,7 @@ obscure_aaci_test() ->
|
|||||||
entrypoint fixed_bytes(): bytes(4) = #DEADBEEF
|
entrypoint fixed_bytes(): bytes(4) = #DEADBEEF
|
||||||
entrypoint any_bytes(): bytes() = Bytes.to_any_size(#112233)
|
entrypoint any_bytes(): bytes() = Bytes.to_any_size(#112233)
|
||||||
entrypoint bits(): bits = Bits.all
|
entrypoint bits(): bits = Bits.all
|
||||||
|
entrypoint character(): char = 'a'
|
||||||
",
|
",
|
||||||
{ok, AACI} = aaci_from_string(Contract),
|
{ok, AACI} = aaci_from_string(Contract),
|
||||||
|
|
||||||
@ -2648,5 +2655,7 @@ obscure_aaci_test() ->
|
|||||||
|
|
||||||
{ok, {[], {_, _, bits}}} = aaci_lookup_spec(AACI, "bits"),
|
{ok, {[], {_, _, bits}}} = aaci_lookup_spec(AACI, "bits"),
|
||||||
|
|
||||||
|
{ok, {[], {_, _, char}}} = aaci_lookup_spec(AACI, "character"),
|
||||||
|
|
||||||
ok.
|
ok.
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user