]> git.donarmstrong.com Git - perltidy.git/commitdiff
fixed rt127633
authorSteve Hancock <perltidy@users.sourceforge.net>
Tue, 13 Nov 2018 17:38:45 +0000 (09:38 -0800)
committerSteve Hancock <perltidy@users.sourceforge.net>
Tue, 13 Nov 2018 17:38:45 +0000 (09:38 -0800)
lib/Perl/Tidy/Formatter.pm
t/snippets/README.md
t/snippets/expect/rt127633.def [new file with mode: 0644]
t/snippets/expect/rt127633.rt127633 [new file with mode: 0644]
t/snippets/packing_list.txt
t/snippets/rt127633.in [new file with mode: 0644]
t/snippets/rt127633.par [new file with mode: 0644]
t/snippets13.t

index 8630170c09e2a46d5d22ba10550fb3eb57faa9e9..325fbd79951455b70e276494e3cf94cf60af0fe9 100644 (file)
@@ -15506,13 +15506,36 @@ sub insert_final_breaks {
                 my $token = $tokens_to_go[$ii];
                 my $type  = $types_to_go[$ii];
 
-                # For now, a good break is either a comma or a 'return'.
-                if ( ( $type eq ',' || $type eq 'k' && $token eq 'return' )
-                    && in_same_container( $ii, $i_question ) )
+                # For now, a good break is either a comma or,
+                # in a long chain, a 'return'.  
+               # Patch for RT #126633: added the $nmax>1 check to avoid
+               # breaking after a return for a simple ternary.  For longer
+               # chains the break after return allows vertical alignment, so
+               # it is still done.  So perltidy -wba='?' will not break
+               # immediately after the return in the following statement:
+               # sub x {
+               #    return 0 ? 'aaaaaaaaaaaaaaaaaaaaa' :
+               #      'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb';
+               # }
+                if (
+                    (
+                           $type eq ','
+                        || $type eq 'k' && ( $nmax > 1 && $token eq 'return' )
+                    )
+                    && in_same_container( $ii, $i_question )
+                  )
                 {
                     push @insert_list, $ii;
                     last;
                 }
+
+##                # For now, a good break is either a comma or a 'return'.
+##                if ( ( $type eq ',' || $type eq 'k' && $token eq 'return' )
+##                    && in_same_container( $ii, $i_question ) )
+##                {
+##                    push @insert_list, $ii;
+##                    last;
+##                }
             }
 
             # insert any new break points
index d9c07970861aa77d178edd394f967f7ea1ff7c62..65878325d33663e05be950ce21a9c5d989d3064c 100644 (file)
@@ -1,7 +1,8 @@
 # CODE SNIPPETS FOR TESTING PERLTIDY 
 
 This directory contains some snippets of code to do simple checks of perltidy.
-These are used to create the test file "snippets.t" in the source distribution.
+These are used to create the test files 'snippets\*.t' in the source distribution.
+These test files each contain up to about twenty test cases each.
 
 The tests are intended to give a good overall check that perltidy is working
 correctly at installation but they are by no means exhaustive. Thorough testing
@@ -27,7 +28,6 @@ on the file names.  Two rules are:
 
  - Rule 1: all scripts are run with the default parameters ("def.par")
  - Rule 2: if there is a parameter file with the same base name as the base name of the script file, then the script is also run with that parameter file. 
-then that script is 
 
 For example, consider the source file "rt20421.in".  The base name is 'rt20421'.
 It will be run with the default parameters.  If a parameter file named "rt20421.par" 
@@ -60,13 +60,16 @@ creating new names.
 
 - Parameter files 'style1.par' and 'style35.par' will be run against 'style.in' if it exists.
 
-It is best to avoid file names which are pure digits because they can be difficult to search for. But leading digits followed by some non-digits, would be okay.
+It is best to avoid file names which are pure digits because they can be
+difficult to search for. But leading digits followed by some non-digits, would
+be okay.  These rules may seem a little complex at first but they work quite
+well.
 
 ## How to name a new snippet and parameter file, if any:
 
 - Give it a new base name with extension ".in".  End the name with some digits
   to avoid accidentally invoking unexpected parameter combinations. If you just
-want to format with default parameters, skip to the the run 'make' step.
+want to format with default parameters, you can skip to the next step where you run 'make'. 
 
   - For example, you might add a file named "rt126965.in" and then type 'make'
 and follow the directions.
@@ -100,7 +103,11 @@ if everything looks good.
 
 - ./RUNME.sh
 
-- This re-creates the 'snippet#.t' files in the upper directory.
+- This re-creates the 'snippet#.t' files in the upper directory.  A file 
+named 'packing\_list.txt' is written which shows the order of the snippets
+in the snippet files.  If you added test cases they should appear at the
+end of the list and will be in the highest numbered snippet file.
+
 - Verify that everything is ok by running perl on the new '.t' files or by
 going to the top directory and doing 
 
