Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
home:Ledest:erlang:19
erlang
1256-stdlib-Fix-erl_pp-rendering-unary-operator...
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File 1256-stdlib-Fix-erl_pp-rendering-unary-operators.patch of Package erlang
From 595adb64575aa69829a5be1a97b0e182df21f8fb Mon Sep 17 00:00:00 2001 From: Wojtek Mach <wojtek@wojtekmach.pl> Date: Thu, 5 Aug 2021 13:49:09 +0200 Subject: [PATCH] stdlib: Fix `erl_pp` rendering unary +/- operators --- lib/stdlib/src/erl_pp.erl | 6 ++++++ lib/stdlib/test/erl_pp_SUITE.erl | 26 +++++++++++++++++++++++--- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/lib/stdlib/src/erl_pp.erl b/lib/stdlib/src/erl_pp.erl index 9a0884fdba..d704d097c8 100644 --- a/lib/stdlib/src/erl_pp.erl +++ b/lib/stdlib/src/erl_pp.erl @@ -643,6 +643,12 @@ lexpr({match,_,Lhs,Rhs}, Prec, Opts) -> Rl = lexpr(Rhs, R, Opts), El = {list,[{cstep,[Pl,' ='],Rl}]}, maybe_paren(P, Prec, El); +lexpr({op,_,Op,Arg}, Prec, Opts) when Op =:= '+'; + Op =:= '-' -> + {P,R} = preop_prec(Op), + Ol = {reserved, leaf(atom_to_list(Op))}, + El = [Ol,lexpr(Arg, R, Opts)], + maybe_paren(P, Prec, El); lexpr({op,_,Op,Arg}, Prec, Opts) -> {P,R} = preop_prec(Op), Ol = leaf(format("~s ", [Op])), diff --git a/lib/stdlib/test/erl_pp_SUITE.erl b/lib/stdlib/test/erl_pp_SUITE.erl index ad49321aaa..b740ead730 100644 --- a/lib/stdlib/test/erl_pp_SUITE.erl +++ b/lib/stdlib/test/erl_pp_SUITE.erl @@ -51,7 +51,8 @@ otp_6321/1, otp_6911/1, otp_6914/1, otp_8150/1, otp_8238/1, otp_8473/1, otp_8522/1, otp_8567/1, otp_8664/1, otp_9147/1, otp_10302/1, otp_10820/1, otp_11100/1, otp_11861/1, pr_1014/1, - otp_13662/1]). + otp_13662/1, + gh_5093/1]). %% Internal export. -export([ehook/6]). @@ -81,7 +82,8 @@ groups() -> {tickets, [], [otp_6321, otp_6911, otp_6914, otp_8150, otp_8238, otp_8473, otp_8522, otp_8567, otp_8664, otp_9147, - otp_10302, otp_10820, otp_11100, otp_11861, pr_1014, otp_13662]}]. + otp_10302, otp_10820, otp_11100, otp_11861, pr_1014, otp_13662, + gh_5093]}]. init_per_suite(Config) -> Config. @@ -1205,6 +1207,18 @@ otp_16435(_Config) -> ], compile(Config, Ts). +gh_5093(_Config) -> + assert_same("f() ->\n -1.\n"), + assert_same("f() ->\n +1.\n"), + assert_same("f() ->\n +1.1.\n"), + assert_same("f() ->\n +(+1).\n"), + assert_same("f(X) ->\n -X.\n"), + assert_same("f(X) ->\n +X.\n"), + assert_same("f(X, Y) ->\n X + Y.\n"), + assert_same("f(X, Y) ->\n X + +Y.\n"), + assert_same("f(X, Y) ->\n X - Y.\n"), + ok. + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% compile(Config, Tests) -> @@ -1385,3 +1399,10 @@ fail() -> start_node(Name, Xargs) -> PA = filename:dirname(code:which(?MODULE)), test_server:start_node(Name, peer, [{args, "-pa " ++ PA ++ " " ++ Xargs}]). + +assert_same(Expected) when is_list(Expected) -> + Actual = binary_to_list(iolist_to_binary(parse_and_pp_forms(Expected, []))), + case Expected == Actual of + true -> ok; + false -> error({Expected, Actual}) + end. -- 2.31.1
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor