forked from Perl-Critic/PPI
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
issue Perl-Critic#31 - DESTROY and AUTOLOAD don't parse as subs witho…
…ut 'sub'
- Loading branch information
Showing
4 changed files
with
100 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#!/usr/bin/perl | ||
|
||
# Test PPI::Statement::Sub | ||
|
||
use strict; | ||
BEGIN { | ||
$^W = 1; | ||
no warnings 'once'; | ||
$PPI::XS_DISABLE = 1; | ||
$PPI::Lexer::X_TOKENIZER ||= $ENV{X_TOKENIZER}; | ||
} | ||
|
||
use Test::More tests => 113; | ||
use Test::NoWarnings; | ||
use PPI; | ||
|
||
|
||
SUB_WORD_OPTIONAL: { | ||
foreach my $name ( qw( AUTOLOAD DESTROY ) ) { | ||
foreach my $sub ( '', 'sub ' ) { | ||
# '{}' -- function definition | ||
# ';' -- function declaration | ||
# '' -- function declaration with missing semicolon | ||
foreach my $followed_by ( ' {}', '{}', ';', '' ) { | ||
my $code = "$sub$name$followed_by"; | ||
my $Document = PPI::Document->new( \$code ); | ||
isa_ok( $Document, 'PPI::Document', "$code: got document" ); | ||
|
||
my ( $sub_statement, $dummy ) = $Document->schildren(); | ||
isa_ok( $sub_statement, 'PPI::Statement::Sub', "$code: document child is a sub" ); | ||
isnt( ref $sub_statement, 'PPI::Statement::Scheduled', "$code: not a PPI::Statement::Scheduled" ); | ||
is( $dummy, undef, "$code: document has exactly one child" ); | ||
ok( $sub_statement->reserved(), "$code: is reserved" ); | ||
is( $sub_statement->name(), $name, "$code: name() correct" ); | ||
if ( $followed_by =~ /}/ ) { | ||
isa_ok( $sub_statement->block(), 'PPI::Structure::Block', "$code: has a block" ); | ||
} | ||
else { | ||
ok( !$sub_statement->block(), "$code: has no block" ); | ||
} | ||
} | ||
} | ||
} | ||
} |