File: 29_logical_filename.t

package info (click to toggle)
libppi-perl 1.281-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 2,220 kB
  • sloc: perl: 15,287; makefile: 8
file content (68 lines) | stat: -rwxr-xr-x 2,097 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
#!/usr/bin/perl

# Testing of PPI::Element->logical_filename

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

use File::Spec::Functions qw( catfile );
use PPI::Document ();
use PPI::Document::File ();
use PPI::Util ();
use Test::More tests => 20 + 1; # Test::NoWarnings
use Test::NoWarnings; ## no perlimports

for my $class ( ( PPI::Document::, PPI::Document::File:: ) ) {

	#####################################################################
	# Actual filename is used until #line directive

	SCOPE: {
		my $file = catfile('t', 'data', 'filename.pl');
		ok( -f $file, "$class, test file" );

		my $doc = $class->new( $file );
		my $items = $doc->find( 'Token::Quote' );
		is( @$items + 0, 2, "$class, number of items" );
		is( $items->[ 0 ]->logical_filename, "$file", "$class, filename" );
		is( $items->[ 1 ]->logical_filename, "moo.pl", "$class, filename" );
	}

	#####################################################################
	# filename attribute overrides actual filename

	SCOPE: {
		my $file = catfile('t', 'data', 'filename.pl');
		ok( -f $file, "$class, test file" );

		my $doc = $class->new( $file, filename => 'assa.pl' );
		my $items = $doc->find( 'Token::Quote' );
		is( @$items + 0, 2, "$class, number of items" );
		my $str = $items->[ 0 ];
		is( $items->[ 0 ]->logical_filename, "assa.pl", "$class, filename" );
		is( $items->[ 1 ]->logical_filename, "moo.pl", "$class, filename" );
	}

}

#####################################################################
# filename attribute works for strings too

SCOPE: {
	my $class = 'PPI::Document';
	my $file = catfile('t', 'data', 'filename.pl');
	ok( -f $file, "$class, test file" );
	my $text = PPI::Util::_slurp( $file );

	my $doc = $class->new( $text, filename => 'tadam.pl' );
	my $items = $doc->find( 'Token::Quote' );
	is( @$items + 0, 2, "$class, number of items" );
	my $str = $items->[ 0 ];
	is( $items->[ 0 ]->logical_filename, "tadam.pl", "$class, filename" );
	is( $items->[ 1 ]->logical_filename, "moo.pl", "$class, filename" );
}