From 6d6384c0c08e59c9a19d5c5a857db626ad53301c Mon Sep 17 00:00:00 2001 From: Steve Hancock Date: Mon, 30 Jan 2023 09:52:48 -0800 Subject: [PATCH] fix b1446 --- dev-bin/run_convergence_tests.pl.data | 34 ++++++++++ dev-bin/run_convergence_tests.pl.expect | 37 +++++++++-- lib/Perl/Tidy/Formatter.pm | 88 ++++++++++++++++++++----- 3 files changed, 135 insertions(+), 24 deletions(-) diff --git a/dev-bin/run_convergence_tests.pl.data b/dev-bin/run_convergence_tests.pl.data index bc9f7f35..8157e373 100644 --- a/dev-bin/run_convergence_tests.pl.data +++ b/dev-bin/run_convergence_tests.pl.data @@ -11338,6 +11338,40 @@ $last = after ( --maximum-line-length=20 --opening-hash-brace-right +==> b1446.in <== + serverprint($d, + &X::newxCreateGlyphCursorReq( + $cursor=&next_resource_id, + $c,# sourcefont + $c,# maskfont + $ch,# sourcechar + $ch+1,# maskchar + $fr,$fg,$fb, + $br,$bg,$bb + ) + ); + + serverprint( + $d, + &X::newxCreateGlyphCursorReq($cursor=&next_resource_id, + $c,# sourcefont + $c,# maskfont + $ch,# sourcechar + $ch+1,# maskchar + $fr,$fg,$fb, + $br,$bg,$bb + ) + ); + +==> b1446.par <== +--noadd-whitespace +--delete-old-whitespace +--extended-line-up-parentheses +--indent-columns=5 +--maximum-line-length=56 +--variable-maximum-line-length +--vertical-tightness=2 + ==> b1447.in <== ok(defined($seqio= $gb->get_Stream_by_batch([qw(J00522 AF303112 diff --git a/dev-bin/run_convergence_tests.pl.expect b/dev-bin/run_convergence_tests.pl.expect index 289ca7d2..8c2df742 100644 --- a/dev-bin/run_convergence_tests.pl.expect +++ b/dev-bin/run_convergence_tests.pl.expect @@ -6122,18 +6122,18 @@ $obj = { subtest '->save' => sub { plan tests => 1; my $layout - =C4::Patroncards::Layout->new ( layout_name => "new patron card", - layout_id => '', # The interface send an empty string - layout_xml => 'some_xml' + =C4::Patroncards::Layout->new (layout_name => "new patron card", + layout_id => '', # The interface send an empty string + layout_xml => 'some_xml' ); }; subtest '->save' => sub { plan tests => 1; my $layout - =C4::Patroncards::Layout->new ( layout_name => "new patron card", - layout_id => '', # The interface send an empty string - layout_xml => 'some_xml' + =C4::Patroncards::Layout->new (layout_name => "new patron card", + layout_id => '', # The interface send an empty string + layout_xml => 'some_xml' ); }; @@ -7694,6 +7694,31 @@ $last = after ( die "Unrecognized $type number: $num\n"; +==> b1446 <== + serverprint( + $d, + &X::newxCreateGlyphCursorReq($cursor=&next_resource_id, + $c,# sourcefont + $c,# maskfont + $ch,# sourcechar + $ch+1,# maskchar + $fr,$fg,$fb, + $br,$bg,$bb + ) + ); + + serverprint( + $d, + &X::newxCreateGlyphCursorReq($cursor=&next_resource_id, + $c,# sourcefont + $c,# maskfont + $ch,# sourcechar + $ch+1,# maskchar + $fr,$fg,$fb, + $br,$bg,$bb + ) + ); + ==> b1447 <== ok(defined($seqio= $gb->get_Stream_by_batch([qw(J00522 AF303112 diff --git a/lib/Perl/Tidy/Formatter.pm b/lib/Perl/Tidy/Formatter.pm index d3b54033..ca8a4f0b 100644 --- a/lib/Perl/Tidy/Formatter.pm +++ b/lib/Perl/Tidy/Formatter.pm @@ -12721,6 +12721,46 @@ sub is_fragile_block_type { return; } + sub cumulative_length_to_comma { + my ( $self, $KK, $K_comma, $K_closing ) = @_; + + # Given: + # $KK = index of starting token, or blank before start + # $K_comma = index of line-ending comma + # $K_closing = index of the container closing token + + # Return: + # $length = cumulative length of the term + + my $rLL = $self->[_rLL_]; + if ( $rLL->[$KK]->[_TYPE_] eq 'b' ) { $KK++ } + my $length = 0; + if ( + $KK < $K_comma + && $rLL->[$K_comma]->[_TYPE_] eq ',' # should be true + + # Ignore if terminal comma, causes instability (b1297, + # b1330) + && ( + $K_closing - $K_comma > 2 + || ( $K_closing - $K_comma == 2 + && $rLL->[ $K_comma + 1 ]->[_TYPE_] ne 'b' ) + ) + + # The comma should be in this container + && ( $rLL->[$K_comma]->[_LEVEL_] - 1 == + $rLL->[$K_closing]->[_LEVEL_] ) + ) + { + + # $len => $leng to fix b1302 b1306 b1317 b1321 + my $starting_len = + $KK >= 0 ? $rLL->[ $KK - 1 ]->[_CUMULATIVE_LENGTH_] : 0; + $length = $rLL->[$K_comma]->[_CUMULATIVE_LENGTH_] - $starting_len; + } + return $length; + } ## end sub cumulative_length_to_comma + sub xlp_collapsed_lengths { my $self = shift; @@ -12975,31 +13015,21 @@ sub is_fragile_block_type { #-------------------------- # END patch for issue b1408 #-------------------------- + if ( $rLL->[$K_terminal]->[_TYPE_] eq ',' ) { - if ( - $rLL->[$K_terminal]->[_TYPE_] eq ',' - - # Ignore if terminal comma, causes instability (b1297, - # b1330) - && ( - $K_c - $K_terminal > 2 - || ( $K_c - $K_terminal == 2 - && $rLL->[ $K_terminal + 1 ]->[_TYPE_] ne 'b' ) - ) - ) - { - - # $len => my $leng to fix b1302 b1306 b1317 b1321 - my $leng = $rLL->[$K_terminal]->[_CUMULATIVE_LENGTH_] - - $rLL->[ $K_first - 1 ]->[_CUMULATIVE_LENGTH_]; + my $length = + $self->cumulative_length_to_comma( $K_first, + $K_terminal, $K_c ); # 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; + $length += $len + 1; + } + if ( $length > $max_prong_len ) { + $max_prong_len = $length; } - if ( $leng > $max_prong_len ) { $max_prong_len = $leng } } } } @@ -13140,6 +13170,27 @@ sub is_fragile_block_type { my $K_c = $K_closing_container->{$seqno}; + # Add length of any terminal list item if interrupted + # so that the result is the same as if the term is + # in the next line (b1446). + + if ( + $interrupted_list_rule + && $KK < $K_terminal + + # The line should end in a comma + # NOTE: this currently assumes break after comma. + # As long as the other call to cumulative_length.. + # makes the same assumption we should remain stable. + && $rLL->[$K_terminal]->[_TYPE_] eq ',' + + ) + { + $max_prong_len = + $self->cumulative_length_to_comma( $KK + 1, + $K_terminal, $K_c ); + } + push @stack, [ $max_prong_len, @@ -13150,6 +13201,7 @@ sub is_fragile_block_type { $K_c, $interrupted_list_rule ]; + } #-------------------- -- 2.39.5