diff --git a/t/snippets/expect/rt127633.def b/t/snippets/expect/rt127633.def
new file mode 100644 (file)
index 0000000..c7ee4ef
--- /dev/null
@@ -0,0 +1,4 @@
+# do not break after return with -wba=':'
+return $ref eq 'SCALAR'
+  ? $self->encode_scalar( $object, $name, $type, $attr )
+  : $ref eq 'ARRAY';
diff --git a/t/snippets/expect/rt127633.rt127633 b/t/snippets/expect/rt127633.rt127633
new file mode 100644 (file)
index 0000000..eed8d0e
--- /dev/null
@@ -0,0 +1,3 @@
+# do not break after return with -wba=':'
+return $ref eq 'SCALAR' ? $self->encode_scalar( $object, $name, $type, $attr ) :
+  $ref eq 'ARRAY';
index c7734126a7d3faae066ac8eea6ece6b16cd0273d..5476d1abef41da0bb3cb5bd5cbde446cb95be99a 100644 (file)
@@ -82,6 +82,7 @@
 ../snippets13.t        align10.def
 ../snippets13.t        align11.def
 ../snippets13.t        align12.def
+../snippets13.t        align13.def
 ../snippets2.t angle.def
 ../snippets2.t arrows1.def
 ../snippets2.t arrows2.def
 ../snippets9.t rt98902.def
 ../snippets9.t rt98902.rt98902
 ../snippets9.t rt99961.def
-../snippets13.t        align13.def
+../snippets13.t        rt127633.def
+../snippets13.t        rt127633.rt127633
diff --git a/t/snippets/rt127633.in b/t/snippets/rt127633.in
new file mode 100644 (file)
index 0000000..0f9e143
--- /dev/null
@@ -0,0 +1,2 @@
+# do not break after return with -wba=':'
+return $ref eq 'SCALAR' ? $self->encode_scalar( $object, $name, $type, $attr ) : $ref eq 'ARRAY';
diff --git a/t/snippets/rt127633.par b/t/snippets/rt127633.par
new file mode 100644 (file)
index 0000000..8125ee4
--- /dev/null
@@ -0,0 +1 @@
+-wba=':'
index 51e8c9cfea0578a366909b0eb09de15eb1e053c6..8078edc67dc892dad773e08d23c84371b15f92e9 100644 (file)
@@ -5,6 +5,8 @@
 #2 align11.def
 #3 align12.def
 #4 align13.def
+#5 rt127633.def
+#6 rt127633.rt127633
 
 # To locate test #13 you can search for its name or the string '#13'
 
@@ -21,7 +23,12 @@ BEGIN {
     ###########################################
     # BEGIN SECTION 1: Parameter combinations #
     ###########################################
-    $rparams = { 'def' => "", };
+    $rparams = {
+        'def'      => "",
+        'rt127633' => <<'----------',
+-wba=':'
+----------
+    };
 
     ############################
     # BEGIN SECTION 2: Sources #
@@ -52,6 +59,11 @@ ok( $out !~ /EXACT <fop>/, "No 'baz'" );
 ok( $out =~ /<liz>/,       "Got 'liz'" );    # liz
 ok( $out =~ /<zoo>/,       "Got 'zoo'" );    # zoo
 ok( $out !~ /<zap>/,       "Got 'zap'" );    # zap 
+----------
+
+        'rt127633' => <<'----------',
+# do not break after return with -wba=':'
+return $ref eq 'SCALAR' ? $self->encode_scalar( $object, $name, $type, $attr ) : $ref eq 'ARRAY';
 ----------
     };
 
@@ -101,6 +113,27 @@ ok( $out =~ /<zoo>/,       "Got 'zoo'" );    # zoo
 ok( $out !~ /<zap>/,       "Got 'zap'" );    # zap
 #4...........
         },
+
+        'rt127633.def' => {
+            source => "rt127633",
+            params => "def",
+            expect => <<'#5...........',
+# do not break after return with -wba=':'
+return $ref eq 'SCALAR'
+  ? $self->encode_scalar( $object, $name, $type, $attr )
+  : $ref eq 'ARRAY';
+#5...........
+        },
+
+        'rt127633.rt127633' => {
+            source => "rt127633",
+            params => "rt127633",
+            expect => <<'#6...........',
+# do not break after return with -wba=':'
+return $ref eq 'SCALAR' ? $self->encode_scalar( $object, $name, $type, $attr ) :
+  $ref eq 'ARRAY';
+#6...........
+        },
     };
 
     my $ntests = 0 + keys %{$rtests};