File: ppi_token_quotelike_words.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 (63 lines) | stat: -rw-r--r-- 1,453 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
#!/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 => 12;

# =begin testing literal 12
{
my $empty_list_document = PPI::Document->new(\<<'END_PERL');
qw//
qw/    /
END_PERL

isa_ok( $empty_list_document, 'PPI::Document' );
my $empty_list_tokens =
	$empty_list_document->find('PPI::Token::QuoteLike::Words');
is( scalar @{$empty_list_tokens}, 2, 'Found expected empty word lists.' );
foreach my $token ( @{$empty_list_tokens} ) {
	my @literal = $token->literal;
	is( scalar @literal, 0, qq<No elements for "$token"> );
}

my $non_empty_list_document = PPI::Document->new(\<<'END_PERL');
qw/foo bar baz/
qw/  foo bar baz  /
qw {foo bar baz}
END_PERL
my @expected = qw/ foo bar baz /;

isa_ok( $non_empty_list_document, 'PPI::Document' );
my $non_empty_list_tokens =
	$non_empty_list_document->find('PPI::Token::QuoteLike::Words');
is(
	scalar(@$non_empty_list_tokens),
	3,
	'Found expected non-empty word lists.',
);
foreach my $token ( @$non_empty_list_tokens ) {
	my $literal = $token->literal;
	is(
		$literal,
		scalar @expected,
		qq<Scalar context literal() returns the list for "$token">,
	);
	my @literal = $token->literal;
	is_deeply( [ $token->literal ], \@expected, '->literal matches expected' );
}
}


1;