-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy path11_util.t
58 lines (42 loc) · 1.42 KB
/
11_util.t
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
#!/usr/bin/perl
# Test the PPI::Util package
use lib 't/lib';
use PPI::Test::pragmas;
use Test::More tests => 11 + ( $ENV{AUTHOR_TESTING} ? 1 : 0 );
use File::Spec::Functions qw( catfile );
use PPI ();
use PPI::Util qw( _Document _slurp );
use Helper 'safe_new';
# 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 = safe_new \$testsource;
# 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_unicode = PPI::Util::HAVE_UNICODE();
ok( defined $have_unicode, 'HAVE_UNICODE defined' );
is( $have_unicode, !!$have_unicode, 'HAVE_UNICODE is a boolean' );