From b52e3d92c36bd3d53421787eec01c1fe4f3de7fd Mon Sep 17 00:00:00 2001 From: Steve Hancock Date: Fri, 30 Nov 2018 17:44:55 -0800 Subject: [PATCH] added alignment test cases --- t/snippets/align24.in | 7 ++ t/snippets/align25.in | 5 ++ t/snippets/align26.in | 3 + t/snippets/align27.in | 4 ++ t/snippets/else1.in | 4 ++ t/snippets/else2.in | 3 + t/snippets/expect/align12.def | 4 +- t/snippets/expect/align24.def | 7 ++ t/snippets/expect/align25.def | 5 ++ t/snippets/expect/align26.def | 3 + t/snippets/expect/align27.def | 4 ++ t/snippets/expect/else1.def | 4 ++ t/snippets/expect/else2.def | 3 + t/snippets/expect/smart.def | 20 +++--- t/snippets14.t | 121 ++++++++++++++++++++++++++++++++++ 15 files changed, 185 insertions(+), 12 deletions(-) create mode 100644 t/snippets/align24.in create mode 100644 t/snippets/align25.in create mode 100644 t/snippets/align26.in create mode 100644 t/snippets/align27.in create mode 100644 t/snippets/else1.in create mode 100644 t/snippets/else2.in create mode 100644 t/snippets/expect/align24.def create mode 100644 t/snippets/expect/align25.def create mode 100644 t/snippets/expect/align26.def create mode 100644 t/snippets/expect/align27.def create mode 100644 t/snippets/expect/else1.def create mode 100644 t/snippets/expect/else2.def create mode 100644 t/snippets14.t diff --git a/t/snippets/align24.in b/t/snippets/align24.in new file mode 100644 index 00000000..5b78b026 --- /dev/null +++ b/t/snippets/align24.in @@ -0,0 +1,7 @@ +# Do not align interior fat commas here; differnt container types +my $p = TAP::Parser::SubclassTest->new( + { + exec => [ $cat => $file ], + sources => { MySourceHandler => { accept_all => 1 } }, + } +); diff --git a/t/snippets/align25.in b/t/snippets/align25.in new file mode 100644 index 00000000..ad093b97 --- /dev/null +++ b/t/snippets/align25.in @@ -0,0 +1,5 @@ +# do not align commas here; different container types +is_deeply( [ $a, $a ], [ $b, $c ] ); +is_deeply( { foo => $a, bar => $a }, { foo => $b, bar => $c } ); +is_deeply( [ \$a, \$a ], [ \$b, \$c ] ); + diff --git a/t/snippets/align26.in b/t/snippets/align26.in new file mode 100644 index 00000000..f8a5db8b --- /dev/null +++ b/t/snippets/align26.in @@ -0,0 +1,3 @@ +# align first of multiple equals +$SIG{PIPE}=sub{die"writingtoaclosedpipe"};#1= +$SIG{HUP}=$SIG{BREAK}=$SIG{INT}=$SIG{TERM};#3= diff --git a/t/snippets/align27.in b/t/snippets/align27.in new file mode 100644 index 00000000..80ff92b0 --- /dev/null +++ b/t/snippets/align27.in @@ -0,0 +1,4 @@ +# do not align first equals here (unmatched commas on left side of =) +my ( $self, $name, $type ) = @_; +my $html_toc_fh = $self->{_html_toc_fh}; +my $html_prelim_fh = $self->{_html_prelim_fh}; diff --git a/t/snippets/else1.in b/t/snippets/else1.in new file mode 100644 index 00000000..981ec27e --- /dev/null +++ b/t/snippets/else1.in @@ -0,0 +1,4 @@ +# pad after 'if' when followed by 'elsif' +if ( not defined $dir or not length $dir ) { $rslt = ''; } +elsif ( $dir =~ /^\$\([^\)]+\)\Z(?!\n)/s ) { $rslt = $dir; } +else { $rslt = vmspath($dir); } diff --git a/t/snippets/else2.in b/t/snippets/else2.in new file mode 100644 index 00000000..b9f934c6 --- /dev/null +++ b/t/snippets/else2.in @@ -0,0 +1,3 @@ + # no pad after 'if' when followed by 'else' + if ( $m = $g[$x][$y] ) { print $$m{v}; $$m{i}->() } + else { print " " } diff --git a/t/snippets/expect/align12.def b/t/snippets/expect/align12.def index 74150550..7d52a648 100644 --- a/t/snippets/expect/align12.def +++ b/t/snippets/expect/align12.def @@ -1,3 +1,3 @@ - my $type = shift || "o"; - my $fname = ( $type eq 'oo' ? 'orte_city' : 'orte' ); + my $type = shift || "o"; + my $fname = ( $type eq 'oo' ? 'orte_city' : 'orte' ); my $suffix = ( $coord_system eq 'standard' ? '' : '-orig' ); diff --git a/t/snippets/expect/align24.def b/t/snippets/expect/align24.def new file mode 100644 index 00000000..8e3bf60e --- /dev/null +++ b/t/snippets/expect/align24.def @@ -0,0 +1,7 @@ +# Do not align interior fat commas here; differnt container types +my $p = TAP::Parser::SubclassTest->new( + { + exec => [ $cat => $file ], + sources => { MySourceHandler => { accept_all => 1 } }, + } +); diff --git a/t/snippets/expect/align25.def b/t/snippets/expect/align25.def new file mode 100644 index 00000000..72d462cf --- /dev/null +++ b/t/snippets/expect/align25.def @@ -0,0 +1,5 @@ +# do not align commas here; different container types +is_deeply( [ $a, $a ], [ $b, $c ] ); +is_deeply( { foo => $a, bar => $a }, { foo => $b, bar => $c } ); +is_deeply( [ \$a, \$a ], [ \$b, \$c ] ); + diff --git a/t/snippets/expect/align26.def b/t/snippets/expect/align26.def new file mode 100644 index 00000000..8e0ceef0 --- /dev/null +++ b/t/snippets/expect/align26.def @@ -0,0 +1,3 @@ +# align first of multiple equals +$SIG{PIPE} = sub { die "writingtoaclosedpipe" }; #1= +$SIG{HUP} = $SIG{BREAK} = $SIG{INT} = $SIG{TERM}; #3= diff --git a/t/snippets/expect/align27.def b/t/snippets/expect/align27.def new file mode 100644 index 00000000..038630df --- /dev/null +++ b/t/snippets/expect/align27.def @@ -0,0 +1,4 @@ +# do not align first equals here (unmatched commas on left side of =) +my ( $self, $name, $type ) = @_; +my $html_toc_fh = $self->{_html_toc_fh}; +my $html_prelim_fh = $self->{_html_prelim_fh}; diff --git a/t/snippets/expect/else1.def b/t/snippets/expect/else1.def new file mode 100644 index 00000000..981ec27e --- /dev/null +++ b/t/snippets/expect/else1.def @@ -0,0 +1,4 @@ +# pad after 'if' when followed by 'elsif' +if ( not defined $dir or not length $dir ) { $rslt = ''; } +elsif ( $dir =~ /^\$\([^\)]+\)\Z(?!\n)/s ) { $rslt = $dir; } +else { $rslt = vmspath($dir); } diff --git a/t/snippets/expect/else2.def b/t/snippets/expect/else2.def new file mode 100644 index 00000000..4b9d9459 --- /dev/null +++ b/t/snippets/expect/else2.def @@ -0,0 +1,3 @@ + # no pad after 'if' when followed by 'else' + if ( $m = $g[$x][$y] ) { print $$m{v}; $$m{i}->() } + else { print " " } diff --git a/t/snippets/expect/smart.def b/t/snippets/expect/smart.def index 41b03cdf..cf1600c5 100644 --- a/t/snippets/expect/smart.def +++ b/t/snippets/expect/smart.def @@ -46,20 +46,20 @@ b_const ~~ a_const; [ keys %main:: ] ~~ \%::; \%:: ~~ []; [] ~~ \%::; -{ "" => 1 } ~~ [undef]; -[undef] ~~ { "" => 1 }; -{ foo => 1 } ~~ qr/^(fo[ox])$/; -qr/^(fo[ox])$/ ~~ { foo => 1 }; -+{ 0 .. 100 } ~~ qr/[13579]$/; -qr/[13579]$/ ~~ +{ 0 .. 100 }; +{ "" => 1 } ~~ [undef]; +[undef] ~~ { "" => 1 }; +{ foo => 1 } ~~ qr/^(fo[ox])$/; +qr/^(fo[ox])$/ ~~ { foo => 1 }; ++{ 0 .. 100 } ~~ qr/[13579]$/; +qr/[13579]$/ ~~ +{ 0 .. 100 }; +{ foo => 1, bar => 2 } ~~ "foo"; "foo" ~~ +{ foo => 1, bar => 2 }; +{ foo => 1, bar => 2 } ~~ "baz"; "baz" ~~ +{ foo => 1, bar => 2 }; -[] ~~ []; -[] ~~ []; -[] ~~ [1]; -[1] ~~ []; +[] ~~ []; +[] ~~ []; +[] ~~ [1]; +[1] ~~ []; [ ["foo"], ["bar"] ] ~~ [ qr/o/, qr/a/ ]; [ qr/o/, qr/a/ ] ~~ [ ["foo"], ["bar"] ]; [ "foo", "bar" ] ~~ [ qr/o/, qr/a/ ]; diff --git a/t/snippets14.t b/t/snippets14.t new file mode 100644 index 00000000..013585ee --- /dev/null +++ b/t/snippets14.t @@ -0,0 +1,121 @@ +# Created with: ./make_t.pl + +# Contents: +#1 else1.def +#2 else2.def + +# To locate test #13 you can search for its name or the string '#13' + +use strict; +use Test; +use Carp; +use Perl::Tidy; +my $rparams; +my $rsources; +my $rtests; + +BEGIN { + + ########################################### + # BEGIN SECTION 1: Parameter combinations # + ########################################### + $rparams = { 'def' => "", }; + + ############################ + # BEGIN SECTION 2: Sources # + ############################ + $rsources = { + + 'else1' => <<'----------', +# pad after 'if' when followed by 'elsif' +if ( not defined $dir or not length $dir ) { $rslt = ''; } +elsif ( $dir =~ /^\$\([^\)]+\)\Z(?!\n)/s ) { $rslt = $dir; } +else { $rslt = vmspath($dir); } +---------- + + 'else2' => <<'----------', + # no pad after 'if' when followed by 'else' + if ( $m = $g[$x][$y] ) { print $$m{v}; $$m{i}->() } + else { print " " } +---------- + }; + + #################################### + # BEGIN SECTION 3: Expected output # + #################################### + $rtests = { + + 'else1.def' => { + source => "else1", + params => "def", + expect => <<'#1...........', +# pad after 'if' when followed by 'elsif' +if ( not defined $dir or not length $dir ) { $rslt = ''; } +elsif ( $dir =~ /^\$\([^\)]+\)\Z(?!\n)/s ) { $rslt = $dir; } +else { $rslt = vmspath($dir); } +#1........... + }, + + 'else2.def' => { + source => "else2", + params => "def", + expect => <<'#2...........', + # no pad after 'if' when followed by 'else' + if ( $m = $g[$x][$y] ) { print $$m{v}; $$m{i}->() } + else { print " " } +#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 ) { + if ($err) { + print STDERR +"This error received calling Perl::Tidy with '$sname' + '$pname'\n"; + ok( !$err ); + } + if ($stderr_string) { + print STDERR "---------------------\n"; + print STDERR "<>\n$stderr_string\n"; + print STDERR "---------------------\n"; + print STDERR +"This error received calling Perl::Tidy with '$sname' + '$pname'\n"; + ok( !$stderr_string ); + } + if ($errorfile_string) { + print STDERR "---------------------\n"; + print STDERR "<<.ERR file>>\n$errorfile_string\n"; + print STDERR "---------------------\n"; + print STDERR +"This error received calling Perl::Tidy with '$sname' + '$pname'\n"; + ok( !$errorfile_string ); + } + } + else { + ok( $output, $expect ); + } +} -- 2.39.5