From: Steve Hancock Date: Sat, 12 Oct 2019 22:51:50 +0000 (-0700) Subject: fixed git#10, minor -wn -ce conflict X-Git-Tag: 20191203~21 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=696cd16f4eb2ef491311fee56bef5b03f5085d05;p=perltidy.git fixed git#10, minor -wn -ce conflict --- diff --git a/CHANGES.md b/CHANGES.md index 89c48aea..1c877c6e 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -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" diff --git a/lib/Perl/Tidy/Formatter.pm b/lib/Perl/Tidy/Formatter.pm index ae189bca..562bab4b 100644 --- a/lib/Perl/Tidy/Formatter.pm +++ b/lib/Perl/Tidy/Formatter.pm @@ -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 index 00000000..131faeed --- /dev/null +++ b/t/snippets/expect/git10.def @@ -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 index 00000000..6fc2108f --- /dev/null +++ b/t/snippets/expect/git10.git10 @@ -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 index 00000000..6fc2108f --- /dev/null +++ b/t/snippets/git10.in @@ -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 index 00000000..332a78a0 --- /dev/null +++ b/t/snippets/git10.par @@ -0,0 +1 @@ +-wn -ce -cbl=sort,map,grep diff --git a/t/snippets/packing_list.txt b/t/snippets/packing_list.txt index c9c265b6..e9032c0a 100644 --- a/t/snippets/packing_list.txt +++ b/t/snippets/packing_list.txt @@ -138,6 +138,7 @@ ../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 @@ -298,4 +299,5 @@ ../snippets9.t rt98902.def ../snippets9.t rt98902.rt98902 ../snippets9.t rt99961.def -../snippets16.t git16.def +../snippets16.t git10.def +../snippets16.t git10.git10 diff --git a/t/snippets16.t b/t/snippets16.t index b5c199a7..3ad65a8d 100644 --- a/t/snippets16.t +++ b/t/snippets16.t @@ -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};