Perl-Tidy
view release on metacpan or search on metacpan
t/snippets3.t view on Meta::CPAN
# and something like these could become ambiguous without space
# after the '-':
use constant III=>1;
$a = $b - III;
$a = - III;
# keep a space between a token ending in '$' and any word;
die @$ if $@;
# avoid combining tokens to create new meanings. Example:
# this must not become $a++$b
$a+ +$b;
# another example: do not combine these two &'s:
allow_options & &OPT_EXECCGI;
# Perl is sensitive to whitespace after the + here:
$b = xvals $a + 0.1 * yvals $a;
# keep paren separate here:
use Foo::Bar ();
# need space after foreach my; for example, this will fail in
# older versions of Perl:
foreach my$ft(@filetypes)...
# must retain space between grep and left paren; "grep(" may fail
my $match = grep (m/^-extrude$/, @list) ? 1 : 0;
# don't stick numbers next to left parens, as in:
use Mail::Internet 1.28 ();
# do not remove space between an '&' and a bare word because
# it may turn into a function evaluation, like here
# between '&' and 'O_ACCMODE', producing a syntax error [File.pm]
$opts{rdonly} = (($opts{mode} & O_ACCMODE) == O_RDONLY);
----------
'extrude1' => <<'----------',
# do not break before the ++
print $x++ . "\n";
----------
'extrude2' => <<'----------',
if (-l pid_filename()) {
return readlink(pid_filename());
}
----------
'extrude3' => <<'----------',
# Breaking before a ++ can cause perl to guess wrong
print( ( $i++ & 1 ) ? $_ : ( $change{$_} || $_ ) );
# Space between '&' and 'O_ACCMODE' is essential here
$opts{rdonly} = (($opts{mode} & O_ACCMODE) == O_RDONLY);
----------
'extrude4' => <<'----------',
# From Safe.pm caused trouble with extrude
use Opcode 1.01, qw(
opset opset_to_ops opmask_add
empty_opset full_opset invert_opset verify_opset
opdesc opcodes opmask define_optag opset_to_hex
);
----------
'fabrice_bug' => <<'----------',
# no space around ^variable with -bt=0
my $before = ${^PREMATCH};
my $after = ${PREMATCH};
----------
'format1' => <<'----------',
if (/^--list$/o) {
format =
@<<<<<<<<<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
$_, $val
.
print "Available strips:\n";
for ( split ( /\|/, $known_strips ) ) {
$val = $defs{$_}{'name'};
write;
}
}
----------
'given1' => <<'----------',
given ([9,"a",11]) {
when (qr/\d/) {
given ($count) {
when (1) { ok($count==1) }
else { ok($count!=1) }
when ([5,6]) { ok(0) } else { ok(1) }
}
}
ok(1) when 11;
}
----------
'gnu1' => <<'----------',
@common_sometimes = (
"aclocal.m4", "acconfig.h", "config.h.top", "config.h.bot",
"stamp-h.in", 'stamp-vti'
);
----------
};
####################################
# BEGIN SECTION 3: Expected output #
####################################
$rtests = {
'ce_wn1.ce_wn' => {
source => "ce_wn1",
params => "ce_wn",
expect => <<'#1...........',
if ($BOLD_MATH) { (
$labels, $comment,
join( '', ' < B > ', &make_math( $mode, '', '', $_ ), ' < /B>' )
) } else { (
&process_math_in_latex( $mode, $math_style, $slevel, "\\mbox{$text}" ),
$after
) }
t/snippets3.t view on Meta::CPAN
},
'extrude3.def' => {
source => "extrude3",
params => "def",
expect => <<'#12...........',
# Breaking before a ++ can cause perl to guess wrong
print( ( $i++ & 1 ) ? $_ : ( $change{$_} || $_ ) );
# Space between '&' and 'O_ACCMODE' is essential here
$opts{rdonly} = ( ( $opts{mode} & O_ACCMODE ) == O_RDONLY );
#12...........
},
'extrude3.extrude' => {
source => "extrude3",
params => "extrude",
expect => <<'#13...........',
# Breaking before a ++ can cause perl to guess wrong
print
(
(
$i++
&
1
)
?
$_
:
(
$change{
$_
}
||
$_
)
)
;
# Space between '&' and 'O_ACCMODE' is essential here
$opts{rdonly}
=
(
(
$opts{mode}
&
O_ACCMODE
)
==
O_RDONLY
)
;
#13...........
},
'extrude4.def' => {
source => "extrude4",
params => "def",
expect => <<'#14...........',
# From Safe.pm caused trouble with extrude
use Opcode 1.01, qw(
opset opset_to_ops opmask_add
empty_opset full_opset invert_opset verify_opset
opdesc opcodes opmask define_optag opset_to_hex
);
#14...........
},
'extrude4.extrude' => {
source => "extrude4",
params => "extrude",
expect => <<'#15...........',
# From Safe.pm caused trouble with extrude
use
Opcode
1.01
,
qw(
opset opset_to_ops opmask_add
empty_opset full_opset invert_opset verify_opset
opdesc opcodes opmask define_optag opset_to_hex
)
;
#15...........
},
'fabrice_bug.def' => {
source => "fabrice_bug",
params => "def",
expect => <<'#16...........',
# no space around ^variable with -bt=0
my $before = ${^PREMATCH};
my $after = ${PREMATCH};
#16...........
},
'fabrice_bug.fabrice_bug' => {
source => "fabrice_bug",
params => "fabrice_bug",
expect => <<'#17...........',
# no space around ^variable with -bt=0
my $before = ${^PREMATCH};
my $after = ${ PREMATCH };
#17...........
},
'format1.def' => {
source => "format1",
params => "def",
expect => <<'#18...........',
if (/^--list$/o) {
format =
@<<<<<<<<<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
$_, $val
.
print "Available strips:\n";
for ( split( /\|/, $known_strips ) ) {
$val = $defs{$_}{'name'};
write;
}
}
#18...........
},
'given1.def' => {
source => "given1",
params => "def",
expect => <<'#19...........',
given ( [ 9, "a", 11 ] ) {
when (qr/\d/) {
given ($count) {
when (1) { ok( $count == 1 ) }
else { ok( $count != 1 ) }
when ( [ 5, 6 ] ) { ok(0) }
else { ok(1) }
}
}
ok(1) when 11;
}
#19...........
},
( run in 0.722 second using v1.01-cache-2.11-cpan-71847e10f99 )