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
# 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
- 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"
- 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.
- ./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
--- /dev/null
+# do not break after return with -wba=':'
+return $ref eq 'SCALAR'
+ ? $self->encode_scalar( $object, $name, $type, $attr )
+ : $ref eq 'ARRAY';
--- /dev/null
+# do not break after return with -wba=':'
+return $ref eq 'SCALAR' ? $self->encode_scalar( $object, $name, $type, $attr ) :
+ $ref eq 'ARRAY';
../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
--- /dev/null
+# do not break after return with -wba=':'
+return $ref eq 'SCALAR' ? $self->encode_scalar( $object, $name, $type, $attr ) : $ref eq 'ARRAY';
#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'
###########################################
# BEGIN SECTION 1: Parameter combinations #
###########################################
- $rparams = { 'def' => "", };
+ $rparams = {
+ 'def' => "",
+ 'rt127633' => <<'----------',
+-wba=':'
+----------
+ };
############################
# BEGIN SECTION 2: Sources #
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';
----------
};
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};