]> git.donarmstrong.com Git - perltidy.git/commitdiff
fix b1230, rare formatting instability
authorSteve Hancock <perltidy@users.sourceforge.net>
Fri, 22 Oct 2021 21:57:08 +0000 (14:57 -0700)
committerSteve Hancock <perltidy@users.sourceforge.net>
Fri, 22 Oct 2021 21:57:08 +0000 (14:57 -0700)
dev-bin/run_convergence_tests.pl.data
lib/Perl/Tidy/Formatter.pm

index 4da617f1bdd726bc64a457581927ea359683d2c3..4fb952226cfd54f8601429638580ecdbfc54b489 100644 (file)
@@ -7767,6 +7767,38 @@ $obj= {foo => sub { "bar" ; }
 --line-up-parentheses
 --maximum-line-length=67
 
+==> b1230.in <==
+# S1
+    join(
+        '',
+        map {
+            $_ eq "\e"           ? '\M-'
+                  : ord($_) < 32 ? '\C-'
+                  . lc( chr(
+                             ord($_) + 64 ) )
+                  : $_
+        } ( split( '', $_[0] ) ) );
+# S2
+    join(
+        '',
+        map {
+            $_ eq "\e"           ? '\M-'
+                  : ord($_) < 32 ? '\C-'
+                  . lc( chr(
+                             ord($_) + 64 ) )
+                  : $_
+        } (       split( '', $_[0] ) )
+    );
+
+==> b1230.par <==
+--continuation-indentation=6
+--line-up-parentheses
+--maximum-line-length=31
+--paren-vertical-tightness-closing=2
+--variable-maximum-line-length
+--vertical-tightness=2
+--weld-nested-containers
+
 ==> b131.in <==
         unless
           ( open( SCORE, "+>>$Score_File" ) )
index 6d3589c6e5f3b204ab8497096f28993bbcc7cce5..41459647fe5abd991b52ca425f9ca7a6db0ad31a 100644 (file)
@@ -8494,9 +8494,14 @@ EOM
             # (2) the line does not exceed the allowable length
             if ( $iline_oo == $iline_oc ) {
 
-                # All the tokens are on one line, now check their length
+                # All the tokens are on one line, now check their length:
+                # - measure entire line if balanced
+                # - measure to the closing container if unbalanced (fixes b1230)
+                my $is_balanced =
+                  $rLL->[$Kfirst]->[_LEVEL_] == $rLL->[$Klast]->[_LEVEL_];
+                my $Kstop = $is_balanced ? $Klast : $Kouter_closing;
                 my $excess =
-                  $self->excess_line_length_for_Krange( $Kfirst, $Klast );
+                  $self->excess_line_length_for_Krange( $Kfirst, $Kstop );
 
                 # Note: coding simplified here for case b1219
                 $is_one_line_weld = $excess <= 0;