]> git.donarmstrong.com Git - perltidy.git/commitdiff
fixed git#10, minor -wn -ce conflict
authorSteve Hancock <perltidy@users.sourceforge.net>
Sat, 12 Oct 2019 22:51:50 +0000 (15:51 -0700)
committerSteve Hancock <perltidy@users.sourceforge.net>
Sat, 12 Oct 2019 22:51:50 +0000 (15:51 -0700)
CHANGES.md
lib/Perl/Tidy/Formatter.pm
t/snippets/expect/git10.def [new file with mode: 0644]
t/snippets/expect/git10.git10 [new file with mode: 0644]
t/snippets/git10.in [new file with mode: 0644]
t/snippets/git10.par [new file with mode: 0644]
t/snippets/packing_list.txt
t/snippets16.t

index 89c48aea4f305f0cab27e7f5013c9c235d883c02..1c877c6e2191e46e29503564743b3d338a5c6dc8 100644 (file)
@@ -30,6 +30,8 @@
 
     - fixed issue git#16, minor vertical alignment issue.
 
+    - fixed issue git#10, minor conflict of -wn and -ce
+
 ## 2019 09 15
 
     - fixed issue RT#130344: false warning "operator in print statement" 
index ae189bcac650cf9d459e666af4a091c67113e901..562bab4b20f4023ef06529fc936ee524cf32c57d 100644 (file)
@@ -3948,6 +3948,36 @@ sub weld_nested_containers {
         # Do not weld if this makes our line too long
         $do_not_weld ||= $excess_length_to_K->($Kinner_opening) > 0;
 
+        # DO-NOT-WELD RULE 4; implemented for git#10:
+       # Do not weld an opening -ce brace if the next container is on a single
+       # line, different from the opening brace. (This is very rare).  For
+       # example, given the following with -ce, we will avoid joining the {
+       # and [
+          
+        #  } else {
+        #      [ $_, length($_) ]
+        #  }
+        
+       # because this would produce a terminal one-line block:
+
+        #  } else { [ $_, length($_) ]  }
+
+       # which may not be what is desired. But given this input:
+
+        #  } else { [ $_, length($_) ]  }
+
+       # then we will do the weld and retain the one-line block
+        if ( $rOpts->{'cuddled-else'} ) {
+            my $block_type = $rLL->[$Kouter_opening]->[_BLOCK_TYPE_];
+            if ( $block_type && $rcuddled_block_types->{'*'}->{$block_type} ) {
+                my $io_line = $inner_opening->[_LINE_INDEX_];
+                my $ic_line = $inner_closing->[_LINE_INDEX_];
+                my $oo_line = $outer_opening->[_LINE_INDEX_];
+                $do_not_weld ||=
+                  ( $oo_line < $io_line && $ic_line == $io_line );
+            }
+        }
+
         if ($do_not_weld) {
 
             # After neglecting a pair, we start measuring from start of point io
diff --git a/t/snippets/expect/git10.def b/t/snippets/expect/git10.def
new file mode 100644 (file)
index 0000000..131faee
--- /dev/null
@@ -0,0 +1,5 @@
+# perltidy -wn -ce -cbl=sort,map,grep
+@sorted =
+  map  { $_->[0] }
+  sort { $a->[1] <=> $b->[1] or $a->[0] cmp $b->[0] }
+  map  { [ $_, length($_) ] } @unsorted;
diff --git a/t/snippets/expect/git10.git10 b/t/snippets/expect/git10.git10
new file mode 100644 (file)
index 0000000..6fc2108
--- /dev/null
@@ -0,0 +1,8 @@
+# perltidy -wn -ce -cbl=sort,map,grep
+@sorted = map {
+    $_->[0]
+} sort {
+    $a->[1] <=> $b->[1] or $a->[0] cmp $b->[0]
+} map {
+    [ $_, length($_) ]
+} @unsorted;
diff --git a/t/snippets/git10.in b/t/snippets/git10.in
new file mode 100644 (file)
index 0000000..6fc2108
--- /dev/null
@@ -0,0 +1,8 @@
+# perltidy -wn -ce -cbl=sort,map,grep
+@sorted = map {
+    $_->[0]
+} sort {
+    $a->[1] <=> $b->[1] or $a->[0] cmp $b->[0]
+} map {
+    [ $_, length($_) ]
+} @unsorted;
diff --git a/t/snippets/git10.par b/t/snippets/git10.par
new file mode 100644 (file)
index 0000000..332a78a
--- /dev/null
@@ -0,0 +1 @@
+-wn -ce -cbl=sort,map,grep
index c9c265b6652e9d04c43f8ff018f471fd4c0c57b9..e9032c0ace6598b453af283cce0da65d127b8d3c 100644 (file)
 ../snippets15.t        spp.spp0
 ../snippets16.t        spp.spp1
 ../snippets16.t        spp.spp2
+../snippets16.t        git16.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
-../snippets16.t        git16.def
+../snippets16.t        git10.def
+../snippets16.t        git10.git10
index b5c199a7cccbcb69fb861a110702c6806b8f3788..3ad65a8d0c482a913b0ccf1b23a338791a1bacca 100644 (file)
@@ -4,6 +4,8 @@
 #1 spp.spp1
 #2 spp.spp2
 #3 git16.def
+#4 git10.def
+#5 git10.git10
 
 # To locate test #13 you can search for its name or the string '#13'
 
@@ -21,9 +23,10 @@ BEGIN {
     # BEGIN SECTION 1: Parameter combinations #
     ###########################################
     $rparams = {
-        'def'  => "",
-        'spp1' => "-spp=1",
-        'spp2' => "-spp=2",
+        'def'   => "",
+        'git10' => "-wn -ce -cbl=sort,map,grep",
+        'spp1'  => "-spp=1",
+        'spp2'  => "-spp=2",
     };
 
     ############################
@@ -31,6 +34,17 @@ BEGIN {
     ############################
     $rsources = {
 
+        'git10' => <<'----------',
+# perltidy -wn -ce -cbl=sort,map,grep
+@sorted = map {
+    $_->[0]
+} sort {
+    $a->[1] <=> $b->[1] or $a->[0] cmp $b->[0]
+} map {
+    [ $_, length($_) ]
+} @unsorted;
+----------
+
         'git16' => <<'----------',
 # git#16, two equality lines with fat commas on the right
 my $Package = $Self->RepositoryGet( %Param, Result => 'SCALAR' );
@@ -84,6 +98,33 @@ my $Package   = $Self->RepositoryGet( %Param, Result => 'SCALAR' );
 my %Structure = $Self->PackageParse( String => $Package );
 #3...........
         },
+
+        'git10.def' => {
+            source => "git10",
+            params => "def",
+            expect => <<'#4...........',
+# perltidy -wn -ce -cbl=sort,map,grep
+@sorted =
+  map  { $_->[0] }
+  sort { $a->[1] <=> $b->[1] or $a->[0] cmp $b->[0] }
+  map  { [ $_, length($_) ] } @unsorted;
+#4...........
+        },
+
+        'git10.git10' => {
+            source => "git10",
+            params => "git10",
+            expect => <<'#5...........',
+# perltidy -wn -ce -cbl=sort,map,grep
+@sorted = map {
+    $_->[0]
+} sort {
+    $a->[1] <=> $b->[1] or $a->[0] cmp $b->[0]
+} map {
+    [ $_, length($_) ]
+} @unsorted;
+#5...........
+        },
     };
 
     my $ntests = 0 + keys %{$rtests};