For the implementation of these parameters, a B<list> is basically taken to be
a container of items (parens, square brackets, or braces), which is not a code
-block, with one or more commas. These parameters only apply to something that
-fits this definition of a list.
+block, with one or more commas or fat commas. These parameters only apply to
+something that fits this definition of a list.
Note that a paren-less list of parameters is not a list by this definition, so
these parameters have no effect on a paren-less list.
# if this is a list ..
my $rtype_count = $rtype_count_by_seqno->{$type_sequence};
if ( $rtype_count
- && $rtype_count->{','}
+ && ( $rtype_count->{','} || $rtype_count->{'=>'} )
&& !$rtype_count->{';'}
&& !$rtype_count->{'f'} )
{
next;
}
}
+
+ # remember input line index of first '=>' if -wtc is used
+ if (%trailing_comma_rules) {
+ my $seqno = $seqno_stack{ $depth_next - 1 };
+ if ( defined($seqno)
+ && !defined( $self->[_rfirst_comma_line_index_]->{$seqno} )
+ )
+ {
+ $self->[_rfirst_comma_line_index_]->{$seqno} =
+ $rtoken_vars->[_LINE_INDEX_];
+ }
+ }
}
# change 'LABEL :' to 'LABEL:'
return unless ($type_sequence);
my $closing_token = $rLL->[$KK]->[_TOKEN_];
my $rtype_count = $self->[_rtype_count_by_seqno_]->{$type_sequence};
- return unless ( defined($rtype_count) && $rtype_count->{','} );
+ return unless defined($rtype_count);
+ my $comma_count = $rtype_count->{','};
+ my $fat_comma_count = $rtype_count->{'=>'};
+ return unless ( $comma_count || $fat_comma_count );
my $is_permanently_broken =
$self->[_ris_permanently_broken_]->{$type_sequence};
# 'm' matches a Multiline list
#-----------------------------
elsif ( $trailing_comma_style eq 'm' ) {
- $match = $is_multiline;
+ $match = $is_multiline && $comma_count;
}
#----------------------------------
# There must be no more than one comma per line for both 'h' and 'i'
# The new_comma_count here will include the trailing comma.
- my $new_comma_count = $rtype_count->{','};
+ my $new_comma_count = $comma_count;
$new_comma_count += 1 if ($if_add);
my $excess_commas = $new_comma_count - $line_diff_commas - 1;
if ( $excess_commas > 0 ) {
}
}
- # a list of key=>value pairs with at least 2 fat commas is a match
- # for both 'h' and 'i'
- my $fat_comma_count = $rtype_count->{'=>'};
- if ( !$match && $fat_comma_count && $fat_comma_count >= 2 ) {
+ # check fat commas
+ if (
+ !$match
+ && $fat_comma_count
+ && (
+
+ # - a list of key=>value pairs with at least 2 fat commas is a
+ # match for both 'h' and 'i'
+ $fat_comma_count >= 2
+
+ # - an isolated fat comma is a match for type 'h'
+ || ( $fat_comma_count == 1
+ && $new_comma_count == 1
+ && $if_add
+ && $trailing_comma_style eq 'h' )
+ )
+ )
+ {
- # comma count (including trailer) and fat comma count must differ by
- # by no more than 1. This allows for some small variations.
+ # but comma count (including trailer) and fat comma count must
+ # differ by by no more than 1. This allows for some small
+ # variations.
my $comma_diff = $new_comma_count - $fat_comma_count;
$match = ( $comma_diff >= -1 && $comma_diff <= 1 );
}
--- /dev/null
+ # include '=>' in comma count to allow adding trailing comma here
+ my %strips = (
+ 1 => [
+ [ [ 1750, 150, ], [ 1850, 150, ], ],
+ [ [ 1950, 150, ], [ 2050, 150, ], ],
+ ]
+ );
--- /dev/null
+ # include '=>' in comma count to allow adding trailing comma here
+ my %strips = (
+ 1 => [
+ [ [ 1750, 150, ], [ 1850, 150, ], ],
+ [ [ 1950, 150, ], [ 2050, 150, ], ],
+ ],
+ );
my $no_index_1_1 =
{ 'map' =>
- { ':key' => { name => \&string, list => { value => \&string }, }, }, };
+ { ':key' => { name => \&string, list => { value => \&string, }, }, }, };
--- /dev/null
+# include '=>' in comma count to allow adding trailing comma here
+ my %strips = (
+ 1 => [
+ [ [ 1750, 150, ], [ 1850, 150, ], ],
+ [ [ 1950, 150, ], [ 2050, 150, ], ],
+ ]
+ );
--- /dev/null
+-atc -wtc=h
../snippets29.t git137.git137
../snippets29.t git138.def
../snippets29.t git138.git138
+../snippets29.t vsn.vsn3
../snippets3.t ce_wn1.ce_wn
../snippets3.t ce_wn1.def
../snippets3.t colin.colin
../snippets9.t rt98902.def
../snippets9.t rt98902.rt98902
../snippets9.t rt99961.def
-../snippets29.t vsn.vsn3
+../snippets30.t git143.def
+../snippets30.t git143.git143
my $no_index_1_1 =
{ 'map' =>
- { ':key' => { name => \&string, list => { value => \&string }, }, }, };
+ { ':key' => { name => \&string, list => { value => \&string, }, }, }, };
#2...........
},
--- /dev/null
+# Created with: ./make_t.pl
+
+# Contents:
+#1 git143.def
+#2 git143.git143
+
+# To locate test #13 you can search for its name or the string '#13'
+
+use strict;
+use Test::More;
+use Carp;
+use Perl::Tidy;
+my $rparams;
+my $rsources;
+my $rtests;
+
+BEGIN {
+
+ ###########################################
+ # BEGIN SECTION 1: Parameter combinations #
+ ###########################################
+ $rparams = {
+ 'def' => "",
+ 'git143' => "-atc -wtc=h",
+ };
+
+ ############################
+ # BEGIN SECTION 2: Sources #
+ ############################
+ $rsources = {
+
+ 'git143' => <<'----------',
+# include '=>' in comma count to allow adding trailing comma here
+ my %strips = (
+ 1 => [
+ [ [ 1750, 150, ], [ 1850, 150, ], ],
+ [ [ 1950, 150, ], [ 2050, 150, ], ],
+ ]
+ );
+----------
+ };
+
+ ####################################
+ # BEGIN SECTION 3: Expected output #
+ ####################################
+ $rtests = {
+
+ 'git143.def' => {
+ source => "git143",
+ params => "def",
+ expect => <<'#1...........',
+ # include '=>' in comma count to allow adding trailing comma here
+ my %strips = (
+ 1 => [
+ [ [ 1750, 150, ], [ 1850, 150, ], ],
+ [ [ 1950, 150, ], [ 2050, 150, ], ],
+ ]
+ );
+#1...........
+ },
+
+ 'git143.git143' => {
+ source => "git143",
+ params => "git143",
+ expect => <<'#2...........',
+ # include '=>' in comma count to allow adding trailing comma here
+ my %strips = (
+ 1 => [
+ [ [ 1750, 150, ], [ 1850, 150, ], ],
+ [ [ 1950, 150, ], [ 2050, 150, ], ],
+ ],
+ );
+#2...........
+ },
+ };
+
+ my $ntests = 0 + keys %{$rtests};
+ plan tests => $ntests;
+}
+
+###############
+# EXECUTE TESTS
+###############
+
+foreach my $key ( sort keys %{$rtests} ) {
+ my $output;
+ my $sname = $rtests->{$key}->{source};
+ my $expect = $rtests->{$key}->{expect};
+ my $pname = $rtests->{$key}->{params};
+ my $source = $rsources->{$sname};
+ my $params = defined($pname) ? $rparams->{$pname} : "";
+ my $stderr_string;
+ my $errorfile_string;
+ my $err = Perl::Tidy::perltidy(
+ source => \$source,
+ destination => \$output,
+ perltidyrc => \$params,
+ argv => '', # for safety; hide any ARGV from perltidy
+ stderr => \$stderr_string,
+ errorfile => \$errorfile_string, # not used when -se flag is set
+ );
+ if ( $err || $stderr_string || $errorfile_string ) {
+ print STDERR "Error output received for test '$key'\n";
+ if ($err) {
+ print STDERR "An error flag '$err' was returned\n";
+ ok( !$err );
+ }
+ if ($stderr_string) {
+ print STDERR "---------------------\n";
+ print STDERR "<<STDERR>>\n$stderr_string\n";
+ print STDERR "---------------------\n";
+ ok( !$stderr_string );
+ }
+ if ($errorfile_string) {
+ print STDERR "---------------------\n";
+ print STDERR "<<.ERR file>>\n$errorfile_string\n";
+ print STDERR "---------------------\n";
+ ok( !$errorfile_string );
+ }
+ }
+ else {
+ if ( !is( $output, $expect, $key ) ) {
+ my $leno = length($output);
+ my $lene = length($expect);
+ if ( $leno == $lene ) {
+ print STDERR
+"#> Test '$key' gave unexpected output. Strings differ but both have length $leno\n";
+ }
+ else {
+ print STDERR
+"#> Test '$key' gave unexpected output. String lengths differ: output=$leno, expected=$lene\n";
+ }
+ }
+ }
+}