From: Steve Hancock Date: Tue, 29 Mar 2022 18:33:44 +0000 (-0700) Subject: fix rare poor line break, issue c133 X-Git-Tag: 20220217.03~25 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=fac76d93d1080dcc372ef50abe7b472b0c8a1e8c;p=perltidy.git fix rare poor line break, issue c133 --- diff --git a/lib/Perl/Tidy/Formatter.pm b/lib/Perl/Tidy/Formatter.pm index b61ec7a7..944a5acd 100644 --- a/lib/Perl/Tidy/Formatter.pm +++ b/lib/Perl/Tidy/Formatter.pm @@ -3969,8 +3969,10 @@ EOM my $rbond_strength_to_go = []; - my $rK_weld_right = $self->[_rK_weld_right_]; - my $rK_weld_left = $self->[_rK_weld_left_]; + my $rLL = $self->[_rLL_]; + my $rK_weld_right = $self->[_rK_weld_right_]; + my $rK_weld_left = $self->[_rK_weld_left_]; + my $ris_list_by_seqno = $self->[_ris_list_by_seqno_]; # patch-its always ok to break at end of line $nobreak_to_go[$max_index_to_go] = 0; @@ -4048,6 +4050,22 @@ EOM # this will cause good preceding breaks to be retained if ( $i_next_nonblank > $max_index_to_go ) { $bsl = NOMINAL; + + # But weaken the bond at a 'missing terminal comma'. If an + # optional comma is missing at the end of a broken list, use + # the strength of a comma anyway to make formatting the same as + # if it were there. Fixes issue c133. + if ( !defined($bsr) || $bsr > VERY_WEAK ) { + my $seqno = $parent_seqno_to_go[$max_index_to_go]; + if ( $ris_list_by_seqno->{$seqno} ) { + my $KK = $K_to_go[$max_index_to_go]; + my $Kn = $self->K_next_nonblank($KK); + my $seqno_n = $rLL->[$Kn]->[_TYPE_SEQUENCE_]; + if ( $seqno_n && $seqno_n eq $seqno ) { + $bsl = VERY_WEAK; + } + } + } } # define right bond strengths of certain keywords diff --git a/t/snippets/c133.in b/t/snippets/c133.in new file mode 100644 index 00000000..cdd14744 --- /dev/null +++ b/t/snippets/c133.in @@ -0,0 +1,17 @@ +# this will make 1 line unless -boc is used +return ( + $x * cos($a) - $y * sin($a), + $x * sin($a) + $y * cos($a) +); + +# broken list - issue c133 +return ( + $x * cos($a) - $y * sin($a), + $x * sin($a) + $y * cos($a) + +); + +# no parens +return + $x * cos($a) - $y * sin($a), + $x * sin($a) + $y * cos($a); diff --git a/t/snippets/c133.par b/t/snippets/c133.par new file mode 100644 index 00000000..081a3bdf --- /dev/null +++ b/t/snippets/c133.par @@ -0,0 +1 @@ +-boc diff --git a/t/snippets/expect/c133.c133 b/t/snippets/expect/c133.c133 new file mode 100644 index 00000000..cdd14744 --- /dev/null +++ b/t/snippets/expect/c133.c133 @@ -0,0 +1,17 @@ +# this will make 1 line unless -boc is used +return ( + $x * cos($a) - $y * sin($a), + $x * sin($a) + $y * cos($a) +); + +# broken list - issue c133 +return ( + $x * cos($a) - $y * sin($a), + $x * sin($a) + $y * cos($a) + +); + +# no parens +return + $x * cos($a) - $y * sin($a), + $x * sin($a) + $y * cos($a); diff --git a/t/snippets/expect/c133.def b/t/snippets/expect/c133.def new file mode 100644 index 00000000..098ea3fc --- /dev/null +++ b/t/snippets/expect/c133.def @@ -0,0 +1,14 @@ +# this will make 1 line unless -boc is used +return ( $x * cos($a) - $y * sin($a), $x * sin($a) + $y * cos($a) ); + +# broken list - issue c133 +return ( + $x * cos($a) - $y * sin($a), + $x * sin($a) + $y * cos($a) + +); + +# no parens +return + $x * cos($a) - $y * sin($a), + $x * sin($a) + $y * cos($a); diff --git a/t/snippets/packing_list.txt b/t/snippets/packing_list.txt index 1749d9ad..730cc34f 100644 --- a/t/snippets/packing_list.txt +++ b/t/snippets/packing_list.txt @@ -348,6 +348,7 @@ ../snippets25.t bal.bal1 ../snippets26.t bal.bal2 ../snippets26.t bal.def +../snippets26.t lpxl.lpxl6 ../snippets3.t ce_wn1.ce_wn ../snippets3.t ce_wn1.def ../snippets3.t colin.colin @@ -488,4 +489,5 @@ ../snippets9.t rt98902.def ../snippets9.t rt98902.rt98902 ../snippets9.t rt99961.def -../snippets26.t lpxl.lpxl6 +../snippets26.t c133.c133 +../snippets26.t c133.def diff --git a/t/snippets26.t b/t/snippets26.t index d46fcf1f..3a50a207 100644 --- a/t/snippets26.t +++ b/t/snippets26.t @@ -4,6 +4,8 @@ #1 bal.bal2 #2 bal.def #3 lpxl.lpxl6 +#4 c133.c133 +#5 c133.def # To locate test #13 you can search for its name or the string '#13' @@ -22,6 +24,7 @@ BEGIN { ########################################### $rparams = { 'bal2' => "-bal=2", + 'c133' => "-boc", 'def' => "", 'lpxl6' => <<'----------', # equivalent to -lpxl='{ [ F(2' @@ -42,6 +45,26 @@ BEGIN { }; ---------- + 'c133' => <<'----------', +# this will make 1 line unless -boc is used +return ( + $x * cos($a) - $y * sin($a), + $x * sin($a) + $y * cos($a) +); + +# broken list - issue c133 +return ( + $x * cos($a) - $y * sin($a), + $x * sin($a) + $y * cos($a) + +); + +# no parens +return + $x * cos($a) - $y * sin($a), + $x * sin($a) + $y * cos($a); +---------- + 'lpxl' => <<'----------', # simple function call my $loanlength = getLoanLength( @@ -200,6 +223,51 @@ $behaviour = { }; #3........... }, + + 'c133.c133' => { + source => "c133", + params => "c133", + expect => <<'#4...........', +# this will make 1 line unless -boc is used +return ( + $x * cos($a) - $y * sin($a), + $x * sin($a) + $y * cos($a) +); + +# broken list - issue c133 +return ( + $x * cos($a) - $y * sin($a), + $x * sin($a) + $y * cos($a) + +); + +# no parens +return + $x * cos($a) - $y * sin($a), + $x * sin($a) + $y * cos($a); +#4........... + }, + + 'c133.def' => { + source => "c133", + params => "def", + expect => <<'#5...........', +# this will make 1 line unless -boc is used +return ( $x * cos($a) - $y * sin($a), $x * sin($a) + $y * cos($a) ); + +# broken list - issue c133 +return ( + $x * cos($a) - $y * sin($a), + $x * sin($a) + $y * cos($a) + +); + +# no parens +return + $x * cos($a) - $y * sin($a), + $x * sin($a) + $y * cos($a); +#5........... + }, }; my $ntests = 0 + keys %{$rtests};