diff options
author | Björn-Egil Dahlberg <[email protected]> | 2014-10-24 18:49:01 +0200 |
---|---|---|
committer | Björn-Egil Dahlberg <[email protected]> | 2014-10-24 18:49:01 +0200 |
commit | 6e245477da37b82056b41d6d2b6fe08e8407bd72 (patch) | |
tree | 2c2f3fcd72336dd641ddfa4b09d20a260c965650 /lib/syntax_tools/test/syntax_tools_SUITE.erl | |
parent | ac264cba1435bf84eecc6b31809bd996c4c8e9c0 (diff) | |
download | otp-6e245477da37b82056b41d6d2b6fe08e8407bd72.tar.gz otp-6e245477da37b82056b41d6d2b6fe08e8407bd72.tar.bz2 otp-6e245477da37b82056b41d6d2b6fe08e8407bd72.zip |
syntax_tools: Strengthen erl_syntax comments tests
Comments in the syntax tree.
Tested via t_epp_dodger.
Diffstat (limited to 'lib/syntax_tools/test/syntax_tools_SUITE.erl')
-rw-r--r-- | lib/syntax_tools/test/syntax_tools_SUITE.erl | 28 |
1 files changed, 25 insertions, 3 deletions
diff --git a/lib/syntax_tools/test/syntax_tools_SUITE.erl b/lib/syntax_tools/test/syntax_tools_SUITE.erl index 721d1fd87c..30e5e7b713 100644 --- a/lib/syntax_tools/test/syntax_tools_SUITE.erl +++ b/lib/syntax_tools/test/syntax_tools_SUITE.erl @@ -237,9 +237,31 @@ pretty_print_parse_forms([{Fs0,Type}|FsForms],PrivDir,Filename) -> Parser = atom_to_list(Type), OutFile = filename:join(PrivDir, Parser ++"_" ++ Filename), io:format("Pretty print ~p (~w) to ~p~n", [Filename,Type,OutFile]), - Fs1 = erl_syntax:form_list(Fs0), - PP = erl_prettypr:format(Fs1), - ok = file:write_file(OutFile,iolist_to_binary(PP)), + Comment = fun (Node,{CntCase,CntTry}=Cnt) -> + case erl_syntax:type(Node) of + case_expr -> + C1 = erl_syntax:comment(2,["Before a case expression"]), + Node1 = erl_syntax:add_precomments([C1],Node), + C2 = erl_syntax:comment(2,["After a case expression"]), + Node2 = erl_syntax:add_postcomments([C2],Node1), + {Node2,{CntCase+1,CntTry}}; + try_expr -> + C1 = erl_syntax:comment(2,["Before a try expression"]), + Node1 = erl_syntax:set_precomments(Node, + erl_syntax:get_precomments(Node) ++ [C1]), + C2 = erl_syntax:comment(2,["After a try expression"]), + Node2 = erl_syntax:set_postcomments(Node1, + erl_syntax:get_postcomments(Node1) ++ [C2]), + {Node2,{CntCase,CntTry+1}}; + _ -> + {Node,Cnt} + end + end, + Fs1 = erl_syntax:form_list(Fs0), + {Fs2,{CC,CT}} = erl_syntax_lib:mapfold(Comment,{0,0}, Fs1), + io:format("Commented on ~w cases and ~w tries~n", [CC,CT]), + PP = erl_prettypr:format(Fs2), + ok = file:write_file(OutFile,iolist_to_binary(PP)), pretty_print_parse_forms(FsForms,PrivDir,Filename). |