PPIx-EditorTools
view release on metacpan or search on metacpan
t/05-renamepackagefrompath.t view on Meta::CPAN
#!/usr/bin/perl
use strict;
BEGIN {
$^W = 1;
}
use Test::More;
use Test::Differences;
use PPI;
BEGIN {
if ( $PPI::VERSION =~ /_/ ) {
plan skip_all => "Need released version of PPI. You have $PPI::VERSION";
exit 0;
}
}
plan tests => 4;
use PPIx::EditorTools::RenamePackageFromPath;
my $code = "package TestPackage;\nuse strict;\nBEGIN {
$^W = 1;
}\n1;\n";
sub new_code {
return sprintf "package %s;\nuse strict;\nBEGIN {
$^W = 1;
}\n1;\n", shift;
}
my $munged = PPIx::EditorTools::RenamePackageFromPath->new->rename(
code => $code,
filename => './lib/Test/Code/Path.pm',
);
eq_or_diff( $munged->code, new_code("Test::Code::Path"), 'simple package' );
eq_or_diff(
PPIx::EditorTools::RenamePackageFromPath->new->rename(
code => $code,
filename => './Test/Code/Path.pm',
)->code,
new_code("Test::Code::Path"),
'no lib package'
);
eq_or_diff(
PPIx::EditorTools::RenamePackageFromPath->new->rename(
code => $code,
filename => 'lib/Test/./Code/Path.pm',
)->code,
new_code("Test::Code::Path"),
'with /./ part'
);
TODO: {
local $TODO = 'Does not support /../ path constructs yet';
eq_or_diff(
PPIx::EditorTools::RenamePackageFromPath->new->rename(
code => $code,
filename => 'lib/Test/Ignore/../Code/Path.pm',
)->code,
new_code("Test::Code::Path"),
'strip .. from package'
);
}
( run in 2.315 seconds using v1.01-cache-2.11-cpan-5837b0d9d2c )