File: ppi_statement_include.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 (250 lines) | stat: -rw-r--r-- 6,509 bytes parent folder | download | duplicates (2)
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
#!/usr/bin/perl

# Unit testing for PPI, generated by Test::Inline

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

# Execute the tests
use Test::More tests => 63;

# =begin testing type 9
{
my $document = PPI::Document->new(\<<'END_PERL');
require 5.6;
require Module;
require 'Module.pm';
use 5.6;
use Module;
use Module 1.00;
no Module;
END_PERL

isa_ok( $document, 'PPI::Document' );
my $statements = $document->find('PPI::Statement::Include');
is( scalar(@$statements), 7, 'Found 7 include statements' );
my @expected = qw{ require require require use use use no };
foreach ( 0 .. 6 ) {
	is( $statements->[$_]->type, $expected[$_], "->type $_ ok" );
}
}



# =begin testing module_version 9
{
my $document = PPI::Document->new(\<<'END_PERL');
use Integer::Version 1;
use Float::Version 1.5;
use Version::With::Argument 1 2;
use No::Version;
use No::Version::With::Argument 'x';
use No::Version::With::Arguments 1, 2;
use 5.005;
END_PERL

isa_ok( $document, 'PPI::Document' );
my $statements = $document->find('PPI::Statement::Include');
is( scalar @{$statements}, 7, 'Found expected include statements.' );
is( $statements->[0]->module_version, 1, 'Integer version' );
is( $statements->[1]->module_version, 1.5, 'Float version' );
is( $statements->[2]->module_version, 1, 'Version and argument' );
is( $statements->[3]->module_version, undef, 'No version, no arguments' );
is( $statements->[4]->module_version, undef, 'No version, with argument' );
is( $statements->[5]->module_version, undef, 'No version, with arguments' );
is( $statements->[6]->module_version, undef, 'Version include, no module' );
}



# =begin testing version 13
{
my $document = PPI::Document->new(\<<'END_PERL');
# Examples from perlfunc in 5.10.
use v5.6.1;
use 5.6.1;
use 5.006_001;
use 5.006; use 5.6.1;

# Same, but using require.
require v5.6.1;
require 5.6.1;
require 5.006_001;
require 5.006; require 5.6.1;

# Module.
use Float::Version 1.5;
END_PERL

isa_ok( $document, 'PPI::Document' );
my $statements = $document->find('PPI::Statement::Include');
is( scalar @{$statements}, 11, 'Found expected include statements.' );

is( $statements->[0]->version, 'v5.6.1', 'use v-string' );
is( $statements->[1]->version, '5.6.1', 'use v-string, no leading "v"' );
is( $statements->[2]->version, '5.006_001', 'use developer release' );
is( $statements->[3]->version, '5.006', 'use back-compatible version, followed by...' );
is( $statements->[4]->version, '5.6.1', '... use v-string, no leading "v"' );

is( $statements->[5]->version, 'v5.6.1', 'require v-string' );
is( $statements->[6]->version, '5.6.1', 'require v-string, no leading "v"' );
is( $statements->[7]->version, '5.006_001', 'require developer release' );
is( $statements->[8]->version, '5.006', 'require back-compatible version, followed by...' );
is( $statements->[9]->version, '5.6.1', '... require v-string, no leading "v"' );

is( $statements->[10]->version, '', 'use module version' );
}



# =begin testing version_literal 13
{
my $document = PPI::Document->new(\<<'END_PERL');
# Examples from perlfunc in 5.10.
use v5.6.1;
use 5.6.1;
use 5.006_001;
use 5.006; use 5.6.1;

# Same, but using require.
require v5.6.1;
require 5.6.1;
require 5.006_001;
require 5.006; require 5.6.1;

# Module.
use Float::Version 1.5;
END_PERL

isa_ok( $document, 'PPI::Document' );
my $statements = $document->find('PPI::Statement::Include');
is( scalar @{$statements}, 11, 'Found expected include statements.' );

is( $statements->[0]->version_literal, v5.6.1, 'use v-string' );
is( $statements->[1]->version_literal, 5.6.1, 'use v-string, no leading "v"' );
is( $statements->[2]->version_literal, 5.006_001, 'use developer release' );
is( $statements->[3]->version_literal, 5.006, 'use back-compatible version, followed by...' );
is( $statements->[4]->version_literal, 5.6.1, '... use v-string, no leading "v"' );

is( $statements->[5]->version_literal, v5.6.1, 'require v-string' );
is( $statements->[6]->version_literal, 5.6.1, 'require v-string, no leading "v"' );
is( $statements->[7]->version_literal, 5.006_001, 'require developer release' );
is( $statements->[8]->version_literal, 5.006, 'require back-compatible version, followed by...' );
is( $statements->[9]->version_literal, 5.6.1, '... require v-string, no leading "v"' );

is( $statements->[10]->version_literal, '', 'use module version' );
}



# =begin testing arguments 19
{
my $document = PPI::Document->new(\<<'END_PERL');
use 5.006;       # Don't expect anything.
use Foo;         # Don't expect anything.
use Foo 5;       # Don't expect anything.
use Foo 'bar';   # One thing.
use Foo 5 'bar'; # One thing.
use Foo qw< bar >, "baz";
use Test::More tests => 5 * 9   # Don't get tripped up by the lack of the ";"
END_PERL

isa_ok( $document, 'PPI::Document' );
my $statements = $document->find('PPI::Statement::Include');
is( scalar @{$statements}, 7, 'Found expected include statements.' );

is(
	scalar $statements->[0]->arguments, undef, 'arguments for perl version',
);
is(
	scalar $statements->[1]->arguments,
	undef,
	'arguments with no arguments',
);
is(
	scalar $statements->[2]->arguments,
	undef,
	'arguments with no arguments but module version',
);

my @arguments = $statements->[3]->arguments;
is( scalar @arguments, 1, 'arguments with single argument' );
is( $arguments[0]->content, q<'bar'>, 'arguments with single argument' );

@arguments = $statements->[4]->arguments;
is(
	scalar @arguments,
	1,
	'arguments with single argument and module version',
);
is(
	$arguments[0]->content,
	q<'bar'>,
	'arguments with single argument and module version',
);

@arguments = $statements->[5]->arguments;
is(
	scalar @arguments,
	3,
	'arguments with multiple arguments',
);
is(
	$arguments[0]->content,
	q/qw< bar >/,
	'arguments with multiple arguments',
);
is(
	$arguments[1]->content,
	q<,>,
	'arguments with multiple arguments',
);
is(
	$arguments[2]->content,
	q<"baz">,
	'arguments with multiple arguments',
);

@arguments = $statements->[6]->arguments;
is(
	scalar @arguments,
	5,
	'arguments with Test::More',
);
is(
	$arguments[0]->content,
	'tests',
	'arguments with Test::More',
);
is(
	$arguments[1]->content,
	q[=>],
	'arguments with Test::More',
);
is(
	$arguments[2]->content,
	5,
	'arguments with Test::More',
);
is(
	$arguments[3]->content,
	'*',
	'arguments with Test::More',
);
is(
	$arguments[4]->content,
	9,
	'arguments with Test::More',
);
}


1;