1 # Created with: ./make_t.pl
9 #6 break_old_methods.break_old_methods
10 #7 break_old_methods.def
24 # To locate test #13 you can search for its name or the string '#13'
36 ###########################################
37 # BEGIN SECTION 1: Parameter combinations #
38 ###########################################
41 'break_old_methods' => "--break-at-old-method-breakpoints",
43 'git09' => "-ce -cbl=map,sort,grep",
47 'sal' => <<'----------',
53 ############################
54 # BEGIN SECTION 2: Sources #
55 ############################
58 'align28' => <<'----------',
59 # tests for 'delete_needless_parens'
60 # align all '='s; but do not align parens
61 my $w = $columns * $cell_w + ( $columns + 1 ) * $border;
62 my $h = $rows * $cell_h + ( $rows + 1 ) * $border;
63 my $img = new Gimp::Image( $w, $h, RGB );
65 # keep leading paren after if as alignment for padding
67 if ( $a->{'abc'} eq 'ABC' ) { no_op(23) }
72 'align29' => <<'----------',
73 # alignment with lots of commas
74 is( floor(1.23441242), 1, "Basic floor(1.23441242) test" );
75 is( fmod( 3.5, 2.0 ), 1.5, "Basic fmod(3.5, 2.0) test" );
76 is( join( " ", frexp(1) ), "0.5 1", "Basic frexp(1) test" );
77 is( ldexp( 0, 1 ), 0, "Basic ldexp(0,1) test" );
78 is( log10(1), 0, "Basic log10(1) test" );
81 'align30' => <<'----------',
82 # commas on lhs align, commas on rhs do not (different subs)
83 ($x,$y,$z)=spherical_to_cartesian($rho,$theta,$phi);
84 ($rho_c,$theta,$z)=spherical_to_cylindrical($rho_s,$theta,$phi);
85 ( $r2, $theta2, $z2 )=cartesian_to_cylindrical( $x1, $y1, $z1 );
87 # two-line if/elsif gets aligned
89 elsif($i>$depth){$_=0;}
92 'bom1' => <<'----------',
93 # keep cuddled call chain with -bom
94 return Mojo::Promise->resolve(
99 return $c->render(text => '', status => $code);
102 return $c->render(json => {}, status => 400);
106 'break_old_methods' => <<'----------',
108 ->related_resultset('CDs')
109 ->related_resultset('Tracks')
111 'track.id' => { -ident => 'none_search.id' },
116 'git09' => <<'----------',
117 # no one-line block for first map with -ce -cbl=map,sort,grep
121 $a->[1] <=> $b->[1] or $a->[0] cmp $b->[0]
127 'git14' => <<'----------',
128 # git#14; do not break at trailing 'or'
132 } if $flag1 or $flag2;
135 'gnu5' => <<'----------',
136 # side comments limit gnu type formatting with l=80; note extra comma
138 "Lowest code point requiring 13 bytes to represent", # 2**36
139 "\xff\x80\x80\x80\x80\x80\x81\x80\x80\x80\x80\x80\x80",
140 ($::is64bit) ? 0x1000000000 : -1, # overflows on 32bit
145 'olbs' => <<'----------',
146 for $x ( 1, 2 ) { s/(.*)/+$1/ }
147 for $x ( 1, 2 ) { s/(.*)/+$1/ } # side comment
148 if ( $editlblk eq 1 ) { $editlblk = "on"; $editlblkchecked = "checked" }
149 for $x ( 1, 2 ) { s/(.*)/+$1/; }
150 for $x ( 1, 2 ) { s/(.*)/+$1/; } # side comment
151 if ( $editlblk eq 1 ) { $editlblk = "on"; $editlblkchecked = "checked"; }
154 'sal' => <<'----------',
159 method get_value () {
163 fun get_other_value () {
168 'spp' => <<'----------',
178 'wngnu1' => <<'----------',
180 foreach my $parameter (
185 maximum_violations_per_document
191 $config->get($parameter),
193 qq<"$parameter" is not defined via get() for $policy_short_name.>,
199 ####################################
200 # BEGIN SECTION 3: Expected output #
201 ####################################
207 expect => <<'#1...........',
208 # side comments limit gnu type formatting with l=80; note extra comma
210 "Lowest code point requiring 13 bytes to represent", # 2**36
211 "\xff\x80\x80\x80\x80\x80\x81\x80\x80\x80\x80\x80\x80",
212 ($::is64bit) ? 0x1000000000 : -1, # overflows on 32bit
221 expect => <<'#2...........',
223 foreach my $parameter (
228 maximum_violations_per_document
234 $config->get($parameter),
236 qq<"$parameter" is not defined via get() for $policy_short_name.>,
245 expect => <<'#3...........',
246 for $x ( 1, 2 ) { s/(.*)/+$1/ }
247 for $x ( 1, 2 ) { s/(.*)/+$1/ } # side comment
248 if ( $editlblk eq 1 ) { $editlblk = "on"; $editlblkchecked = "checked" }
249 for $x ( 1, 2 ) { s/(.*)/+$1/; }
250 for $x ( 1, 2 ) { s/(.*)/+$1/; } # side comment
251 if ( $editlblk eq 1 ) { $editlblk = "on"; $editlblkchecked = "checked"; }
258 expect => <<'#4...........',
259 for $x ( 1, 2 ) { s/(.*)/+$1/ }
260 for $x ( 1, 2 ) { s/(.*)/+$1/ } # side comment
261 if ( $editlblk eq 1 ) { $editlblk = "on"; $editlblkchecked = "checked" }
262 for $x ( 1, 2 ) { s/(.*)/+$1/ }
263 for $x ( 1, 2 ) { s/(.*)/+$1/ } # side comment
264 if ( $editlblk eq 1 ) { $editlblk = "on"; $editlblkchecked = "checked"; }
271 expect => <<'#5...........',
272 for $x ( 1, 2 ) { s/(.*)/+$1/; }
273 for $x ( 1, 2 ) { s/(.*)/+$1/; } # side comment
274 if ( $editlblk eq 1 ) { $editlblk = "on"; $editlblkchecked = "checked"; }
275 for $x ( 1, 2 ) { s/(.*)/+$1/; }
276 for $x ( 1, 2 ) { s/(.*)/+$1/; } # side comment
277 if ( $editlblk eq 1 ) { $editlblk = "on"; $editlblkchecked = "checked"; }
281 'break_old_methods.break_old_methods' => {
282 source => "break_old_methods",
283 params => "break_old_methods",
284 expect => <<'#6...........',
286 ->related_resultset('CDs')
287 ->related_resultset('Tracks')
290 'track.id' => { -ident => 'none_search.id' },
296 'break_old_methods.def' => {
297 source => "break_old_methods",
299 expect => <<'#7...........',
300 my $q = $rs->related_resultset('CDs')->related_resultset('Tracks')->search(
302 'track.id' => { -ident => 'none_search.id' },
311 expect => <<'#8...........',
312 # keep cuddled call chain with -bom
313 return Mojo::Promise->resolve(
317 )->then( sub ($code) {
318 return $c->render( text => '', status => $code );
322 return $c->render( json => {}, status => 400 );
330 expect => <<'#9...........',
331 # keep cuddled call chain with -bom
332 return Mojo::Promise->resolve($query_params)->then(&_reveal_event)->then(
334 return $c->render( text => '', status => $code );
339 return $c->render( json => {}, status => 400 );
348 expect => <<'#10...........',
349 # tests for 'delete_needless_parens'
350 # align all '='s; but do not align parens
351 my $w = $columns * $cell_w + ( $columns + 1 ) * $border;
352 my $h = $rows * $cell_h + ( $rows + 1 ) * $border;
353 my $img = new Gimp::Image( $w, $h, RGB );
355 # keep leading paren after if as alignment for padding
357 if ( $a->{'abc'} eq 'ABC' ) { no_op(23) }
366 expect => <<'#11...........',
367 # alignment with lots of commas
368 is( floor(1.23441242), 1, "Basic floor(1.23441242) test" );
369 is( fmod( 3.5, 2.0 ), 1.5, "Basic fmod(3.5, 2.0) test" );
370 is( join( " ", frexp(1) ), "0.5 1", "Basic frexp(1) test" );
371 is( ldexp( 0, 1 ), 0, "Basic ldexp(0,1) test" );
372 is( log10(1), 0, "Basic log10(1) test" );
379 expect => <<'#12...........',
380 # commas on lhs align, commas on rhs do not (different subs)
381 ( $x, $y, $z ) = spherical_to_cartesian( $rho, $theta, $phi );
382 ( $rho_c, $theta, $z ) = spherical_to_cylindrical( $rho_s, $theta, $phi );
383 ( $r2, $theta2, $z2 ) = cartesian_to_cylindrical( $x1, $y1, $z1 );
385 # two-line if/elsif gets aligned
386 if ( $i == $depth ) { $_++; }
387 elsif ( $i > $depth ) { $_ = 0; }
394 expect => <<'#13...........',
395 # no one-line block for first map with -ce -cbl=map,sort,grep
398 sort { $a->[1] <=> $b->[1] or $a->[0] cmp $b->[0] }
399 map { [ $_, length($_) ] } @unsorted;
406 expect => <<'#14...........',
407 # no one-line block for first map with -ce -cbl=map,sort,grep
411 $a->[1] <=> $b->[1] or $a->[0] cmp $b->[0]
421 expect => <<'#15...........',
422 # git#14; do not break at trailing 'or'
426 } if $flag1 or $flag2;
433 expect => <<'#16...........',
442 fun get_other_value() {
451 expect => <<'#17...........',
456 method get_value () {
460 fun get_other_value () {
469 expect => <<'#18...........',
475 my $sub1 = sub () { };
476 my $sub2 = sub () { };
483 expect => <<'#19...........',
489 my $sub1 = sub() { };
490 my $sub2 = sub() { };
495 my $ntests = 0 + keys %{$rtests};
496 plan tests => $ntests;
503 foreach my $key ( sort keys %{$rtests} ) {
505 my $sname = $rtests->{$key}->{source};
506 my $expect = $rtests->{$key}->{expect};
507 my $pname = $rtests->{$key}->{params};
508 my $source = $rsources->{$sname};
509 my $params = defined($pname) ? $rparams->{$pname} : "";
511 my $errorfile_string;
512 my $err = Perl::Tidy::perltidy(
514 destination => \$output,
515 perltidyrc => \$params,
516 argv => '', # for safety; hide any ARGV from perltidy
517 stderr => \$stderr_string,
518 errorfile => \$errorfile_string, # not used when -se flag is set
520 if ( $err || $stderr_string || $errorfile_string ) {
521 print STDERR "Error output received for test '$key'\n";
523 print STDERR "An error flag '$err' was returned\n";
526 if ($stderr_string) {
527 print STDERR "---------------------\n";
528 print STDERR "<<STDERR>>\n$stderr_string\n";
529 print STDERR "---------------------\n";
530 ok( !$stderr_string );
532 if ($errorfile_string) {
533 print STDERR "---------------------\n";
534 print STDERR "<<.ERR file>>\n$errorfile_string\n";
535 print STDERR "---------------------\n";
536 ok( !$errorfile_string );
540 if ( !is( $output, $expect, $key ) ) {
541 my $leno = length($output);
542 my $lene = length($expect);
543 if ( $leno == $lene ) {
545 "#> Test '$key' gave unexpected output. Strings differ but both have length $leno\n";
549 "#> Test '$key' gave unexpected output. String lengths differ: output=$leno, expected=$lene\n";