Skip to content

Commit

Permalink
add mime_to_exts function to generated module
Browse files Browse the repository at this point in the history
  • Loading branch information
beapirate committed Sep 9, 2011
1 parent bafdf35 commit c006ad8
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/mimetypes.erl
Expand Up @@ -250,7 +250,10 @@ ext_to_mimes_clauses(Pairs) ->
%% @private Generate a set of mime_to_exts clauses.
-spec mime_to_exts_clauses([{binary(), binary()}]) -> [erl_syntax:syntaxTree()].
mime_to_exts_clauses(Pairs) ->
[].
Types = lists:usort([T || {T,_} <- Pairs]),
Groups = [{T, lists:usort([E || {U,E} <- Pairs, U =:= T])} || T <- Types],
[erl_syntax:clause([erl_syntax:abstract(T)], none, [erl_syntax:abstract(Es)])
|| {T, Es} <- Groups].


%% @private Compile and load a module.
Expand Down Expand Up @@ -282,6 +285,7 @@ codegen_test() ->
AbsCode = map_to_abstract(mimetypes_map, [{<<"a">>, <<"b">>}]),
ok = compile_and_load_forms(AbsCode, []),
mimetypes_map:module_info(),
?assertEqual([<<"a">>], mimetypes_map:ext_to_mimes(<<"b">>)).
?assertEqual([<<"a">>], mimetypes_map:ext_to_mimes(<<"b">>)),
?assertEqual([<<"b">>], mimetypes_map:mime_to_exts(<<"a">>)).

-endif.

0 comments on commit c006ad8

Please sign in to comment.