From 73ecb91e5536b1115d2a066d4da5721d88ef1ee3 Mon Sep 17 00:00:00 2001 From: Steve Hancock Date: Mon, 6 Apr 2020 19:06:59 -0700 Subject: [PATCH] fixed rare problem of some blinkers with -pbp --- lib/Perl/Tidy/Formatter.pm | 15 ++++++- t/snippets/expect/pbp6.def | 21 ++++++++++ t/snippets/expect/pbp6.pbp | 23 +++++++++++ t/snippets/packing_list.txt | 6 ++- t/snippets/pbp6.in | 14 +++++++ t/snippets17.t | 78 +++++++++++++++++++++++++++++++++++++ 6 files changed, 154 insertions(+), 3 deletions(-) create mode 100644 t/snippets/expect/pbp6.def create mode 100644 t/snippets/expect/pbp6.pbp create mode 100644 t/snippets/pbp6.in diff --git a/lib/Perl/Tidy/Formatter.pm b/lib/Perl/Tidy/Formatter.pm index 0fa3c26b..54f03e53 100644 --- a/lib/Perl/Tidy/Formatter.pm +++ b/lib/Perl/Tidy/Formatter.pm @@ -12861,6 +12861,12 @@ sub terminal_type_K { if ( $next_nonblank_token =~ /^(die|confess|croak|warn)$/ ) { if ( $want_break_before{$token} && $i > 0 ) { $bond_strength_to_go[ $i - 1 ] -= $delta_bias; + + # keep bond strength of a token and its following blank + # the same + if ( $types_to_go[ $i - 1 ] eq 'b' && $i > 2 ) { + $bond_strength_to_go[ $i - 2 ] -= $delta_bias; + } } else { $bond_str -= $delta_bias; @@ -17252,6 +17258,7 @@ sub set_continuation_breaks { #------------------------------------------------------- # BEGINNING of inner loop to find the best next breakpoint #------------------------------------------------------- + my $strength = NO_BREAK; for ( $i_test = $i_begin ; $i_test <= $imax ; $i_test++ ) { my $type = $types_to_go[$i_test]; my $token = $tokens_to_go[$i_test]; @@ -17261,9 +17268,15 @@ sub set_continuation_breaks { my $next_nonblank_type = $types_to_go[$i_next_nonblank]; my $next_nonblank_token = $tokens_to_go[$i_next_nonblank]; my $next_nonblank_block_type = $block_type_to_go[$i_next_nonblank]; - my $strength = $bond_strength_to_go[$i_test]; my $maximum_line_length = maximum_line_length($i_begin); + # adjustments to the previous bond strength may have been made, and + # we must keep the bond strength of a token and its following blank + # the same; + my $last_strength = $strength; + $strength = $bond_strength_to_go[$i_test]; + if ( $type eq 'b' ) { $strength = $last_strength } + # use old breaks as a tie-breaker. For example to # prevent blinkers with -pbp in this code: diff --git a/t/snippets/expect/pbp6.def b/t/snippets/expect/pbp6.def new file mode 100644 index 00000000..1c03ad27 --- /dev/null +++ b/t/snippets/expect/pbp6.def @@ -0,0 +1,21 @@ + # These formerly blinked with -pbp + return $width1 * + $common_length * + ( + $W * atan2( 1, $W ) + + $H * atan2( 1, $H ) - + $RTHSQPWSQ * atan2( 1, $RTHSQPWSQ ) + + 0.25 * log( + ( $WSQP1 * $HSQP1 ) / + ( 1 + $WSQ + $HSQ ) * + ( $WSQ * ( 1 + $WSQ + $HSQ ) / ( $WSQP1 * $HSQPWSQ ) ) + **$WSQ * + ( $HSQ * ( 1 + $WSQ + $HSQ ) / ( $HSQP1 * $HSQPWSQ ) )**$HSQ + ) + ) / + ( $W * $pi ); + + my $oldSec = + ( 60 * $session->{originalStartHour} + $session->{originalStartMin} ) + * 60; + diff --git a/t/snippets/expect/pbp6.pbp b/t/snippets/expect/pbp6.pbp new file mode 100644 index 00000000..48e26bdc --- /dev/null +++ b/t/snippets/expect/pbp6.pbp @@ -0,0 +1,23 @@ + # These formerly blinked with -pbp + return + $width1 * $common_length + * ( + $W * atan2( 1, $W ) + + $H * atan2( 1, $H ) + - $RTHSQPWSQ * atan2( 1, $RTHSQPWSQ ) + + 0.25 * log( + ( $WSQP1 * $HSQP1 ) + / ( 1 + $WSQ + $HSQ ) + * ( $WSQ * ( 1 + $WSQ + $HSQ ) / ( $WSQP1 * $HSQPWSQ ) ) + **$WSQ + * ( $HSQ * ( 1 + $WSQ + $HSQ ) / ( $HSQP1 * $HSQPWSQ ) ) + **$HSQ + ) + ) + / ( $W * $pi ); + + my $oldSec + = ( 60 * $session->{originalStartHour} + + $session->{originalStartMin} ) + * 60; + diff --git a/t/snippets/packing_list.txt b/t/snippets/packing_list.txt index 591731ba..2fef0807 100644 --- a/t/snippets/packing_list.txt +++ b/t/snippets/packing_list.txt @@ -162,6 +162,8 @@ ../snippets17.t rperl.rperl ../snippets17.t wn7.def ../snippets17.t wn7.wn +../snippets17.t wn8.def +../snippets17.t wn8.wn ../snippets2.t angle.def ../snippets2.t arrows1.def ../snippets2.t arrows2.def @@ -322,5 +324,5 @@ ../snippets9.t rt98902.def ../snippets9.t rt98902.rt98902 ../snippets9.t rt99961.def -../snippets17.t wn8.def -../snippets17.t wn8.wn +../snippets17.t pbp6.def +../snippets17.t pbp6.pbp diff --git a/t/snippets/pbp6.in b/t/snippets/pbp6.in new file mode 100644 index 00000000..4db69341 --- /dev/null +++ b/t/snippets/pbp6.in @@ -0,0 +1,14 @@ + # These formerly blinked with -pbp + return $width1*$common_length*( + $W*atan2(1,$W) + + $H*atan2(1,$H) + - $RTHSQPWSQ*atan2(1,$RTHSQPWSQ) + + 0.25*log( + ($WSQP1*$HSQP1)/(1+$WSQ+$HSQ) + *($WSQ*(1+$WSQ+$HSQ)/($WSQP1*$HSQPWSQ))**$WSQ + *($HSQ*(1+$WSQ+$HSQ)/($HSQP1*$HSQPWSQ))**$HSQ + ) + )/($W*$pi); + + my $oldSec = ( 60 * $session->{originalStartHour} + $session->{originalStartMin} ) * 60; + diff --git a/t/snippets17.t b/t/snippets17.t index 73362e4c..c164d508 100644 --- a/t/snippets17.t +++ b/t/snippets17.t @@ -10,6 +10,8 @@ #7 wn7.wn #8 wn8.def #9 wn8.wn +#10 pbp6.def +#11 pbp6.pbp # To locate test #13 you can search for its name or the string '#13' @@ -28,6 +30,7 @@ BEGIN { ########################################### $rparams = { 'def' => "", + 'pbp' => "-pbp -nst -nse", 'rperl' => "-l=0", 'rt132059' => "-dac", 'wn' => "-wn", @@ -38,6 +41,23 @@ BEGIN { ############################ $rsources = { + 'pbp6' => <<'----------', + # These formerly blinked with -pbp + return $width1*$common_length*( + $W*atan2(1,$W) + + $H*atan2(1,$H) + - $RTHSQPWSQ*atan2(1,$RTHSQPWSQ) + + 0.25*log( + ($WSQP1*$HSQP1)/(1+$WSQ+$HSQ) + *($WSQ*(1+$WSQ+$HSQ)/($WSQP1*$HSQPWSQ))**$WSQ + *($HSQ*(1+$WSQ+$HSQ)/($HSQP1*$HSQPWSQ))**$HSQ + ) + )/($W*$pi); + + my $oldSec = ( 60 * $session->{originalStartHour} + $session->{originalStartMin} ) * 60; + +---------- + 'rperl' => <<'----------', # Some test cases for RPerl, https://github.com/wbraswell/rperl/ # These must not remain as single lines with default formatting and long lines @@ -312,6 +332,64 @@ sub foo_subroutine_in_main { ); #9........... }, + + 'pbp6.def' => { + source => "pbp6", + params => "def", + expect => <<'#10...........', + # These formerly blinked with -pbp + return $width1 * + $common_length * + ( + $W * atan2( 1, $W ) + + $H * atan2( 1, $H ) - + $RTHSQPWSQ * atan2( 1, $RTHSQPWSQ ) + + 0.25 * log( + ( $WSQP1 * $HSQP1 ) / + ( 1 + $WSQ + $HSQ ) * + ( $WSQ * ( 1 + $WSQ + $HSQ ) / ( $WSQP1 * $HSQPWSQ ) ) + **$WSQ * + ( $HSQ * ( 1 + $WSQ + $HSQ ) / ( $HSQP1 * $HSQPWSQ ) )**$HSQ + ) + ) / + ( $W * $pi ); + + my $oldSec = + ( 60 * $session->{originalStartHour} + $session->{originalStartMin} ) + * 60; + +#10........... + }, + + 'pbp6.pbp' => { + source => "pbp6", + params => "pbp", + expect => <<'#11...........', + # These formerly blinked with -pbp + return + $width1 * $common_length + * ( + $W * atan2( 1, $W ) + + $H * atan2( 1, $H ) + - $RTHSQPWSQ * atan2( 1, $RTHSQPWSQ ) + + 0.25 * log( + ( $WSQP1 * $HSQP1 ) + / ( 1 + $WSQ + $HSQ ) + * ( $WSQ * ( 1 + $WSQ + $HSQ ) / ( $WSQP1 * $HSQPWSQ ) ) + **$WSQ + * ( $HSQ * ( 1 + $WSQ + $HSQ ) / ( $HSQP1 * $HSQPWSQ ) ) + **$HSQ + ) + ) + / ( $W * $pi ); + + my $oldSec + = ( 60 * $session->{originalStartHour} + + $session->{originalStartMin} ) + * 60; + +#11........... + }, }; my $ntests = 0 + keys %{$rtests}; -- 2.39.5