1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
|
#!/usr/bin/perl
# Test the PPI::Util package
use strict;
BEGIN {
no warnings 'once';
$| = 1;
$PPI::XS_DISABLE = 1;
$PPI::Lexer::X_TOKENIZER ||= $ENV{X_TOKENIZER};
}
use Test::More tests => 13;
use Test::NoWarnings;
use File::Spec::Functions ':ALL';
use PPI::Lexer ();
use PPI;
use PPI::Util qw{_Document _slurp};
# Execute the tests
my $testfile = catfile( 't', 'data', '11_util', 'test.pm' );
my $testsource = 'print "Hello World!\n"';
my $slurpfile = catfile( 't', 'data', 'basic.pl' );
my $slurpcode = <<'END_FILE';
#!/usr/bin/perl
if ( 1 ) {
print "Hello World!\n";
}
1;
END_FILE
#####################################################################
# Test PPI::Util::_Document
my $Document = PPI::Document->new( \$testsource );
isa_ok( $Document, 'PPI::Document' );
# Good things
foreach my $thing ( $testfile, \$testsource, $Document, [] ) {
isa_ok( _Document( $thing ), 'PPI::Document' );
}
# Bad things
### erm...
# Evil things
foreach my $thing ( {}, sub () { 1 } ) {
is( _Document( $thing ), undef, '_Document(evil) returns undef' );
}
#####################################################################
# Test PPI::Util::_slurp
my $source = _slurp( $slurpfile );
is_deeply( $source, \$slurpcode, '_slurp loads file as expected' );
#####################################################################
# Check the capability flags
my $have_alarm = PPI::Util::HAVE_ALARM();
my $have_unicode = PPI::Util::HAVE_UNICODE();
ok( defined $have_alarm, 'HAVE_ALARM defined' );
ok( defined $have_unicode, 'HAVE_UNICODE defined' );
is( $have_alarm, !! $have_alarm, 'HAVE_ALARM is a boolean' );
is( $have_unicode, !! $have_unicode, 'HAVE_UNICODE is a boolean' );
|