]> git.donarmstrong.com Git - perltidy.git/commitdiff
fix b1461
authorSteve Hancock <perltidy@users.sourceforge.net>
Sun, 8 Oct 2023 22:23:12 +0000 (15:23 -0700)
committerSteve Hancock <perltidy@users.sourceforge.net>
Sun, 8 Oct 2023 22:23:12 +0000 (15:23 -0700)
dev-bin/run_convergence_tests.pl.data
dev-bin/run_convergence_tests.pl.expect
lib/Perl/Tidy/Formatter.pm

index a041480adca245ea31197c28167e5b795782877b..cf67113484ae0e04bda40afc3a92f24cb1eb3b70 100644 (file)
@@ -11817,6 +11817,20 @@ sub bubba {
 --vertical-tightness=2
 --weld-nested-containers
 
+==> b1461.in <==
+        $C_sigmas = sub { [
+            $a3::COMMON, $a3::Offset{lcount} + 47 ] };
+
+        $C_sigmas = sub
+        { [ $a3::COMMON, $a3::Offset{lcount} + 47 ] };
+
+==> b1461.par <==
+--maximum-line-length=68
+--continuation-indentation=9
+--weld-nested-containers
+--want-break-before='='
+--opening-anonymous-sub-brace-on-new-line
+
 ==> b148.in <==
 # state 1
 @yydgoto=(
index 615c743f8eefa39e3ade518a18225f42ac08ee27..fbcd4a4f93f0f5366f262aa035247fb7250e99f9 100644 (file)
@@ -7994,6 +7994,13 @@ sub bubba {
                      ) )[1] ) . "\n";
 
 
+==> b1461 <==
+        $C_sigmas = sub
+        { [ $a3::COMMON, $a3::Offset{lcount} + 47 ] };
+
+        $C_sigmas = sub
+        { [ $a3::COMMON, $a3::Offset{lcount} + 47 ] };
+
 ==> b148 <==
 # state 1
 @yydgoto=(
index b970606273aebb6b9ea7de3371e2f2b8e2f0bd31..11d116f0a04a8f5d44d53c34c67373e36e4d7ee0 100644 (file)
@@ -17567,6 +17567,8 @@ sub starting_one_line_block {
         return;
     }
 
+    my $len_assignment = 0;
+
     my $ris_bli_container = $self->[_ris_bli_container_];
     my $is_bli            = $ris_bli_container->{$type_sequence_j};
 
@@ -17632,8 +17634,24 @@ sub starting_one_line_block {
             my $lev = $levels_to_go[$i_start];
             if ( $lev > $rLL->[$Kj]->[_LEVEL_] ) { return }
         }
-    }
 
+        # include a length of any preceding assignment token if we break before
+        # it (b1461)
+        elsif ( $i_start > 0 ) {
+            my $i_eq = $i_start - 1;
+            if ( $types_to_go[$i_eq] eq 'b' && $i_eq > 0 ) { $i_eq--; }
+            my $type_eq = $types_to_go[$i_eq];
+            if ( $is_assignment{$type_eq} && $want_break_before{$type_eq} ) {
+
+                # We need to keep i_start unchanged because later logic will
+                # look at the block type of $i_start.  So rather than change
+                # i_start we will define a tolerance.
+                # ( summed_lengths_to_go = length from start of token )
+                $len_assignment = $summed_lengths_to_go[$i_start] -
+                  $summed_lengths_to_go[$i_eq];
+            }
+        }
+    }
     elsif ( $previous_nonblank_token eq ')' ) {
 
         # For something like "if (xxx) {", the keyword "if" will be
@@ -17709,6 +17727,9 @@ sub starting_one_line_block {
 
     my $excess = $pos + 1 + $container_length - $maximum_line_length;
 
+    # include length of a preceding assignment which will be on this line
+    $excess += $len_assignment;
+
     # Add a small tolerance for welded tokens (case b901)
     if ( $total_weld_count && $self->is_welded_at_seqno($type_sequence_j) ) {
         $excess += 2;