diff options
Diffstat (limited to 'lib/syntax_tools/test')
-rw-r--r-- | lib/syntax_tools/test/merl_SUITE.erl | 14 | ||||
-rw-r--r-- | lib/syntax_tools/test/syntax_tools_SUITE.erl | 80 |
2 files changed, 90 insertions, 4 deletions
diff --git a/lib/syntax_tools/test/merl_SUITE.erl b/lib/syntax_tools/test/merl_SUITE.erl index 52bbd9b3b8..6389ad7738 100644 --- a/lib/syntax_tools/test/merl_SUITE.erl +++ b/lib/syntax_tools/test/merl_SUITE.erl @@ -30,13 +30,14 @@ %% Test cases -export([merl_smoke_test/1, - transform_parse_error_test/1]). + transform_parse_error_test/1, otp_15291/1]). suite() -> [{ct_hooks,[ts_install_cth]}]. all() -> [merl_smoke_test, - transform_parse_error_test]. + transform_parse_error_test, + otp_15291]. groups() -> []. @@ -101,6 +102,15 @@ transform_parse_error_test(_Config) -> [?Q("merl:qquote(2, \"{\", [{var, V}])")], []))), ok. +otp_15291(_Config) -> + C0 = merl:quote("() -> ok"), + {clause,1,[],[],[{atom,1,ok}]} = C0, + C2 = merl:quote("(_,_) -> ok"), + {clause,1,[{var,1,'_'},{var,1,'_'}],[],[{atom,1,ok}]} = C2, + C1 = merl:quote("(_) -> ok"), + {clause,1,[{var,1,'_'}],[],[{atom,1,ok}]} = C1, + ok. + %% utilities f(Ts) when is_list(Ts) -> diff --git a/lib/syntax_tools/test/syntax_tools_SUITE.erl b/lib/syntax_tools/test/syntax_tools_SUITE.erl index c8e6448d37..9dbd0e302a 100644 --- a/lib/syntax_tools/test/syntax_tools_SUITE.erl +++ b/lib/syntax_tools/test/syntax_tools_SUITE.erl @@ -25,14 +25,14 @@ %% Test cases -export([app_test/1,appup_test/1,smoke_test/1,revert/1,revert_map/1, revert_map_type/1, - t_abstract_type/1,t_erl_parse_type/1,t_epp_dodger/1, + t_abstract_type/1,t_erl_parse_type/1,t_type/1, t_epp_dodger/1, t_comment_scan/1,t_igor/1,t_erl_tidy/1]). suite() -> [{ct_hooks,[ts_install_cth]}]. all() -> [app_test,appup_test,smoke_test,revert,revert_map,revert_map_type, - t_abstract_type,t_erl_parse_type,t_epp_dodger, + t_abstract_type,t_erl_parse_type,t_type,t_epp_dodger, t_comment_scan,t_igor,t_erl_tidy]. groups() -> @@ -145,6 +145,74 @@ revert_map_type(Config) when is_list(Config) -> %% api tests +t_type(Config) when is_list(Config) -> + F0 = fun validate_basic_type/1, + Appl0 = fun(Name) -> + Atom = erl_syntax:atom(Name), + erl_syntax:type_application(none, Atom, []) + end, + User0 = fun(Name) -> + Atom = erl_syntax:atom(Name), + erl_syntax:user_type_application(Atom, []) + end, + ok = validate(F0,[{"tuple()", erl_syntax:tuple_type()} + ,{"{}", erl_syntax:tuple_type([])} + ,{"integer()", Appl0(integer)} + ,{"foo()", User0(foo)} + ,{"map()", erl_syntax:map_type()} + ,{"#{}", erl_syntax:map_type([])} + ,{"1..2", erl_syntax:integer_range_type + (erl_syntax:integer(1), erl_syntax:integer(2))} + ,{"<<_:1,_:_*2>>", erl_syntax:bitstring_type + (erl_syntax:integer(1), erl_syntax:integer(2))} + ,{"fun()", erl_syntax:fun_type()} + ]), + + F = fun validate_type/1, + ok = validate(F,[{"{}", tuple_type, false} + ,{"tuple()", tuple_type, true} + ,{"{atom()}", tuple_type, false} + ,{"{atom(),integer()}", tuple_type, false} + ,{"integer()", type_application, false} + ,{"foo()", user_type_application, false} + ,{"foo(integer())", user_type_application, false} + ,{"module:function()", type_application, false} + ,{"map()", map_type, true} + ,{"#{}", map_type, false} + ,{"#{atom() => integer()}", map_type, false} + ,{"#{atom() := integer()}", map_type, false} + ,{"#r{}", record_type, false} + ,{"#r{a :: integer()}", record_type, false} + ,{"[]", type_application, false} + ,{"nil()", type_application, false} + ,{"[atom()]", type_application, false} + ,{"1..2", integer_range_type, false} + ,{"<<_:1,_:_*2>>", bitstring_type, false} + ,{"fun()", fun_type, true} + ,{"integer() | atom()", type_union, false} + ,{"A :: fun()", annotated_type, false} + ,{"fun((...) -> atom())", function_type, false} + ,{"fun((integer()) -> atom())", function_type, false} + ,{"V", variable, true} + ]), + ok. + +validate_basic_type({String, Tree}) -> + ErlT = string_to_type(String), + ErlT = erl_syntax:revert(Tree), + ok. + +validate_type({String, Type, Leaf}) -> + ErlT = string_to_type(String), + Type = erl_syntax:type(ErlT), + Leaf = erl_syntax:is_leaf(ErlT), + Tree = erl_syntax_lib:map(fun(Node) -> Node end, ErlT), + Type = erl_syntax:type(Tree), + _ = erl_syntax:meta(Tree), + RevT = erl_syntax:revert(Tree), + Type = erl_syntax:type(RevT), + ok. + t_abstract_type(Config) when is_list(Config) -> F = fun validate_abstract_type/1, ok = validate(F,[{hi,atom}, @@ -157,6 +225,7 @@ t_abstract_type(Config) when is_list(Config) -> {[$a,$b,$c],string}, {"hello world",string}, {<<1,2,3>>,binary}, + {<<1,2,3:4>>,binary}, {#{a=>1,"b"=>2},map_expr}, {#{#{i=>1}=>1,"b"=>#{v=>2}},map_expr}, {{a,b,c},tuple}]), @@ -450,6 +519,13 @@ string_to_expr(String) -> {ok,[Expr]} = erl_parse:parse_exprs(Ts), Expr. +string_to_type(String) -> + io:format("Str: ~p~n", [String]), + {ok,Ts,_} = erl_scan:string("-type foo() :: "++String++".", 0), + {ok,Form} = erl_parse:parse_form(Ts), + {attribute,_,type,{foo,Type,_NoParms=[]}} = Form, + Type. + p_run(Test, List) -> N = erlang:system_info(schedulers), |