From 5c9a068a86ddb6e2a9c5f031a249db9241f5fba2 Mon Sep 17 00:00:00 2001 From: Steve Hancock Date: Sat, 30 Nov 2019 17:46:52 -0800 Subject: [PATCH] fixed RT#131115, problem with -bli --- CHANGES.md | 4 +++ lib/Perl/Tidy/Formatter.pm | 9 ++++- t/snippets/expect/rt131115.def | 7 ++++ t/snippets/expect/rt131115.rt131115 | 9 +++++ t/snippets/packing_list.txt | 4 ++- t/snippets/rt131115.in | 7 ++++ t/snippets/rt131115.par | 1 + t/snippets16.t | 51 ++++++++++++++++++++++++++--- 8 files changed, 86 insertions(+), 6 deletions(-) create mode 100644 t/snippets/expect/rt131115.def create mode 100644 t/snippets/expect/rt131115.rt131115 create mode 100644 t/snippets/rt131115.in create mode 100644 t/snippets/rt131115.par diff --git a/CHANGES.md b/CHANGES.md index f4e5104b..bda5a03f 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -2,6 +2,10 @@ ## 2019 09 15.01 + - Fixed issue RT#131115: -bli option not working correctly. + Closing braces were not indented in some cases due to a glitch + introduced in version 20181120. + - Fixed issue RT#130394: Allow short nested blocks. Given the following $factorial = sub { reduce { $a * $b } 1 .. 11 }; diff --git a/lib/Perl/Tidy/Formatter.pm b/lib/Perl/Tidy/Formatter.pm index 5eac7ad6..40436416 100644 --- a/lib/Perl/Tidy/Formatter.pm +++ b/lib/Perl/Tidy/Formatter.pm @@ -11009,7 +11009,14 @@ sub lookup_opening_indentation { && defined($K_beg) ) { my $K_next_nonblank = $self->K_next_code($K_beg); - if ( defined($K_next_nonblank) ) { + + # Patch for RT#131115: honor -bli flag at closing brace + my $is_bli = + $rOpts_brace_left_and_indent + && $block_type_to_go[$i_terminal] + && $block_type_to_go[$i_terminal] =~ /$bli_pattern/o; + + if ( !$is_bli && defined($K_next_nonblank) ) { my $lev = $rLL->[$K_beg]->[_LEVEL_]; my $level_next = $rLL->[$K_next_nonblank]->[_LEVEL_]; $adjust_indentation = 1 if ( $level_next < $lev ); diff --git a/t/snippets/expect/rt131115.def b/t/snippets/expect/rt131115.def new file mode 100644 index 00000000..a8340283 --- /dev/null +++ b/t/snippets/expect/rt131115.def @@ -0,0 +1,7 @@ +# closing braces to be inteded with -bli +sub a { + my %uniq; + foreach my $par (@_) { + $uniq{$par} = 1; + } +} diff --git a/t/snippets/expect/rt131115.rt131115 b/t/snippets/expect/rt131115.rt131115 new file mode 100644 index 00000000..7f610016 --- /dev/null +++ b/t/snippets/expect/rt131115.rt131115 @@ -0,0 +1,9 @@ +# closing braces to be inteded with -bli +sub a + { + my %uniq; + foreach my $par (@_) + { + $uniq{$par} = 1; + } + } diff --git a/t/snippets/packing_list.txt b/t/snippets/packing_list.txt index 990ed502..c2148c71 100644 --- a/t/snippets/packing_list.txt +++ b/t/snippets/packing_list.txt @@ -146,6 +146,7 @@ ../snippets16.t almost1.def ../snippets16.t almost2.def ../snippets16.t almost3.def +../snippets16.t rt130394.def ../snippets2.t angle.def ../snippets2.t arrows1.def ../snippets2.t arrows2.def @@ -306,4 +307,5 @@ ../snippets9.t rt98902.def ../snippets9.t rt98902.rt98902 ../snippets9.t rt99961.def -../snippets16.t rt130394.def +../snippets16.t rt131115.def +../snippets16.t rt131115.rt131115 diff --git a/t/snippets/rt131115.in b/t/snippets/rt131115.in new file mode 100644 index 00000000..a8340283 --- /dev/null +++ b/t/snippets/rt131115.in @@ -0,0 +1,7 @@ +# closing braces to be inteded with -bli +sub a { + my %uniq; + foreach my $par (@_) { + $uniq{$par} = 1; + } +} diff --git a/t/snippets/rt131115.par b/t/snippets/rt131115.par new file mode 100644 index 00000000..3ee06bc1 --- /dev/null +++ b/t/snippets/rt131115.par @@ -0,0 +1 @@ +-bli diff --git a/t/snippets16.t b/t/snippets16.t index 7677af8b..5770bb58 100644 --- a/t/snippets16.t +++ b/t/snippets16.t @@ -12,6 +12,8 @@ #9 almost2.def #10 almost3.def #11 rt130394.def +#12 rt131115.def +#13 rt131115.rt131115 # To locate test #13 you can search for its name or the string '#13' @@ -29,10 +31,11 @@ BEGIN { # BEGIN SECTION 1: Parameter combinations # ########################################### $rparams = { - 'def' => "", - 'git10' => "-wn -ce -cbl=sort,map,grep", - 'spp1' => "-spp=1", - 'spp2' => "-spp=2", + 'def' => "", + 'git10' => "-wn -ce -cbl=sort,map,grep", + 'rt131115' => "-bli", + 'spp1' => "-spp=1", + 'spp2' => "-spp=2", }; ############################ @@ -100,6 +103,16 @@ $start = $end = $len = $ismut = $number = $allele_ori = $allele_mut = 'rt130394' => <<'----------', # rt130394: keep on one line $factorial = sub { reduce { $a * $b } 1 .. 11 }; +---------- + + 'rt131115' => <<'----------', +# closing braces to be inteded with -bli +sub a { + my %uniq; + foreach my $par (@_) { + $uniq{$par} = 1; + } +} ---------- 'spp' => <<'----------', @@ -245,6 +258,36 @@ sub head { $factorial = sub { reduce { $a * $b } 1 .. 11 }; #11........... }, + + 'rt131115.def' => { + source => "rt131115", + params => "def", + expect => <<'#12...........', +# closing braces to be inteded with -bli +sub a { + my %uniq; + foreach my $par (@_) { + $uniq{$par} = 1; + } +} +#12........... + }, + + 'rt131115.rt131115' => { + source => "rt131115", + params => "rt131115", + expect => <<'#13...........', +# closing braces to be inteded with -bli +sub a + { + my %uniq; + foreach my $par (@_) + { + $uniq{$par} = 1; + } + } +#13........... + }, }; my $ntests = 0 + keys %{$rtests}; -- 2.39.5