./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 198 jiffy:encode(fixup(Term)).
7
8 %% Ground types
9 26 fixup(Term) when is_number(Term) -> Term;
10 829 fixup(Term) when is_atom(Term) -> Term;
11 1131 fixup(Term) when is_binary(Term) -> Term;
12 %% Compound types
13 fixup(Term) when is_list(Term) ->
14 202 [fixup(T) || T <- Term];
15 fixup(Term) when is_map(Term) ->
16 850 KVs = maps:to_list(Term),
17 850 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 30 iolist_to_binary(
21 io_lib:format("~p", [Term])).
22
23 fixup_key(Term) ->
24 1295 case fixup(Term) of
25 T when is_binary(T) ->
26 628 T;
27 T ->
28 667 iolist_to_binary(io_lib:format("~p", [T]))
29 end.
30
Line Hits Source