From: Steve Hancock Date: Fri, 17 Feb 2023 02:12:52 +0000 (-0800) Subject: fix b1450 X-Git-Tag: 20230309~21 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=7550505530ce2baec9a9fa41cd572090876e1fd1;p=perltidy.git fix b1450 --- diff --git a/dev-bin/run_convergence_tests.pl.data b/dev-bin/run_convergence_tests.pl.data index db8c472b..5e8f36a5 100644 --- a/dev-bin/run_convergence_tests.pl.data +++ b/dev-bin/run_convergence_tests.pl.data @@ -11461,6 +11461,35 @@ $last = after ( ==> b1449.par <== --nobreak-at-old-ternary-breakpoints +==> b1450.in <== + if ( $x + || ( ($self->allele_ori eq 'g') + && ( substr($self->dnStreamSeq, -1, 1,) eq + 'c'))) + { + return 1; + } + + if ( $x + || ( ($self->allele_ori eq 'g') + && ( + substr( $self->dnStreamSeq, -1, + 1,) eq 'c'))) + { + return 1; + } + +==> b1450.par <== +--break-before-paren-and-indent=2 +--break-before-paren=2 +--continuation-indentation=9 +--extended-continuation-indentation +--indent-columns=10 +--maximum-line-length=97 +--paren-tightness=2 +--paren-vertical-tightness-closing=2 +--paren-vertical-tightness=1 + ==> b146.in <== # State 1 diff --git a/dev-bin/run_convergence_tests.pl.expect b/dev-bin/run_convergence_tests.pl.expect index df77d451..3e5d70c7 100644 --- a/dev-bin/run_convergence_tests.pl.expect +++ b/dev-bin/run_convergence_tests.pl.expect @@ -5945,10 +5945,9 @@ use overload ==> b1283 <== $_=join( '',$_, - ( - ( $MAX_SPLIT_DEPTH<=$section_commands{ - $outermost_level} - )?"\n
\n":'' + ( ($MAX_SPLIT_DEPTH<= + $section_commands{$outermost_level})? + "\n
\n":'' ), "\\$outermost_level", "*", @@ -5958,10 +5957,9 @@ use overload $_=join( '',$_, - ( - ( $MAX_SPLIT_DEPTH<=$section_commands{ - $outermost_level} - )?"\n
\n":'' + ( ($MAX_SPLIT_DEPTH<= + $section_commands{$outermost_level})? + "\n
\n":'' ), "\\$outermost_level", "*", @@ -7775,6 +7773,23 @@ $last = after ( ->( join( "\n", map $_->(), @data ) . "\n" ); +==> b1450 <== + if ( $x + || ( ($self->allele_ori eq 'g') + && ( substr($self->dnStreamSeq, -1, 1,) eq + 'c'))) + { + return 1; + } + + if ( $x + || ( ($self->allele_ori eq 'g') + && ( substr($self->dnStreamSeq, -1, 1,) eq + 'c'))) + { + return 1; + } + ==> b146 <== # State 1 diff --git a/lib/Perl/Tidy/Formatter.pm b/lib/Perl/Tidy/Formatter.pm index efc29bec..428ea1d5 100644 --- a/lib/Perl/Tidy/Formatter.pm +++ b/lib/Perl/Tidy/Formatter.pm @@ -18362,9 +18362,10 @@ EOM return; } - my $n_best = 0; + my $n_best = 0; + my $bs_best = 0.; - my ( $bs_best, $bs_last, $num_bs, $dbs_min, $dbs_max ); + my ( $bs_last, $num_bs, $dbs_min, $dbs_max ); my ( $nbs_min, $nbs_max ); my $nmax = @{$ri_end} - 1; @@ -18722,6 +18723,9 @@ EOM # we have not taken a shortcut to get here, and && !$incomplete_loop + # we have a good best break by strength + && defined($bs_best) + # we have seen multiple good breaks && defined($num_bs) && $num_bs > 1 @@ -21665,18 +21669,7 @@ EOM $last_old_breakpoint_count = $old_breakpoint_count; # Check for a good old breakpoint .. - if ( - $old_breakpoint_to_go[$i] - - # Note: ignore old breaks at types 'L' and 'R' to fix case - # b1097. These breaks only occur under high stress. - && $type ne 'L' - && $next_nonblank_type ne 'R' - - # ... and ignore other high stress level breaks, fixes b1395 - && $levels_to_go[$i] < $high_stress_level - ) - { + if ( $old_breakpoint_to_go[$i] ) { ( $want_previous_breakpoint, $i_old_assignment_break ) = $self->check_old_breakpoints( $i_next_nonblank, $want_previous_breakpoint, $i_old_assignment_break ); @@ -22037,6 +22030,28 @@ EOM return; } ## end sub study_comma + my %poor_types; + my %poor_keywords; + my %poor_next_types; + my %poor_next_keywords; + + BEGIN { + + # Setup filters for detecting very poor breaks to ignore. + # b1097: old breaks after type 'L' and before 'R' are poor + # b1450: old breaks at 'eq' and related operators are poor + my @q = qw(== <= >= !=); + + @{poor_types}{@q} = (1) x scalar(@q); + @{poor_next_types}{@q} = (1) x scalar(@q); + $poor_types{'L'} = 1; + $poor_next_types{'R'} = 1; + + @q = qw(eq ne le ge lt gt); + @{poor_keywords}{@q} = (1) x scalar(@q); + @{poor_next_keywords}{@q} = (1) x scalar(@q); + } + sub check_old_breakpoints { # Check for a good old breakpoint @@ -22045,6 +22060,23 @@ EOM $i_old_assignment_break ) = @_; + # return if this is a poor break in order to avoid instability + my $poor_break; + + if ( $type eq 'k' ) { $poor_break ||= $poor_keywords{$token} } + else { $poor_break ||= $poor_types{$type} } + + if ( $next_nonblank_type eq 'k' ) { + $poor_break ||= $poor_next_keywords{$next_nonblank_token}; + } + + # ... and ignore any high stress level breaks, fixes b1395 + else { $poor_break ||= $poor_next_types{$next_nonblank_type} } + + $poor_break ||= $levels_to_go[$i] >= $high_stress_level; + + if ($poor_break) { goto RETURN } + $i_line_end = $i; $i_line_start = $i_next_nonblank; @@ -22095,6 +22127,7 @@ EOM elsif ( $is_assignment{$next_nonblank_type} ) { $i_old_assignment_break = $i_next_nonblank; } + RETURN: return ( $want_previous_breakpoint, $i_old_assignment_break ); } ## end sub check_old_breakpoints