diff options
Diffstat (limited to 'lib/syntax_tools/test')
3 files changed, 60 insertions, 5 deletions
diff --git a/lib/syntax_tools/test/syntax_tools_SUITE.erl b/lib/syntax_tools/test/syntax_tools_SUITE.erl index 9baf36ce11..14a7912642 100644 --- a/lib/syntax_tools/test/syntax_tools_SUITE.erl +++ b/lib/syntax_tools/test/syntax_tools_SUITE.erl @@ -25,7 +25,8 @@ %% Test cases -export([app_test/1,appup_test/1,smoke_test/1,revert/1,revert_map/1, revert_map_type/1,wrapped_subtrees/1, - t_abstract_type/1,t_erl_parse_type/1,t_type/1, t_epp_dodger/1, + t_abstract_type/1,t_erl_parse_type/1,t_type/1, + t_epp_dodger/1,t_epp_dodger_clever/1, t_comment_scan/1,t_igor/1,t_erl_tidy/1,t_prettypr/1]). suite() -> [{ct_hooks,[ts_install_cth]}]. @@ -33,7 +34,8 @@ suite() -> [{ct_hooks,[ts_install_cth]}]. all() -> [app_test,appup_test,smoke_test,revert,revert_map,revert_map_type, wrapped_subtrees, - t_abstract_type,t_erl_parse_type,t_type,t_epp_dodger, + t_abstract_type,t_erl_parse_type,t_type, + t_epp_dodger,t_epp_dodger_clever, t_comment_scan,t_igor,t_erl_tidy,t_prettypr]. groups() -> @@ -330,6 +332,13 @@ t_epp_dodger(Config) when is_list(Config) -> ok = test_epp_dodger(Filenames,DataDir,PrivDir), ok. +t_epp_dodger_clever(Config) when is_list(Config) -> + DataDir = ?config(data_dir, Config), + PrivDir = ?config(priv_dir, Config), + Filenames = ["epp_dodger_clever.erl"], + ok = test_epp_dodger_clever(Filenames,DataDir,PrivDir), + ok. + t_comment_scan(Config) when is_list(Config) -> DataDir = ?config(data_dir, Config), Filenames = test_files(), @@ -447,9 +456,30 @@ test_epp_dodger([Filename|Files],DataDir,PrivDir) -> ok = pretty_print_parse_forms(FsForms,PrivDir,Filename), test_epp_dodger(Files,DataDir,PrivDir). +test_epp_dodger_clever([], _, _) -> ok; +test_epp_dodger_clever([Filename|Files],DataDir,PrivDir) -> + io:format("Parsing ~p~n", [Filename]), + InFile = filename:join(DataDir, Filename), + Parsers = [{fun(File) -> + epp_dodger:parse_file(File, [clever]) + end, parse_file}, + {fun(File) -> + epp_dodger:quick_parse_file(File, [clever]) + end, quick_parse_file}], + FsForms = parse_with(Parsers, InFile), + ok = pretty_print_parse_forms(FsForms,PrivDir,Filename), + test_epp_dodger_clever(Files,DataDir,PrivDir). + parse_with([],_) -> []; parse_with([{Fun,ParserType}|Funs],File) -> {ok, Fs} = Fun(File), + ErrorMarkers = [begin + print_error_markers(F, File), + F + end + || F <- Fs, + erl_syntax:type(F) =:= error_marker], + [] = ErrorMarkers, [{Fs,ParserType}|parse_with(Funs,File)]. pretty_print_parse_forms([],_,_) -> ok; diff --git a/lib/syntax_tools/test/syntax_tools_SUITE_data/epp_dodger_clever.erl b/lib/syntax_tools/test/syntax_tools_SUITE_data/epp_dodger_clever.erl new file mode 100644 index 0000000000..4a3be06d98 --- /dev/null +++ b/lib/syntax_tools/test/syntax_tools_SUITE_data/epp_dodger_clever.erl @@ -0,0 +1,12 @@ +-module(epp_dodger_clever). + +-export([foo1/0]). + +-define(macro_string, "hello world"). + +foo1() -> + % string combining ? + [?macro_string + "hello world ", + "more hello" + ?macro_string]. diff --git a/lib/syntax_tools/test/syntax_tools_SUITE_data/syntax_tools_test.erl b/lib/syntax_tools/test/syntax_tools_SUITE_data/syntax_tools_test.erl index dd3f88d7a8..b8a21ef0ab 100644 --- a/lib/syntax_tools/test/syntax_tools_SUITE_data/syntax_tools_test.erl +++ b/lib/syntax_tools/test/syntax_tools_SUITE_data/syntax_tools_test.erl @@ -6,7 +6,7 @@ -module(syntax_tools_test). --export([foo1/0,foo2/2,foo3/0,foo4/3,foo5/1]). +-export([foo1/0,foo2/2,foo3/0,foo4/3,foo5/1,foo6/2]). -include_lib("kernel/include/file.hrl"). -record(state, { a, b, c, d}). @@ -24,6 +24,7 @@ -define(macro_string, "hello world"). -define(macro_argument1(X), (X + 3)). -define(macro_argument2(X,Y), (X + 3 * Y)). +-define(macro_argument3(X), {error, X}). -define(macro_block(X), begin X end). -define(macro_if(X1,X2), if X1 -> X2; true -> none end). @@ -48,8 +49,7 @@ foo1() -> %% macro test foo2(A,B) -> % string combining ? - [?macro_string, ?macro_string - ?macro_string, + [?macro_string, ?macro_string ++ "hello world " "more hello", [?macro_simple1, @@ -113,3 +113,16 @@ foo5(A) -> error:?macro_simple5 -> nope end. + +%% macros in patterns +foo6(?MACRO_SIMPLE2, ?macro_argument3(A)) -> + try foo2(A,A) of + R -> R + catch + ?macro_argument3(B) -> + B; + error:?macro_argument3(B) -> + B; + error:?macro_argument3(B):_ -> + B + end. |