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' => <<'----------',
176 'wngnu1' => <<'----------',
178 foreach my $parameter (
183 maximum_violations_per_document
189 $config->get($parameter),
191 qq<"$parameter" is not defined via get() for $policy_short_name.>,
197 ####################################
198 # BEGIN SECTION 3: Expected output #
199 ####################################
205 expect => <<'#1...........',
206 # side comments limit gnu type formatting with l=80; note extra comma
208 "Lowest code point requiring 13 bytes to represent", # 2**36
209 "\xff\x80\x80\x80\x80\x80\x81\x80\x80\x80\x80\x80\x80",
210 ($::is64bit) ? 0x1000000000 : -1, # overflows on 32bit
219 expect => <<'#2...........',
221 foreach my $parameter (
226 maximum_violations_per_document
232 $config->get($parameter),
234 qq<"$parameter" is not defined via get() for $policy_short_name.>,
243 expect => <<'#3...........',
244 for $x ( 1, 2 ) { s/(.*)/+$1/ }
245 for $x ( 1, 2 ) { s/(.*)/+$1/ } # side comment
246 if ( $editlblk eq 1 ) { $editlblk = "on"; $editlblkchecked = "checked" }
247 for $x ( 1, 2 ) { s/(.*)/+$1/; }
248 for $x ( 1, 2 ) { s/(.*)/+$1/; } # side comment
249 if ( $editlblk eq 1 ) { $editlblk = "on"; $editlblkchecked = "checked"; }
256 expect => <<'#4...........',
257 for $x ( 1, 2 ) { s/(.*)/+$1/ }
258 for $x ( 1, 2 ) { s/(.*)/+$1/ } # side comment
259 if ( $editlblk eq 1 ) { $editlblk = "on"; $editlblkchecked = "checked" }
260 for $x ( 1, 2 ) { s/(.*)/+$1/ }
261 for $x ( 1, 2 ) { s/(.*)/+$1/ } # side comment
262 if ( $editlblk eq 1 ) { $editlblk = "on"; $editlblkchecked = "checked"; }
269 expect => <<'#5...........',
270 for $x ( 1, 2 ) { s/(.*)/+$1/; }
271 for $x ( 1, 2 ) { s/(.*)/+$1/; } # side comment
272 if ( $editlblk eq 1 ) { $editlblk = "on"; $editlblkchecked = "checked"; }
273 for $x ( 1, 2 ) { s/(.*)/+$1/; }
274 for $x ( 1, 2 ) { s/(.*)/+$1/; } # side comment
275 if ( $editlblk eq 1 ) { $editlblk = "on"; $editlblkchecked = "checked"; }
279 'break_old_methods.break_old_methods' => {
280 source => "break_old_methods",
281 params => "break_old_methods",
282 expect => <<'#6...........',
284 ->related_resultset('CDs')
285 ->related_resultset('Tracks')
288 'track.id' => { -ident => 'none_search.id' },
294 'break_old_methods.def' => {
295 source => "break_old_methods",
297 expect => <<'#7...........',
298 my $q = $rs->related_resultset('CDs')->related_resultset('Tracks')->search(
300 'track.id' => { -ident => 'none_search.id' },
309 expect => <<'#8...........',
310 # keep cuddled call chain with -bom
311 return Mojo::Promise->resolve(
315 )->then( sub ($code) {
316 return $c->render( text => '', status => $code );
320 return $c->render( json => {}, status => 400 );
328 expect => <<'#9...........',
329 # keep cuddled call chain with -bom
330 return Mojo::Promise->resolve($query_params)->then(&_reveal_event)->then(
332 return $c->render( text => '', status => $code );
337 return $c->render( json => {}, status => 400 );
346 expect => <<'#10...........',
347 # tests for 'delete_needless_parens'
348 # align all '='s; but do not align parens
349 my $w = $columns * $cell_w + ( $columns + 1 ) * $border;
350 my $h = $rows * $cell_h + ( $rows + 1 ) * $border;
351 my $img = new Gimp::Image( $w, $h, RGB );
353 # keep leading paren after if as alignment for padding
355 if ( $a->{'abc'} eq 'ABC' ) { no_op(23) }
364 expect => <<'#11...........',
365 # alignment with lots of commas
366 is( floor(1.23441242), 1, "Basic floor(1.23441242) test" );
367 is( fmod( 3.5, 2.0 ), 1.5, "Basic fmod(3.5, 2.0) test" );
368 is( join( " ", frexp(1) ), "0.5 1", "Basic frexp(1) test" );
369 is( ldexp( 0, 1 ), 0, "Basic ldexp(0,1) test" );
370 is( log10(1), 0, "Basic log10(1) test" );
377 expect => <<'#12...........',
378 # commas on lhs align, commas on rhs do not (different subs)
379 ( $x, $y, $z ) = spherical_to_cartesian( $rho, $theta, $phi );
380 ( $rho_c, $theta, $z ) = spherical_to_cylindrical( $rho_s, $theta, $phi );
381 ( $r2, $theta2, $z2 ) = cartesian_to_cylindrical( $x1, $y1, $z1 );
383 # two-line if/elsif gets aligned
384 if ( $i == $depth ) { $_++; }
385 elsif ( $i > $depth ) { $_ = 0; }
392 expect => <<'#13...........',
393 # no one-line block for first map with -ce -cbl=map,sort,grep
396 sort { $a->[1] <=> $b->[1] or $a->[0] cmp $b->[0] }
397 map { [ $_, length($_) ] } @unsorted;
404 expect => <<'#14...........',
405 # no one-line block for first map with -ce -cbl=map,sort,grep
409 $a->[1] <=> $b->[1] or $a->[0] cmp $b->[0]
419 expect => <<'#15...........',
420 # git#14; do not break at trailing 'or'
424 } if $flag1 or $flag2;
431 expect => <<'#16...........',
440 fun get_other_value() {
449 expect => <<'#17...........',
454 method get_value () {
458 fun get_other_value () {
467 expect => <<'#18...........',
479 expect => <<'#19...........',
489 my $ntests = 0 + keys %{$rtests};
490 plan tests => $ntests;
497 foreach my $key ( sort keys %{$rtests} ) {
499 my $sname = $rtests->{$key}->{source};
500 my $expect = $rtests->{$key}->{expect};
501 my $pname = $rtests->{$key}->{params};
502 my $source = $rsources->{$sname};
503 my $params = defined($pname) ? $rparams->{$pname} : "";
505 my $errorfile_string;
506 my $err = Perl::Tidy::perltidy(
508 destination => \$output,
509 perltidyrc => \$params,
510 argv => '', # for safety; hide any ARGV from perltidy
511 stderr => \$stderr_string,
512 errorfile => \$errorfile_string, # not used when -se flag is set
514 if ( $err || $stderr_string || $errorfile_string ) {
517 "This error received calling Perl::Tidy with '$sname' + '$pname'\n";
520 if ($stderr_string) {
521 print STDERR "---------------------\n";
522 print STDERR "<<STDERR>>\n$stderr_string\n";
523 print STDERR "---------------------\n";
525 "This error received calling Perl::Tidy with '$sname' + '$pname'\n";
526 ok( !$stderr_string );
528 if ($errorfile_string) {
529 print STDERR "---------------------\n";
530 print STDERR "<<.ERR file>>\n$errorfile_string\n";
531 print STDERR "---------------------\n";
533 "This error received calling Perl::Tidy with '$sname' + '$pname'\n";
534 ok( !$errorfile_string );
538 ok( $output, $expect );