From 14c7b22fe8dd58f1e1b256d6091fdb1c2b6bdce1 Mon Sep 17 00:00:00 2001 From: Steve Hancock Date: Tue, 30 Aug 2022 06:53:10 -0700 Subject: [PATCH] add test case c158 --- lib/Perl/Tidy/Tokenizer.pm | 40 +++++++++++++++++++++---------------- t/snippets/c158.in | 5 +++++ t/snippets/expect/c158.def | 5 +++++ t/snippets/packing_list.txt | 3 ++- t/snippets26.t | 21 +++++++++++++++++++ 5 files changed, 56 insertions(+), 18 deletions(-) create mode 100644 t/snippets/c158.in create mode 100644 t/snippets/expect/c158.def diff --git a/lib/Perl/Tidy/Tokenizer.pm b/lib/Perl/Tidy/Tokenizer.pm index c9be0627..821ca601 100644 --- a/lib/Perl/Tidy/Tokenizer.pm +++ b/lib/Perl/Tidy/Tokenizer.pm @@ -5146,22 +5146,25 @@ EOM $continuation_string_in_tokenizer .= ( $in_statement_continuation > 0 ) ? '1' : '0'; - # Sometimes we want to give an opening brace continuation indentation, - # and sometimes not. For code blocks, we don't do it, so that the leading - # '{' gets outdented, like this: - # - # if ( !$output_block_type[$i] - # && ($in_statement_continuation) ) - # { <--outdented - # - # For other types, we will give them continuation indentation. For example, - # here is how a list looks with the opening paren indented: - # - # @LoL = - # ( [ "fred", "barney" ], [ "george", "jane", "elroy" ], - # [ "homer", "marge", "bart" ], ); - # - # This looks best when 'ci' is one-half of the indentation (i.e., 2 and 4) + # Sometimes we want to give an opening brace + # continuation indentation, and sometimes not. For code + # blocks, we don't do it, so that the leading '{' gets + # outdented, like this: + # + # if ( !$output_block_type[$i] + # && ($in_statement_continuation) ) + # { <--outdented + # + # For other types, we will give them continuation + # indentation. For example, here is how a list looks + # with the opening paren indented: + # + # @LoL = + # ( [ "fred", "barney" ], [ "george", "jane", "elroy" ], + # [ "homer", "marge", "bart" ], ); + # + # This looks best when 'ci' is one-half of the + # indentation (i.e., 2 and 4) my $total_ci = $ci_string_sum; if ( @@ -5298,7 +5301,10 @@ EOM } } - # be sure binary operators get continuation indentation + # Be sure binary operators get continuation indentation. + # Note: the check on $nesting_block_flag is only needed + # to add ci to binary operators following a 'try' block, + # or similar extended syntax block operator (see c158). if ( ( $nesting_block_flag || $nesting_list_flag ) && ( $type_i eq 'k' && $is_binary_keyword{$tok_i} diff --git a/t/snippets/c158.in b/t/snippets/c158.in new file mode 100644 index 00000000..fda9aece --- /dev/null +++ b/t/snippets/c158.in @@ -0,0 +1,5 @@ +my $meta = try { $package->meta } +or die "$package does not have a ->meta method\n"; + +my ($curr) = current(); +err(@_); diff --git a/t/snippets/expect/c158.def b/t/snippets/expect/c158.def new file mode 100644 index 00000000..2ab3edb9 --- /dev/null +++ b/t/snippets/expect/c158.def @@ -0,0 +1,5 @@ +my $meta = try { $package->meta } + or die "$package does not have a ->meta method\n"; + +my ($curr) = current(); +err(@_); diff --git a/t/snippets/packing_list.txt b/t/snippets/packing_list.txt index ec4c13d1..d8e9f78f 100644 --- a/t/snippets/packing_list.txt +++ b/t/snippets/packing_list.txt @@ -360,6 +360,7 @@ ../snippets26.t git106.def ../snippets26.t git106.git106 ../snippets26.t c154.def +../snippets26.t code_skipping.code_skipping ../snippets3.t ce_wn1.ce_wn ../snippets3.t ce_wn1.def ../snippets3.t colin.colin @@ -500,4 +501,4 @@ ../snippets9.t rt98902.def ../snippets9.t rt98902.rt98902 ../snippets9.t rt99961.def -../snippets26.t code_skipping.code_skipping +../snippets26.t c158.def diff --git a/t/snippets26.t b/t/snippets26.t index c553ac72..3e466a6d 100644 --- a/t/snippets26.t +++ b/t/snippets26.t @@ -16,6 +16,7 @@ #13 git106.git106 #14 c154.def #15 code_skipping.code_skipping +#16 c158.def # To locate test #13 you can search for its name or the string '#13' @@ -151,6 +152,14 @@ for ( ...; } }}}} +---------- + + 'c158' => <<'----------', +my $meta = try { $package->meta } +or die "$package does not have a ->meta method\n"; + +my ($curr) = current(); +err(@_); ---------- 'code_skipping' => <<'----------', @@ -750,6 +759,18 @@ my $self = shift; my $cloning = shift; #15........... }, + + 'c158.def' => { + source => "c158", + params => "def", + expect => <<'#16...........', +my $meta = try { $package->meta } + or die "$package does not have a ->meta method\n"; + +my ($curr) = current(); +err(@_); +#16........... + }, }; my $ntests = 0 + keys %{$rtests}; -- 2.39.5