File: 03_document.t

package info (click to toggle)
libppi-perl 1.215-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 1,820 kB
  • sloc: perl: 12,129; makefile: 8
file content (87 lines) | stat: -rw-r--r-- 1,888 bytes parent folder | download | duplicates (3)
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
79
80
81
82
83
84
85
86
87
#!/usr/bin/perl

# PPI::Document tests

use strict;
use File::Spec::Functions ':ALL';
BEGIN {
	no warnings 'once';
	$| = 1;
	$PPI::XS_DISABLE = 1;
	$PPI::Lexer::X_TOKENIZER ||= $ENV{X_TOKENIZER};
}
use PPI;

# Execute the tests
use Test::More tests => 14;
use Test::NoWarnings;

# Test file
my $file  = catfile(qw{ t data 03_document test.dat  });
my $empty = catfile(qw{ t data 03_document empty.dat });
ok( -f $file,  'Found test file' );
ok( -f $empty, 'Found test file' );

# Test script
my $script = <<'END_PERL';
#!/usr/bin/perl

# A simple test script

print "Hello World!\n";
END_PERL





#####################################################################
# Test a basic document

# Parse a simple document in all possible ways
SCOPE: {
	my $doc1 = PPI::Document->new( $file );
	isa_ok( $doc1, 'PPI::Document' );

	my $doc2 = PPI::Document->new( \$script );
	isa_ok( $doc2, 'PPI::Document' );

	my $doc3 = PPI::Document->new( [
		"#!/usr/bin/perl",
		"",
		"# A simple test script",
		"",
		"print \"Hello World!\\n\";",
	] );
	isa_ok( $doc3, 'PPI::Document' );

	# Compare the three forms
	is_deeply( $doc1, $doc2, 'Stringref form matches file form' );
	is_deeply( $doc1, $doc3, 'Arrayref form matches file form'  );
}

# Repeat the above with a null document
SCOPE: {
	my $doc1 = PPI::Document->new( $empty );
	isa_ok( $doc1, 'PPI::Document' );

	my $doc2 = PPI::Document->new( \'' );
	isa_ok( $doc2, 'PPI::Document' );

	my $doc3 = PPI::Document->new( [ ] );
	isa_ok( $doc3, 'PPI::Document' );

	# Compare the three forms
	is_deeply( $doc1, $doc2, 'Stringref form matches file form' );
	is_deeply( $doc1, $doc3, 'Arrayref form matches file form'  );

	# Make sure the null document round-trips
	my $string = $doc1->serialize;
	is( $string, '', '->serialize ok' );

	# Check for warnings on null document index_locations
	{
		local $^W = 1;
		$doc1->index_locations();
	}
}