From e6807086ebc626a9aa7ab343f92167d968e9ee2d Mon Sep 17 00:00:00 2001 From: Steve Hancock Date: Wed, 13 May 2020 21:41:51 -0700 Subject: [PATCH] fixed minor problem with -gnu closing brace placement; added test --- lib/Perl/Tidy/Formatter.pm | 4 ++- t/snippets/expect/gnu6.def | 12 ++++++++ t/snippets/expect/gnu6.gnu | 12 ++++++++ t/snippets/gnu6.in | 12 ++++++++ t/snippets/packing_list.txt | 6 ++-- t/snippets20.t | 56 +++++++++++++++++++++++++++++++++++++ 6 files changed, 99 insertions(+), 3 deletions(-) create mode 100644 t/snippets/expect/gnu6.def create mode 100644 t/snippets/expect/gnu6.gnu create mode 100644 t/snippets/gnu6.in diff --git a/lib/Perl/Tidy/Formatter.pm b/lib/Perl/Tidy/Formatter.pm index 2568f1ce..8032b832 100644 --- a/lib/Perl/Tidy/Formatter.pm +++ b/lib/Perl/Tidy/Formatter.pm @@ -7213,6 +7213,9 @@ sub copy_token_as_type { my $in_continued_quote = ( $Ktoken_vars == $K_first ) && $line_of_tokens->{_starting_in_quote}; + if ( $max_index_to_go == 0 ) { + $starting_in_quote = $in_continued_quote; + } # Define the indentation that this token would have if it started # a new line. We start by using the default formula. @@ -7379,7 +7382,6 @@ sub copy_token_as_type { my $rtok_first = $rLL->[$K_first]; - $starting_in_quote = $line_of_tokens->{_starting_in_quote}; my $in_quote = $line_of_tokens->{_ending_in_quote}; $ending_in_quote = $in_quote; my $guessed_indentation_level = diff --git a/t/snippets/expect/gnu6.def b/t/snippets/expect/gnu6.def new file mode 100644 index 00000000..cdacc483 --- /dev/null +++ b/t/snippets/expect/gnu6.def @@ -0,0 +1,12 @@ +# the closing braces should have the same position for these two hashes with -gnu + $var1 = { + 'foo10' => undef, + 'foo72' => ' +', + }; + $var2 = { + 'foo72' => ' +', + 'foo10' => undef, + }; + diff --git a/t/snippets/expect/gnu6.gnu b/t/snippets/expect/gnu6.gnu new file mode 100644 index 00000000..af7299cf --- /dev/null +++ b/t/snippets/expect/gnu6.gnu @@ -0,0 +1,12 @@ + # the closing braces should have the same position for these two hashes with -gnu + $var1 = { + 'foo10' => undef, + 'foo72' => ' +', + }; + $var2 = { + 'foo72' => ' +', + 'foo10' => undef, + }; + diff --git a/t/snippets/gnu6.in b/t/snippets/gnu6.in new file mode 100644 index 00000000..cdacc483 --- /dev/null +++ b/t/snippets/gnu6.in @@ -0,0 +1,12 @@ +# the closing braces should have the same position for these two hashes with -gnu + $var1 = { + 'foo10' => undef, + 'foo72' => ' +', + }; + $var2 = { + 'foo72' => ' +', + 'foo10' => undef, + }; + diff --git a/t/snippets/packing_list.txt b/t/snippets/packing_list.txt index 1638e6c9..3e63a2d9 100644 --- a/t/snippets/packing_list.txt +++ b/t/snippets/packing_list.txt @@ -238,6 +238,8 @@ ../snippets20.t wc.def ../snippets20.t wc.wc1 ../snippets20.t wc.wc2 +../snippets20.t ce2.ce +../snippets20.t ce2.def ../snippets3.t ce_wn1.ce_wn ../snippets3.t ce_wn1.def ../snippets3.t colin.colin @@ -378,5 +380,5 @@ ../snippets9.t rt98902.def ../snippets9.t rt98902.rt98902 ../snippets9.t rt99961.def -../snippets20.t ce2.ce -../snippets20.t ce2.def +../snippets20.t gnu6.def +../snippets20.t gnu6.gnu diff --git a/t/snippets20.t b/t/snippets20.t index 1845695f..4be39332 100644 --- a/t/snippets20.t +++ b/t/snippets20.t @@ -9,6 +9,8 @@ #6 wc.wc2 #7 ce2.ce #8 ce2.def +#9 gnu6.def +#10 gnu6.gnu # To locate test #13 you can search for its name or the string '#13' @@ -28,6 +30,7 @@ BEGIN { $rparams = { 'ce' => "-cuddled-blocks", 'def' => "", + 'gnu' => "-gnu", 'space6' => <<'----------', -nwrs="+ - / *" -nwls="+ - / *" @@ -62,6 +65,21 @@ else { # Is Perl being run from a slave editor or graphical debugger? ... } +---------- + + 'gnu6' => <<'----------', +# the closing braces should have the same position for these two hashes with -gnu + $var1 = { + 'foo10' => undef, + 'foo72' => ' +', + }; + $var2 = { + 'foo72' => ' +', + 'foo10' => undef, + }; + ---------- 'space6' => <<'----------', @@ -279,6 +297,44 @@ else { } #8........... }, + + 'gnu6.def' => { + source => "gnu6", + params => "def", + expect => <<'#9...........', +# the closing braces should have the same position for these two hashes with -gnu + $var1 = { + 'foo10' => undef, + 'foo72' => ' +', + }; + $var2 = { + 'foo72' => ' +', + 'foo10' => undef, + }; + +#9........... + }, + + 'gnu6.gnu' => { + source => "gnu6", + params => "gnu", + expect => <<'#10...........', + # the closing braces should have the same position for these two hashes with -gnu + $var1 = { + 'foo10' => undef, + 'foo72' => ' +', + }; + $var2 = { + 'foo72' => ' +', + 'foo10' => undef, + }; + +#10........... + }, }; my $ntests = 0 + keys %{$rtests}; -- 2.39.5