./ct_report/coverage/mongoose_graphql_cowboy_response.COVER.html

1 -module(mongoose_graphql_cowboy_response).
2
3 -export([term_to_json/1]).
4
5 term_to_json(Term) ->
6 134 jiffy:encode(fixup(Term)).
7
8 %% Ground types
9 11 fixup(Term) when is_number(Term) -> Term;
10 625 fixup(Term) when is_atom(Term) -> Term;
11 727 fixup(Term) when is_binary(Term) -> Term;
12 %% Compound types
13 fixup(Term) when is_list(Term) ->
14 147 [fixup(T) || T <- Term];
15 fixup(Term) when is_map(Term) ->
16 565 KVs = maps:to_list(Term),
17 565 maps:from_list([{fixup_key(K), fixup(V)} || {K, V} <- KVs]);
18 fixup(Term) ->
19 %% Every other term is transformed into a binary value
20 26 iolist_to_binary(
21 io_lib:format("~p", [Term])).
22
23 fixup_key(Term) ->
24 880 case fixup(Term) of
25 T when is_binary(T) ->
26 376 T;
27 T ->
28 504 iolist_to_binary(io_lib:format("~p", [T]))
29 end.
30
Line Hits Source