fix rare instability found in testing, issue b1331
authorSteve Hancock <perltidy@users.sourceforge.net>
Tue, 5 Apr 2022 15:39:47 +0000 (08:39 -0700)
committerSteve Hancock <perltidy@users.sourceforge.net>
Tue, 5 Apr 2022 15:39:47 +0000 (08:39 -0700)
dev-bin/run_convergence_tests.pl.data
lib/Perl/Tidy/Formatter.pm

index d1d4196b23e065349293da3be3d8ede4ddf74275..70f0d0398c710be38bb0d420a67da8ed8f8d10ed 100644 (file)
@@ -9643,6 +9643,28 @@ WriteMakefile(
 --indent-columns=1
 --square-bracket-vertical-tightness-closing=1
 
+==> b1331.in <==
+# S1
+WriteMakefile PREREQ_PM =>
+  {  # e.g., Module::Name => 1.1
+  'ExtUtils::MakeMaker' => 5.45,
+  'LWP::UserAgent'      => 0,
+  },
+  ;
+
+# S2
+WriteMakefile PREREQ_PM =>
+  {  # e.g., Module::Name => 1.1
+  'ExtUtils::MakeMaker' => 5.45,
+  'LWP::UserAgent'      => 0,
+  },
+  ;
+
+
+==> b1331.par <==
+--extended-line-up-parentheses
+--maximum-line-length=32
+
 ==> b1332.in <==
 # S1
       $b->configure (
index 533c3b5dc9cb451ec6c23da9bd5e1097aeb50ee7..eecf028474849359b7a67219947b16b29ee5a6d0 100644 (file)
@@ -10926,7 +10926,7 @@ sub collapsed_lengths {
                 defined($K_c)
                 && $rLL->[$K_terminal]->[_TYPE_] eq ','
 
-                # Ignore a terminal comma, causes instability (b1297, b1330)
+                # Ignore if terminal comma, causes instability (b1297, b1330)
                 && (
                     $K_c - $K_terminal > 2
                     || (   $K_c - $K_terminal == 2
@@ -10949,6 +10949,12 @@ sub collapsed_lengths {
                 my $leng = $rLL->[$Kend]->[_CUMULATIVE_LENGTH_] -
                   $rLL->[ $K_first - 1 ]->[_CUMULATIVE_LENGTH_];
 
+                # Fix for b1331: at a broken => item, include the length of
+                # the previous half of the item plus one for the missing space
+                if ( $last_nonblank_type eq '=>' ) {
+                    $leng += $len + 1;
+                }
+
                 if ( $leng > $max_prong_len ) { $max_prong_len = $leng }
             }
         }
@@ -11179,7 +11185,7 @@ EOM
                 if ( $len > $max_prong_len ) { $max_prong_len = $len }
 
                 # but only include one => per item
-                if ( $last_nonblank_type eq '=>' ) { $len = $token_length }
+                $len = $token_length;
             }
 
             # include everthing to end of line after a here target