]> git.donarmstrong.com Git - perltidy.git/commitdiff
fix rare poor line break, issue c133
authorSteve Hancock <perltidy@users.sourceforge.net>
Tue, 29 Mar 2022 18:33:44 +0000 (11:33 -0700)
committerSteve Hancock <perltidy@users.sourceforge.net>
Tue, 29 Mar 2022 18:33:44 +0000 (11:33 -0700)
lib/Perl/Tidy/Formatter.pm
t/snippets/c133.in [new file with mode: 0644]
t/snippets/c133.par [new file with mode: 0644]
t/snippets/expect/c133.c133 [new file with mode: 0644]
t/snippets/expect/c133.def [new file with mode: 0644]
t/snippets/packing_list.txt
t/snippets26.t

index b61ec7a7f60f7c13db5d2680d965fbdde4f9b346..944a5acddb8bdeb1efefced4686f11d3d1db1644 100644 (file)
@@ -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 (file)
index 0000000..cdd1474
--- /dev/null
@@ -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 (file)
index 0000000..081a3bd
--- /dev/null
@@ -0,0 +1 @@
+-boc
diff --git a/t/snippets/expect/c133.c133 b/t/snippets/expect/c133.c133
new file mode 100644 (file)
index 0000000..cdd1474
--- /dev/null
@@ -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 (file)
index 0000000..098ea3f
--- /dev/null
@@ -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);
index 1749d9addcb88754a4aea8e684e91ede887a4c93..730cc34fe2dfe0c5c4741cd215eda4fb82b18d08 100644 (file)
 ../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
 ../snippets9.t rt98902.def
 ../snippets9.t rt98902.rt98902
 ../snippets9.t rt99961.def
-../snippets26.t        lpxl.lpxl6
+../snippets26.t        c133.c133
+../snippets26.t        c133.def
index d46fcf1ffecd183b61374ebb50509e43fe8f0ce2..3a50a207f7a6be4cd7f0e8b08d4632d2700e71e7 100644 (file)
@@ -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};