From d684e734d43ba704f333ccefdf714e3754702415 Mon Sep 17 00:00:00 2001 From: Steve Hancock Date: Sat, 23 Nov 2024 07:31:32 -0800 Subject: [PATCH] fix c424, lost space with -qwaf -naws and '\ )' --- lib/Perl/Tidy/Formatter.pm | 19 +++++++++++++++---- t/snippets/c424.in | 2 ++ t/snippets/c424.par | 1 + t/snippets/expect/c424.c424 | 2 ++ t/snippets/expect/c424.def | 2 ++ t/snippets/packing_list.txt | 10 ++++++---- t/snippets31.t | 26 ++++++++++++++++++++++++++ 7 files changed, 54 insertions(+), 8 deletions(-) create mode 100644 t/snippets/c424.in create mode 100644 t/snippets/c424.par create mode 100644 t/snippets/expect/c424.c424 create mode 100644 t/snippets/expect/c424.def diff --git a/lib/Perl/Tidy/Formatter.pm b/lib/Perl/Tidy/Formatter.pm index 8482d196..85e588b1 100644 --- a/lib/Perl/Tidy/Formatter.pm +++ b/lib/Perl/Tidy/Formatter.pm @@ -7452,21 +7452,26 @@ EOM return; } - # c414: do not join a '\' and a closing ')' for example like here: + # c414 and c424: do not join a '\' and a closing ')' like here: # my @clock_chars = qw( | / - \ | / - \ ); if ( @words && $closing && substr( $words[-1], -1, 1 ) eq BACKSLASH - && ( $tightness{')'} == 2 - || $tightness{')'} == 1 && @words == 1 ) + && ( + !$rOpts_add_whitespace + || ( $tightness{')'} == 2 + || $tightness{')'} == 1 && @words == 1 ) + ) ) { # fix by including a space after the \ $words[-1] .= SPACE; # and for symmetry, before the first word if the '(' is on this line - if ($opening) { $words[0] = SPACE . $words[0] } + if ( $opening && $rOpts_add_whitespace ) { + $words[0] = SPACE . $words[0]; + } } #--------------------------------------------------------------------- @@ -38520,6 +38525,12 @@ sub make_paren_name { # indentation of a line in the Formatter. #-------------------------------------------------------------- + # Given: + # ($ibeg, $iend) = index range of tokens on this line + # $rindentation_list = ref to indentation of each line in this batch, + # to be updated by this sub + # $level_jump = level change to $token $ibeg from previous token + # It starts with the basic indentation which has been defined for the # leading token, and then takes into account any options that the user # has set regarding special indenting and outdenting. diff --git a/t/snippets/c424.in b/t/snippets/c424.in new file mode 100644 index 00000000..cf1c6c41 --- /dev/null +++ b/t/snippets/c424.in @@ -0,0 +1,2 @@ +my @chars = qw( | / - \ | / - \ ); +my @chars = qw(| / - \ | / - \ ); diff --git a/t/snippets/c424.par b/t/snippets/c424.par new file mode 100644 index 00000000..361ea4fb --- /dev/null +++ b/t/snippets/c424.par @@ -0,0 +1 @@ +-naws -qwaf diff --git a/t/snippets/expect/c424.c424 b/t/snippets/expect/c424.c424 new file mode 100644 index 00000000..f92d92e9 --- /dev/null +++ b/t/snippets/expect/c424.c424 @@ -0,0 +1,2 @@ +my @chars = qw( | / - \ | / - \ ); +my @chars = qw(| / - \ | / - \ ); diff --git a/t/snippets/expect/c424.def b/t/snippets/expect/c424.def new file mode 100644 index 00000000..cf1c6c41 --- /dev/null +++ b/t/snippets/expect/c424.def @@ -0,0 +1,2 @@ +my @chars = qw( | / - \ | / - \ ); +my @chars = qw(| / - \ | / - \ ); diff --git a/t/snippets/packing_list.txt b/t/snippets/packing_list.txt index 77f42a26..19d8c8fc 100644 --- a/t/snippets/packing_list.txt +++ b/t/snippets/packing_list.txt @@ -460,6 +460,10 @@ ../snippets30.t git162.git162 ../snippets30.t qwaf.def ../snippets30.t qwaf.qwaf +../snippets30.t btct.btct1 +../snippets31.t btct.btct2 +../snippets31.t btct.btct3 +../snippets31.t btct.def ../snippets4.t gnu1.gnu ../snippets4.t gnu2.def ../snippets4.t gnu2.gnu @@ -580,7 +584,5 @@ ../snippets9.t rt98902.def ../snippets9.t rt98902.rt98902 ../snippets9.t rt99961.def -../snippets30.t btct.btct1 -../snippets31.t btct.btct2 -../snippets31.t btct.btct3 -../snippets31.t btct.def +../snippets31.t c424.c424 +../snippets31.t c424.def diff --git a/t/snippets31.t b/t/snippets31.t index 27f54210..e4536826 100644 --- a/t/snippets31.t +++ b/t/snippets31.t @@ -4,6 +4,8 @@ #1 btct.btct2 #2 btct.btct3 #3 btct.def +#4 c424.c424 +#5 c424.def # To locate test #13 you can search for its name or the string '#13' @@ -23,6 +25,7 @@ BEGIN { $rparams = { 'btct2' => "-btct=1 -atc -wtc=1", 'btct3' => "-btct=1 -atc -wtc=1", + 'c424' => "-naws -qwaf", 'def' => "", }; @@ -45,6 +48,11 @@ $w->bind( $w->bind( '' => xx); $lut = byte [ [ 0, 0, 0 ], [ 10, 1, 10 ], [ 2, 20, 20 ], [ 30, 30, 3 ], ]; +---------- + + 'c424' => <<'----------', +my @chars = qw( | / - \ | / - \ ); +my @chars = qw(| / - \ | / - \ ); ---------- }; @@ -136,6 +144,24 @@ $w->bind( '' => xx ); $lut = byte [ [ 0, 0, 0 ], [ 10, 1, 10 ], [ 2, 20, 20 ], [ 30, 30, 3 ], ]; #3........... }, + + 'c424.c424' => { + source => "c424", + params => "c424", + expect => <<'#4...........', +my @chars = qw( | / - \ | / - \ ); +my @chars = qw(| / - \ | / - \ ); +#4........... + }, + + 'c424.def' => { + source => "c424", + params => "def", + expect => <<'#5...........', +my @chars = qw( | / - \ | / - \ ); +my @chars = qw(| / - \ | / - \ ); +#5........... + }, }; my $ntests = 0 + keys %{$rtests}; -- 2.39.5