1 # Created with: ./make_t.pl
25 # To locate test #13 you can search for its name or the string '#13'
37 ###########################################
38 # BEGIN SECTION 1: Parameter combinations #
39 ###########################################
44 'style1' => <<'----------',
61 -wbb="% + - * / x != == >= <= =~ < > | & **= += *= &= <<= &&= -= /= |= >>= ||= .= %= ^= x="
64 'style2' => <<'----------',
76 'style3' => <<'----------',
91 'style4' => <<'----------',
98 'style5' => <<'----------',
119 -wrs="= .= =~ !~ ? :"
128 -wba="% + - * / x != == >= <= =~ !~ < > | & >= < = **= += *= &= <<= &&= -= /= |= >>= ||= .= %= ^= x= . << >> -> && ||"
135 ############################
136 # BEGIN SECTION 2: Sources #
137 ############################
140 'scl' => <<'----------',
141 # try -scl=12 to see '$returns' joined with the previous line
142 $format = "format STDOUT =\n" . &format_line('Function: @') . '$name' . "\n" . &format_line('Arguments: @') . '$args' . "\n" . &format_line('Returns: @') . '$returns' . "\n" . &format_line(' ~~ ^') . '$desc' . "\n.\n";
145 'semicolon2' => <<'----------',
146 # will not add semicolon for this block type
147 $highest = List::Util::reduce { Sort::Versions::versioncmp( $a, $b ) > 0 ? $a : $b }
150 'side_comments1' => <<'----------',
151 # side comments at different indentation levels should not be aligned
152 { { { { { ${msg} = "Hello World!"; print "My message: ${msg}\n"; } } #end level 4
158 'sil1' => <<'----------',
159 #############################################################
160 # This will walk to the left because of bad -sil guess
162 #############################################################
165 # This will walk to the right if it is the first line of a file.
167 ov_method mycan( $package, '(""' ), $package
168 or ov_method mycan( $package, '(0+' ), $package
169 or ov_method mycan( $package, '(bool' ), $package
170 or ov_method mycan( $package, '(nomethod' ), $package;
174 'slashslash' => <<'----------',
175 $home = $ENV{HOME} // $ENV{LOGDIR} // ( getpwuid($<) )[7]
176 // die "You're homeless!\n";
178 $version = 'v' . join '.', map ord, split //, $version->PV;
179 foreach ( split( //, $lets ) ) { }
180 foreach ( split( //, $input ) ) { }
184 'smart' => <<'----------',
204 a_const ~~ "a constant";
205 "a constant" ~~ a_const;
214 {1 => 2} ~~ {1 => 2};
215 {1 => 2} ~~ {1 => 2};
216 {1 => 2} ~~ {1 => 3};
217 {1 => 3} ~~ {1 => 2};
218 {1 => 2} ~~ {2 => 3};
219 {2 => 3} ~~ {1 => 2};
220 \%main:: ~~ {map {$_ => 'x'} keys %main::};
221 {map {$_ => 'x'} keys %main::} ~~ \%main::;
222 \%hash ~~ \%tied_hash;
223 \%tied_hash ~~ \%hash;
224 \%tied_hash ~~ \%tied_hash;
225 \%tied_hash ~~ \%tied_hash;
226 \%:: ~~ [keys %main::];
227 [keys %main::] ~~ \%::;
230 {"" => 1} ~~ [undef];
231 [undef] ~~ {"" => 1};
232 {foo => 1} ~~ qr/^(fo[ox])$/;
233 qr/^(fo[ox])$/ ~~ {foo => 1};
234 +{0..100} ~~ qr/[13579]$/;
235 qr/[13579]$/ ~~ +{0..100};
236 +{foo => 1, bar => 2} ~~ "foo";
237 "foo" ~~ +{foo => 1, bar => 2};
238 +{foo => 1, bar => 2} ~~ "baz";
239 "baz" ~~ +{foo => 1, bar => 2};
244 [["foo"], ["bar"]] ~~ [qr/o/, qr/a/];
245 [qr/o/, qr/a/] ~~ [["foo"], ["bar"]];
246 ["foo", "bar"] ~~ [qr/o/, qr/a/];
247 [qr/o/, qr/a/] ~~ ["foo", "bar"];
252 \@nums ~~ \@tied_nums;
253 \@tied_nums ~~ \@nums;
254 [qw(foo bar baz quux)] ~~ qr/x/;
255 qr/x/ ~~ [qw(foo bar baz quux)];
256 [qw(foo bar baz quux)] ~~ qr/y/;
257 qr/y/ ~~ [qw(foo bar baz quux)];
258 [qw(1foo 2bar)] ~~ 2;
259 2 ~~ [qw(1foo 2bar)];
260 [qw(1foo 2bar)] ~~ "2";
261 "2" ~~ [qw(1foo 2bar)];
296 'space1' => <<'----------',
297 # We usually want a space at '} (', for example:
298 map { 1 * $_; } ( $y, $M, $w, $d, $h, $m, $s );
301 &{ $_->[1] }( delete $_[$#_]{ $_->[0] } );
303 # remove unwanted spaces after $ and -> here
304 &{ $ _ -> [1] }( delete $ _ [$#_ ]{ $_ -> [0] } );
307 'space2' => <<'----------',
308 # space before this opening paren
311 # retain any space between '-' and bare word
312 $myhash{USER-NAME}='steve';
315 'space3' => <<'----------',
316 # Treat newline as a whitespace. Otherwise, we might combine
317 # 'Send' and '-recipients' here
318 my $msg = new Fax::Send
323 'space4' => <<'----------',
324 # first prototype line will cause space between 'redirect' and '(' to close
325 sub html::redirect($); #<-- temporary prototype;
327 print html::redirect ('http://www.glob.com.au/');
330 'space5' => <<'----------',
331 # first prototype line commented out; space after 'redirect' remains
332 #sub html::redirect($); #<-- temporary prototype;
334 print html::redirect ('http://www.glob.com.au/');
338 'structure1' => <<'----------',
339 push@contents,$c->table({-width=>'100%'},$c->Tr($c->td({-align=>'left'},"The emboldened field names are mandatory, ","the remainder are optional",),$c->td({-align=>'right'},$c->a({-href=>'help.cgi',-target=>'_blank'},"What are the various fields?"))));
342 'style' => <<'----------',
343 # This test snippet is from package bbbike v3.214 by Slaven Rezic; GPL 2.0 licence
344 sub arrange_topframe {
345 my(@order) = ($hslabel_frame, $km_frame, $speed_frame[0],
346 $power_frame[0], $wind_frame, $percent_frame, $temp_frame,
347 @speed_frame[1..$#speed_frame],
348 @power_frame[1..$#power_frame],
350 my(@col) = (0, 1, 3, 4+$#speed_frame, 5+$#speed_frame+$#power_frame,
351 2, 6+$#speed_frame+$#power_frame,
353 5+$#speed_frame..4+$#speed_frame+$#power_frame);
356 my(%gridslaves) = map {($_, 1)} $top_frame->gridSlaves;
357 for(my $i = 0; $i <= $#order; $i++) {
359 next unless Tk::Exists($w);
360 my $col = $col[$i] || 0;
361 $width += $w->reqwidth;
362 if ($gridslaves{$w}) {
365 if ($width <= $top->width) {
368 -sticky => 'nsew'); # XXX
376 ####################################
377 # BEGIN SECTION 3: Expected output #
378 ####################################
384 expect => <<'#1...........',
385 # try -scl=12 to see '$returns' joined with the previous line
388 . &format_line('Function: @') . '$name' . "\n"
389 . &format_line('Arguments: @') . '$args' . "\n"
390 . &format_line('Returns: @')
392 . &format_line(' ~~ ^') . '$desc' . "\n.\n";
399 expect => <<'#2...........',
400 # try -scl=12 to see '$returns' joined with the previous line
403 . &format_line('Function: @') . '$name' . "\n"
404 . &format_line('Arguments: @') . '$args' . "\n"
405 . &format_line('Returns: @') . '$returns' . "\n"
406 . &format_line(' ~~ ^') . '$desc' . "\n.\n";
410 'semicolon2.def' => {
411 source => "semicolon2",
413 expect => <<'#3...........',
414 # will not add semicolon for this block type
415 $highest = List::Util::reduce {
416 Sort::Versions::versioncmp( $a, $b ) > 0 ? $a : $b
421 'side_comments1.def' => {
422 source => "side_comments1",
424 expect => <<'#4...........',
425 # side comments at different indentation levels should not be aligned
430 { ${msg} = "Hello World!"; print "My message: ${msg}\n"; }
441 expect => <<'#5...........',
442 #############################################################
443 # This will walk to the left because of bad -sil guess
445 #############################################################
448 # This will walk to the right if it is the first line of a file.
450 ov_method mycan( $package, '(""' ), $package
451 or ov_method mycan( $package, '(0+' ), $package
452 or ov_method mycan( $package, '(bool' ), $package
453 or ov_method mycan( $package, '(nomethod' ), $package;
461 expect => <<'#6...........',
462 #############################################################
463 # This will walk to the left because of bad -sil guess
465 #############################################################
468 # This will walk to the right if it is the first line of a file.
470 ov_method mycan( $package, '(""' ), $package
471 or ov_method mycan( $package, '(0+' ), $package
472 or ov_method mycan( $package, '(bool' ), $package
473 or ov_method mycan( $package, '(nomethod' ), $package;
478 'slashslash.def' => {
479 source => "slashslash",
481 expect => <<'#7...........',
482 $home = $ENV{HOME} // $ENV{LOGDIR} // ( getpwuid($<) )[7]
483 // die "You're homeless!\n";
485 $version = 'v' . join '.', map ord, split //, $version->PV;
486 foreach ( split( //, $lets ) ) { }
487 foreach ( split( //, $input ) ) { }
495 expect => <<'#8...........',
507 1 ~~ sub { scalar @_ };
508 sub { scalar @_ } ~~ 1;
515 a_const ~~ "a constant";
516 "a constant" ~~ a_const;
525 { 1 => 2 } ~~ { 1 => 2 };
526 { 1 => 2 } ~~ { 1 => 2 };
527 { 1 => 2 } ~~ { 1 => 3 };
528 { 1 => 3 } ~~ { 1 => 2 };
529 { 1 => 2 } ~~ { 2 => 3 };
530 { 2 => 3 } ~~ { 1 => 2 };
531 \%main:: ~~ { map { $_ => 'x' } keys %main:: };
533 map { $_ => 'x' } keys %main::
536 \%hash ~~ \%tied_hash;
537 \%tied_hash ~~ \%hash;
538 \%tied_hash ~~ \%tied_hash;
539 \%tied_hash ~~ \%tied_hash;
540 \%:: ~~ [ keys %main:: ];
541 [ keys %main:: ] ~~ \%::;
544 { "" => 1 } ~~ [undef];
545 [undef] ~~ { "" => 1 };
546 { foo => 1 } ~~ qr/^(fo[ox])$/;
547 qr/^(fo[ox])$/ ~~ { foo => 1 };
548 +{ 0 .. 100 } ~~ qr/[13579]$/;
549 qr/[13579]$/ ~~ +{ 0 .. 100 };
550 +{ foo => 1, bar => 2 } ~~ "foo";
551 "foo" ~~ +{ foo => 1, bar => 2 };
552 +{ foo => 1, bar => 2 } ~~ "baz";
553 "baz" ~~ +{ foo => 1, bar => 2 };
558 [ ["foo"], ["bar"] ] ~~ [ qr/o/, qr/a/ ];
559 [ qr/o/, qr/a/ ] ~~ [ ["foo"], ["bar"] ];
560 [ "foo", "bar" ] ~~ [ qr/o/, qr/a/ ];
561 [ qr/o/, qr/a/ ] ~~ [ "foo", "bar" ];
566 \@nums ~~ \@tied_nums;
567 \@tied_nums ~~ \@nums;
568 [qw(foo bar baz quux)] ~~ qr/x/;
569 qr/x/ ~~ [qw(foo bar baz quux)];
570 [qw(foo bar baz quux)] ~~ qr/y/;
571 qr/y/ ~~ [qw(foo bar baz quux)];
572 [qw(1foo 2bar)] ~~ 2;
573 2 ~~ [qw(1foo 2bar)];
574 [qw(1foo 2bar)] ~~ "2";
575 "2" ~~ [qw(1foo 2bar)];
600 @nums ~~ [ 1 .. 10 ];
601 [ 1 .. 10 ] ~~ @nums;
614 expect => <<'#9...........',
615 # We usually want a space at '} (', for example:
616 map { 1 * $_; } ( $y, $M, $w, $d, $h, $m, $s );
619 &{ $_->[1] }( delete $_[$#_]{ $_->[0] } );
621 # remove unwanted spaces after $ and -> here
622 &{ $_->[1] }( delete $_[$#_]{ $_->[0] } );
629 expect => <<'#10...........',
630 # space before this opening paren
631 for $i ( 0 .. 20 ) { }
633 # retain any space between '-' and bare word
634 $myhash{ USER-NAME } = 'steve';
641 expect => <<'#11...........',
642 # Treat newline as a whitespace. Otherwise, we might combine
643 # 'Send' and '-recipients' here
644 my $msg = new Fax::Send
653 expect => <<'#12...........',
654 # first prototype line will cause space between 'redirect' and '(' to close
655 sub html::redirect($); #<-- temporary prototype;
657 print html::redirect('http://www.glob.com.au/');
664 expect => <<'#13...........',
665 # first prototype line commented out; space after 'redirect' remains
666 #sub html::redirect($); #<-- temporary prototype;
668 print html::redirect ('http://www.glob.com.au/');
673 'structure1.def' => {
674 source => "structure1",
676 expect => <<'#14...........',
679 { -width => '100%' },
682 { -align => 'left' },
683 "The emboldened field names are mandatory, ",
684 "the remainder are optional",
687 { -align => 'right' },
689 { -href => 'help.cgi', -target => '_blank' },
690 "What are the various fields?"
701 expect => <<'#15...........',
702 # This test snippet is from package bbbike v3.214 by Slaven Rezic; GPL 2.0 licence
703 sub arrange_topframe {
712 @speed_frame[ 1 .. $#speed_frame ],
713 @power_frame[ 1 .. $#power_frame ],
720 5 + $#speed_frame + $#power_frame,
722 6 + $#speed_frame + $#power_frame,
723 4 .. 3 + $#speed_frame,
724 5 + $#speed_frame .. 4 + $#speed_frame + $#power_frame
728 my (%gridslaves) = map { ( $_, 1 ) } $top_frame->gridSlaves;
729 for ( my $i = 0 ; $i <= $#order ; $i++ ) {
731 next unless Tk::Exists($w);
732 my $col = $col[$i] || 0;
733 $width += $w->reqwidth;
734 if ( $gridslaves{$w} ) {
737 if ( $width <= $top->width ) {
753 expect => <<'#16...........',
754 # This test snippet is from package bbbike v3.214 by Slaven Rezic; GPL 2.0 licence
755 sub arrange_topframe {
757 $hslabel_frame, $km_frame, $speed_frame[0],
758 $power_frame[0], $wind_frame, $percent_frame, $temp_frame,
759 @speed_frame[1 .. $#speed_frame],
760 @power_frame[1 .. $#power_frame],
765 5 + $#speed_frame + $#power_frame,
767 6 + $#speed_frame + $#power_frame,
768 4 .. 3 + $#speed_frame,
769 5 + $#speed_frame .. 4 + $#speed_frame + $#power_frame
773 my (%gridslaves) = map { ($_, 1) } $top_frame->gridSlaves;
774 for (my $i = 0; $i <= $#order; $i++) {
776 next unless Tk::Exists($w);
777 my $col = $col[$i] || 0;
778 $width += $w->reqwidth;
779 if ($gridslaves{$w}) {
782 if ($width <= $top->width) {
798 expect => <<'#17...........',
799 # This test snippet is from package bbbike v3.214 by Slaven Rezic; GPL 2.0 licence
800 sub arrange_topframe {
802 $hslabel_frame, $km_frame,
803 $speed_frame[0], $power_frame[0],
804 $wind_frame, $percent_frame,
805 $temp_frame, @speed_frame[1..$#speed_frame],
806 @power_frame[1..$#power_frame],
813 5 + $#speed_frame + $#power_frame,
815 6 + $#speed_frame + $#power_frame,
816 4..3 + $#speed_frame,
817 5 + $#speed_frame..4 + $#speed_frame + $#power_frame
821 my (%gridslaves) = map { ($_, 1) } $top_frame->gridSlaves;
822 for (my $i = 0; $i <= $#order; $i++) {
824 next unless Tk::Exists($w);
825 my $col = $col[$i] || 0;
826 $width += $w->reqwidth;
827 if ($gridslaves{$w}) {
830 if ($width <= $top->width) {
846 expect => <<'#18...........',
847 # This test snippet is from package bbbike v3.214 by Slaven Rezic; GPL 2.0 licence
848 sub arrange_topframe {
850 $hslabel_frame, $km_frame, $speed_frame[0], $power_frame[0], $wind_frame, $percent_frame, $temp_frame,
851 @speed_frame[ 1 .. $#speed_frame ],
852 @power_frame[ 1 .. $#power_frame ],
857 5 + $#speed_frame + $#power_frame,
859 6 + $#speed_frame + $#power_frame,
860 4 .. 3 + $#speed_frame,
861 5 + $#speed_frame .. 4 + $#speed_frame + $#power_frame
865 my (%gridslaves) = map { ( $_, 1 ) } $top_frame->gridSlaves;
866 for ( my $i = 0 ; $i <= $#order ; $i++ ) {
868 next unless Tk::Exists($w);
869 my $col = $col[$i] || 0;
870 $width += $w->reqwidth;
871 if ( $gridslaves{$w} ) {
874 if ( $width <= $top->width ) {
882 } ## end sub arrange_topframe
890 expect => <<'#19...........',
891 # This test snippet is from package bbbike v3.214 by Slaven Rezic; GPL 2.0 licence
892 sub arrange_topframe {
894 $hslabel_frame, $km_frame,
895 $speed_frame[0], $power_frame[0],
896 $wind_frame, $percent_frame,
897 $temp_frame, @speed_frame[1 .. $#speed_frame],
898 @power_frame[1 .. $#power_frame],
905 5 + $#speed_frame + $#power_frame,
907 6 + $#speed_frame + $#power_frame,
908 4 .. 3 + $#speed_frame,
909 5 + $#speed_frame .. 4 + $#speed_frame + $#power_frame
913 my (%gridslaves) = map { ($_, 1) } $top_frame->gridSlaves;
914 for (my $i = 0 ; $i <= $#order ; $i++) {
916 next unless Tk::Exists($w);
917 my $col = $col[$i] || 0;
918 $width += $w->reqwidth;
919 if ($gridslaves{$w}) {
922 if ($width <= $top->width) {
938 expect => <<'#20...........',
939 # This test snippet is from package bbbike v3.214 by Slaven Rezic; GPL 2.0 licence
943 $hslabel_frame, $km_frame,
944 $speed_frame[0], $power_frame[0],
945 $wind_frame, $percent_frame,
946 $temp_frame, @speed_frame[1 .. $#speed_frame],
947 @power_frame[1 .. $#power_frame],
954 5 + $#speed_frame + $#power_frame,
956 6 + $#speed_frame + $#power_frame,
957 4 .. 3 + $#speed_frame,
958 5 + $#speed_frame .. 4 + $#speed_frame + $#power_frame
962 my (%gridslaves) = map { ($_, 1) } $top_frame->gridSlaves;
963 for (my $i = 0; $i <= $#order; $i++)
966 next unless Tk::Exists($w);
967 my $col = $col[$i] || 0;
968 $width += $w->reqwidth;
973 if ($width <= $top->width)
988 my $ntests = 0 + keys %{$rtests};
989 plan tests => $ntests;
996 foreach my $key ( sort keys %{$rtests} ) {
998 my $sname = $rtests->{$key}->{source};
999 my $expect = $rtests->{$key}->{expect};
1000 my $pname = $rtests->{$key}->{params};
1001 my $source = $rsources->{$sname};
1002 my $params = defined($pname) ? $rparams->{$pname} : "";
1004 my $errorfile_string;
1005 my $err = Perl::Tidy::perltidy(
1007 destination => \$output,
1008 perltidyrc => \$params,
1009 argv => '', # for safety; hide any ARGV from perltidy
1010 stderr => \$stderr_string,
1011 errorfile => \$errorfile_string, # not used when -se flag is set
1013 if ( $err || $stderr_string || $errorfile_string ) {
1016 "This error received calling Perl::Tidy with '$sname' + '$pname'\n";
1019 if ($stderr_string) {
1020 print STDERR "---------------------\n";
1021 print STDERR "<<STDERR>>\n$stderr_string\n";
1022 print STDERR "---------------------\n";
1024 "This error received calling Perl::Tidy with '$sname' + '$pname'\n";
1025 ok( !$stderr_string );
1027 if ($errorfile_string) {
1028 print STDERR "---------------------\n";
1029 print STDERR "<<.ERR file>>\n$errorfile_string\n";
1030 print STDERR "---------------------\n";
1032 "This error received calling Perl::Tidy with '$sname' + '$pname'\n";
1033 ok( !$errorfile_string );
1037 ok( $output, $expect );