diff options
author | Erlang/OTP <otp@erlang.org> | 2019-10-04 15:26:59 +0200 |
---|---|---|
committer | Erlang/OTP <otp@erlang.org> | 2019-10-04 15:26:59 +0200 |
commit | 022e03bfd06fdfd4d96cd10a569e12dc60cc2759 (patch) | |
tree | eb245ace05319769add60a9317d331ab8f3ddd5f /lib | |
parent | ba0ff092bc23b71a60e4ca16e827fa3d2d208ce4 (diff) | |
parent | 19697637a41f7e5199f017abae44bac5e7367c57 (diff) | |
download | erlang-022e03bfd06fdfd4d96cd10a569e12dc60cc2759.tar.gz |
Merge branch 'zadean/syntax_tools/add_missing_unwrap/OTP-16012/PR-2348' into maint-20
* zadean/syntax_tools/add_missing_unwrap/OTP-16012/PR-2348:
Update test suite
Also unwrap map_type_* name and value
Add unwrap calls to map_field_* in erl_syntax
# Conflicts:
# lib/syntax_tools/test/syntax_tools_SUITE.erl
Diffstat (limited to 'lib')
-rw-r--r-- | lib/syntax_tools/src/erl_syntax.erl | 48 | ||||
-rw-r--r-- | lib/syntax_tools/test/syntax_tools_SUITE.erl | 38 | ||||
-rw-r--r-- | lib/syntax_tools/test/syntax_tools_SUITE_data/type_specs.erl | 3 |
3 files changed, 64 insertions, 25 deletions
diff --git a/lib/syntax_tools/src/erl_syntax.erl b/lib/syntax_tools/src/erl_syntax.erl index 5bd67b3806..2d451c0657 100644 --- a/lib/syntax_tools/src/erl_syntax.erl +++ b/lib/syntax_tools/src/erl_syntax.erl @@ -2190,11 +2190,11 @@ revert_map_field_assoc(Node) -> -spec map_field_assoc_name(syntaxTree()) -> syntaxTree(). map_field_assoc_name(Node) -> - case Node of + case unwrap(Node) of {map_field_assoc, _, Name, _} -> Name; - _ -> - (data(Node))#map_field_assoc.name + Node1 -> + (data(Node1))#map_field_assoc.name end. @@ -2206,11 +2206,11 @@ map_field_assoc_name(Node) -> -spec map_field_assoc_value(syntaxTree()) -> syntaxTree(). map_field_assoc_value(Node) -> - case Node of + case unwrap(Node) of {map_field_assoc, _, _, Value} -> Value; - _ -> - (data(Node))#map_field_assoc.value + Node1 -> + (data(Node1))#map_field_assoc.value end. @@ -2248,11 +2248,11 @@ revert_map_field_exact(Node) -> -spec map_field_exact_name(syntaxTree()) -> syntaxTree(). map_field_exact_name(Node) -> - case Node of + case unwrap(Node) of {map_field_exact, _, Name, _} -> Name; - _ -> - (data(Node))#map_field_exact.name + Node1 -> + (data(Node1))#map_field_exact.name end. @@ -2264,11 +2264,11 @@ map_field_exact_name(Node) -> -spec map_field_exact_value(syntaxTree()) -> syntaxTree(). map_field_exact_value(Node) -> - case Node of + case unwrap(Node) of {map_field_exact, _, _, Value} -> Value; - _ -> - (data(Node))#map_field_exact.value + Node1 -> + (data(Node1))#map_field_exact.value end. @@ -5335,11 +5335,11 @@ revert_map_type_assoc(Node) -> -spec map_type_assoc_name(syntaxTree()) -> syntaxTree(). map_type_assoc_name(Node) -> - case Node of + case unwrap(Node) of {type, _, map_field_assoc, [Name, _]} -> Name; - _ -> - (data(Node))#map_type_assoc.name + Node1 -> + (data(Node1))#map_type_assoc.name end. @@ -5351,11 +5351,11 @@ map_type_assoc_name(Node) -> -spec map_type_assoc_value(syntaxTree()) -> syntaxTree(). map_type_assoc_value(Node) -> - case Node of + case unwrap(Node) of {type, _, map_field_assoc, [_, Value]} -> Value; - _ -> - (data(Node))#map_type_assoc.value + Node1 -> + (data(Node1))#map_type_assoc.value end. @@ -5393,11 +5393,11 @@ revert_map_type_exact(Node) -> -spec map_type_exact_name(syntaxTree()) -> syntaxTree(). map_type_exact_name(Node) -> - case Node of + case unwrap(Node) of {type, _, map_field_exact, [Name, _]} -> Name; - _ -> - (data(Node))#map_type_exact.name + Node1 -> + (data(Node1))#map_type_exact.name end. @@ -5409,11 +5409,11 @@ map_type_exact_name(Node) -> -spec map_type_exact_value(syntaxTree()) -> syntaxTree(). map_type_exact_value(Node) -> - case Node of + case unwrap(Node) of {type, _, map_field_exact, [_, Value]} -> Value; - _ -> - (data(Node))#map_type_exact.value + Node1 -> + (data(Node1))#map_type_exact.value end. diff --git a/lib/syntax_tools/test/syntax_tools_SUITE.erl b/lib/syntax_tools/test/syntax_tools_SUITE.erl index c8e6448d37..8dc1b18b08 100644 --- a/lib/syntax_tools/test/syntax_tools_SUITE.erl +++ b/lib/syntax_tools/test/syntax_tools_SUITE.erl @@ -24,7 +24,7 @@ %% Test cases -export([app_test/1,appup_test/1,smoke_test/1,revert/1,revert_map/1, - revert_map_type/1, + revert_map_type/1,wrapped_subtrees/1, t_abstract_type/1,t_erl_parse_type/1,t_epp_dodger/1, t_comment_scan/1,t_igor/1,t_erl_tidy/1]). @@ -32,6 +32,7 @@ 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_epp_dodger, t_comment_scan,t_igor,t_erl_tidy]. @@ -143,6 +144,41 @@ revert_map_type(Config) when is_list(Config) -> Form2 = erl_syntax:revert(Mapped2), ?t:timetrap_cancel(Dog). +%% Read with erl_parse, wrap each tree node with erl_syntax and check that +%% erl_syntax:subtrees can access the wrapped node. +wrapped_subtrees(Config) when is_list(Config) -> + Dog = ?t:timetrap(?t:minutes(2)), + Wc = filename:join([code:lib_dir(stdlib),"src","*.erl"]), + Fs = filelib:wildcard(Wc) ++ test_files(Config), + Path = [filename:join(code:lib_dir(stdlib), "include"), + filename:join(code:lib_dir(kernel), "include")], + io:format("~p files\n", [length(Fs)]), + Map = fun (File) -> wrapped_subtrees_file(File, Path) end, + case p_run(Map, Fs) of + 0 -> ok; + N -> ?t:fail({N,errors}) + end, + ?t:timetrap_cancel(Dog). + +wrapped_subtrees_file(File, Path) -> + case epp:parse_file(File, Path, []) of + {ok,Fs0} -> + lists:foreach(fun wrap_each/1, Fs0) + end. + +wrap_each(Tree) -> + % only `wrap` top-level erl_parse node + Tree1 = erl_syntax:set_pos(Tree, erl_syntax:get_pos(Tree)), + % assert ability to access subtrees of wrapped node with erl_syntax:subtrees/1 + case erl_syntax:subtrees(Tree1) of + [] -> ok; + List -> + GrpsF = fun(Group) -> + lists:foreach(fun wrap_each/1, Group) + end, + lists:foreach(GrpsF, List) + end. + %% api tests t_abstract_type(Config) when is_list(Config) -> diff --git a/lib/syntax_tools/test/syntax_tools_SUITE_data/type_specs.erl b/lib/syntax_tools/test/syntax_tools_SUITE_data/type_specs.erl index e4f8a1c3de..b23acdb39e 100644 --- a/lib/syntax_tools/test/syntax_tools_SUITE_data/type_specs.erl +++ b/lib/syntax_tools/test/syntax_tools_SUITE_data/type_specs.erl @@ -37,6 +37,9 @@ -record(par, {a :: undefined | ?MODULE}). +-record(mt, {e :: #{any() := any()}, + a :: #{any() => any()}}). + -record(r0, {}). -record(r, |