From: Steve Hancock Date: Thu, 28 Mar 2024 20:22:43 +0000 (-0700) Subject: fix some c353 edge cases X-Git-Tag: 20240202.04~11 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=e8e960b1fde0a340f3812b7aff4903da78ced345;p=perltidy.git fix some c353 edge cases --- diff --git a/lib/Perl/Tidy/VerticalAligner.pm b/lib/Perl/Tidy/VerticalAligner.pm index c6989fc0..8767950d 100644 --- a/lib/Perl/Tidy/VerticalAligner.pm +++ b/lib/Perl/Tidy/VerticalAligner.pm @@ -5777,7 +5777,11 @@ EOM #------------------------------------------------------ # loop over all lines of this vertical alignment column #------------------------------------------------------ - my ( $current_alignment, $starting_colp ); + + my ( + $current_alignment, $starting_colp, + $current_line, @previous_linked_lines + ); foreach my $item ( @{$rwidths} ) { my ( $ix, $width ) = @{$item}; my $line = $rgroup_lines->[$ix]; @@ -5801,25 +5805,32 @@ EOM # nothing to do if no more real alignments on right if ( $jcolp >= $jmax - 1 ) { - $current_alignment = undef; + $current_alignment = undef; + $current_line = undef; + @previous_linked_lines = (); } # handle new rhs alignment elsif ( !$current_alignment ) { - $current_alignment = $alignment; - $starting_colp = $colp; + $current_alignment = $alignment; + $current_line = $line; + $starting_colp = $colp; + @previous_linked_lines = (); } # handle change in existing alignment elsif ( refaddr($alignment) != refaddr($current_alignment) ) { - # completely new rhs + # change rhs alignment column - new vertical group on right if ( $starting_colp != $colp ) { - $starting_colp = $colp; + $starting_colp = $colp; + @previous_linked_lines = (); } else { - # alignment transfer - see if we must increase width + # Same starting alignment col on right, but different alignment + # object. See if we must increase width of this new alignment + # object. my $current_colp = $current_alignment->{column}; if ( $current_colp > $colp ) { my $excess = $current_colp - $colp; @@ -5830,8 +5841,13 @@ EOM $colp = $alignment->{column}; } } + + # remember the previous line in case we have to go back and + # increasse its width + push @previous_linked_lines, $current_line; } $current_alignment = $alignment; + $current_line = $line; } else { # continuing with same alignment @@ -5851,16 +5867,30 @@ EOM my $excess = $lenp + $pad - $avail; if ( $excess > 0 ) { + my $padding_available = $line->get_available_space_on_right(); if ( $excess <= $padding_available ) { $line->increase_field_width( $jcolp, $excess ); + + # Increase space of any previous linked lines + foreach my $line_prev (@previous_linked_lines) { + $padding_available = + $line_prev->get_available_space_on_right(); + if ( $excess <= $padding_available ) { + $line_prev->increase_field_width( $jcolp, $excess ); + } + else { + last; + } + } } else { $pad = 0; } + } - # increase the space + # Add spaces $rfields->[$jcolp] = ( SPACE x $pad ) . $rfields->[$jcolp]; $rfield_lengths->[$jcolp] += $pad; } diff --git a/t/snippets/c353.in b/t/snippets/c353.in index 2fee94bc..902feba2 100644 --- a/t/snippets/c353.in +++ b/t/snippets/c353.in @@ -12,3 +12,15 @@ $unique ||= $hash if (1); $basepath = $CWD unless length($basepath); $basepath .= '/' if -d $basepath && $basepath !~ m#/$#; +$$hr = $1 || $5 || $9 || 0; # 9 is undef, but 5 is defined.. +$$mr = $2 || $6 || 0; +$$sr = $3 || $7 || 0; +$ampm = $4 || $8 || $10; +$$tzr = $11; +$$hr += 12 if $ampm and "\U$ampm" eq "PM" && $$hr != 12; +$$hr = 0 if $$hr == 12 && "\U$ampm" eq "AM"; +$$hr = 0 if $$hr == 24; + +$map = $DEFAULT_MAP unless defined $map; +$map = $DEFAULT_PATH . "/" . $map unless $map =~ m|/|; +$map .= $DEFAULT_EXT unless $map =~ m|/[^/]+\.[^/]+$|; diff --git a/t/snippets/expect/c353.c353 b/t/snippets/expect/c353.c353 index 2fee94bc..07fe6ad1 100644 --- a/t/snippets/expect/c353.c353 +++ b/t/snippets/expect/c353.c353 @@ -12,3 +12,15 @@ $unique ||= $hash if (1); $basepath = $CWD unless length($basepath); $basepath .= '/' if -d $basepath && $basepath !~ m#/$#; +$$hr = $1 || $5 || $9 || 0; # 9 is undef, but 5 is defined.. +$$mr = $2 || $6 || 0; +$$sr = $3 || $7 || 0; +$ampm = $4 || $8 || $10; +$$tzr = $11; +$$hr += 12 if $ampm and "\U$ampm" eq "PM" && $$hr != 12; +$$hr = 0 if $$hr == 12 && "\U$ampm" eq "AM"; +$$hr = 0 if $$hr == 24; + +$map = $DEFAULT_MAP unless defined $map; +$map = $DEFAULT_PATH . "/" . $map unless $map =~ m|/|; +$map .= $DEFAULT_EXT unless $map =~ m|/[^/]+\.[^/]+$|; diff --git a/t/snippets/expect/c353.def b/t/snippets/expect/c353.def index ac76c4c6..4080cb20 100644 --- a/t/snippets/expect/c353.def +++ b/t/snippets/expect/c353.def @@ -12,3 +12,15 @@ $unique ||= $hash if (1); $basepath = $CWD unless length($basepath); $basepath .= '/' if -d $basepath && $basepath !~ m#/$#; +$$hr = $1 || $5 || $9 || 0; # 9 is undef, but 5 is defined.. +$$mr = $2 || $6 || 0; +$$sr = $3 || $7 || 0; +$ampm = $4 || $8 || $10; +$$tzr = $11; +$$hr += 12 if $ampm and "\U$ampm" eq "PM" && $$hr != 12; +$$hr = 0 if $$hr == 12 && "\U$ampm" eq "AM"; +$$hr = 0 if $$hr == 24; + +$map = $DEFAULT_MAP unless defined $map; +$map = $DEFAULT_PATH . "/" . $map unless $map =~ m|/|; +$map .= $DEFAULT_EXT unless $map =~ m|/[^/]+\.[^/]+$|; diff --git a/t/snippets/packing_list.txt b/t/snippets/packing_list.txt index 038440d6..46b998b5 100644 --- a/t/snippets/packing_list.txt +++ b/t/snippets/packing_list.txt @@ -415,6 +415,8 @@ ../snippets29.t git135.def ../snippets29.t git135.git135 ../snippets29.t c352.def +../snippets29.t c353.c353 +../snippets29.t c353.def ../snippets3.t ce_wn1.ce_wn ../snippets3.t ce_wn1.def ../snippets3.t colin.colin @@ -555,5 +557,3 @@ ../snippets9.t rt98902.def ../snippets9.t rt98902.rt98902 ../snippets9.t rt99961.def -../snippets29.t c353.c353 -../snippets29.t c353.def diff --git a/t/snippets29.t b/t/snippets29.t index 53e0f5a5..2018287c 100644 --- a/t/snippets29.t +++ b/t/snippets29.t @@ -83,6 +83,18 @@ $unique ||= $hash if (1); $basepath = $CWD unless length($basepath); $basepath .= '/' if -d $basepath && $basepath !~ m#/$#; +$$hr = $1 || $5 || $9 || 0; # 9 is undef, but 5 is defined.. +$$mr = $2 || $6 || 0; +$$sr = $3 || $7 || 0; +$ampm = $4 || $8 || $10; +$$tzr = $11; +$$hr += 12 if $ampm and "\U$ampm" eq "PM" && $$hr != 12; +$$hr = 0 if $$hr == 12 && "\U$ampm" eq "AM"; +$$hr = 0 if $$hr == 24; + +$map = $DEFAULT_MAP unless defined $map; +$map = $DEFAULT_PATH . "/" . $map unless $map =~ m|/|; +$map .= $DEFAULT_EXT unless $map =~ m|/[^/]+\.[^/]+$|; ---------- 'dia' => <<'----------', @@ -489,6 +501,18 @@ $unique ||= $hash if (1); $basepath = $CWD unless length($basepath); $basepath .= '/' if -d $basepath && $basepath !~ m#/$#; +$$hr = $1 || $5 || $9 || 0; # 9 is undef, but 5 is defined.. +$$mr = $2 || $6 || 0; +$$sr = $3 || $7 || 0; +$ampm = $4 || $8 || $10; +$$tzr = $11; +$$hr += 12 if $ampm and "\U$ampm" eq "PM" && $$hr != 12; +$$hr = 0 if $$hr == 12 && "\U$ampm" eq "AM"; +$$hr = 0 if $$hr == 24; + +$map = $DEFAULT_MAP unless defined $map; +$map = $DEFAULT_PATH . "/" . $map unless $map =~ m|/|; +$map .= $DEFAULT_EXT unless $map =~ m|/[^/]+\.[^/]+$|; #13........... }, @@ -510,6 +534,18 @@ $unique ||= $hash if (1); $basepath = $CWD unless length($basepath); $basepath .= '/' if -d $basepath && $basepath !~ m#/$#; +$$hr = $1 || $5 || $9 || 0; # 9 is undef, but 5 is defined.. +$$mr = $2 || $6 || 0; +$$sr = $3 || $7 || 0; +$ampm = $4 || $8 || $10; +$$tzr = $11; +$$hr += 12 if $ampm and "\U$ampm" eq "PM" && $$hr != 12; +$$hr = 0 if $$hr == 12 && "\U$ampm" eq "AM"; +$$hr = 0 if $$hr == 24; + +$map = $DEFAULT_MAP unless defined $map; +$map = $DEFAULT_PATH . "/" . $map unless $map =~ m|/|; +$map .= $DEFAULT_EXT unless $map =~ m|/[^/]+\.[^/]+$|; #14........... }, };