]> git.donarmstrong.com Git - perltidy.git/commitdiff
fix b1450
authorSteve Hancock <perltidy@users.sourceforge.net>
Fri, 17 Feb 2023 02:12:52 +0000 (18:12 -0800)
committerSteve Hancock <perltidy@users.sourceforge.net>
Fri, 17 Feb 2023 02:12:52 +0000 (18:12 -0800)
dev-bin/run_convergence_tests.pl.data
dev-bin/run_convergence_tests.pl.expect
lib/Perl/Tidy/Formatter.pm

index db8c472b30ec0e2a14f65f9592ad31515985a187..5e8f36a59e7d7728afb9795faf8057702fa430d8 100644 (file)
@@ -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
 
index df77d451a2740ef49d93bedd43d822a2c2e5ccfe..3e5d70c71afd10c6cfa02ceb07fc308133d9b29d 100644 (file)
@@ -5945,10 +5945,9 @@ use overload
 ==> b1283 <==
        $_=join(
               '',$_,
-              (
-                     (      $MAX_SPLIT_DEPTH<=$section_commands{
-                                   $outermost_level}
-                     )?"\n<HR>\n":''
+              (      ($MAX_SPLIT_DEPTH<=
+                              $section_commands{$outermost_level})?
+                       "\n<HR>\n":''
               ),
               "\\$outermost_level",
               "*",
@@ -5958,10 +5957,9 @@ use overload
 
        $_=join(
               '',$_,
-              (
-                     (      $MAX_SPLIT_DEPTH<=$section_commands{
-                                   $outermost_level}
-                     )?"\n<HR>\n":''
+              (      ($MAX_SPLIT_DEPTH<=
+                              $section_commands{$outermost_level})?
+                       "\n<HR>\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
 
index efc29bec09051f4afafda791e7d55e9b62209767..428ea1d5b5435ef83596e4a5ed6e7602fa909ded 100644 (file)
@@ -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