./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 376 jiffy:encode(fixup(Term)).
7
8 %% Ground types
9 142 fixup(Term) when is_number(Term) -> Term;
10 1720 fixup(Term) when is_atom(Term) -> Term;
11 2680 fixup(Term) when is_binary(Term) -> Term;
12 %% Compound types
13 fixup(Term) when is_list(Term) ->
14 370 [fixup(T) || T <- Term];
15 fixup(Term) when is_map(Term) ->
16 1642 KVs = maps:to_list(Term),
17 1642 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 34 iolist_to_binary(
21 io_lib:format("~p", [Term])).
22
23 fixup_key(Term) ->
24 2798 case fixup(Term) of
25 T when is_binary(T) ->
26 1536 T;
27 T ->
28 1262 iolist_to_binary(io_lib:format("~p", [T]))
29 end.
30
Line Hits Source