Code-TidyAll
view release on metacpan or search on metacpan
t/lib/TestFor/Code/TidyAll/Basic.pm view on Meta::CPAN
$self->tidy(
plugins => {
test_plugin('UpperText') => { select => '**/*.txt', only_modes => 'upper' },
test_plugin('ReverseFoo') => { select => '**/foo*', only_modes => 'reversals' }
},
source => { 'foo.txt' => 'abc' },
dest => { 'foo.txt' => 'cba' },
desc => 'one file reversals mode',
options => { mode => 'reversals' },
);
$self->tidy(
plugins => { %UpperText, %ReverseFoo },
source => {
'foo.txt' => 'abc',
'bar.txt' => 'def',
'foo.tx' => 'ghi',
'bar.tx' => 'jkl'
},
dest => {
'foo.txt' => 'CBA',
'bar.txt' => 'DEF',
'foo.tx' => 'ihg',
'bar.tx' => 'jkl'
},
desc => 'four files UpperText ReverseFoo',
);
$self->tidy(
plugins => {%UpperText},
source => { 'foo.txt' => 'abc1' },
dest => { 'foo.txt' => 'abc1' },
desc => 'one file UpperText errors',
errors => qr/non-alpha content/
);
$self->tidy(
plugins => {%UpperText},
options => {
ignore => ['global_ignore/*'],
},
source => {
'global_ignore/foo.txt' => 'abc',
'plugin_ignore/bar.txt' => 'def',
},
dest => {
'global_ignore/foo.txt' => 'abc',
'plugin_ignore/bar.txt' => 'def',
},
desc => 'global and plugin ignores',
);
}
sub test_filemode : Tests {
my $self = shift;
if ( $^O eq 'MSWin32' || $^O eq 'msys' ) {
$self->builder->skip('File mode on Windows is weird');
return;
}
my $root_dir = $self->create_dir( { 'foo.txt' => 'abc' } );
my $file = $root_dir->child('foo.txt');
$file->chmod('0755');
my $ct = Code::TidyAll->new(
plugins => { test_plugin('UpperText') => { select => '**/foo*' } },
root_dir => $root_dir,
);
$ct->process_paths($file);
is( $file->slurp, 'ABC' );
is( $file->stat->mode, 0100755 );
}
sub test_multiple_plugin_instances : Tests {
my $self = shift;
$self->tidy(
plugins => {
test_plugin('RepeatFoo for txt') => { select => '**/*.txt', times => 2 },
test_plugin('RepeatFoo for foo') => { select => '**/foo.*', times => 3 },
%UpperText
},
source => { 'foo.txt' => 'abc', 'foo.dat' => 'def', 'bar.txt' => 'ghi' },
dest => {
'foo.txt' => scalar( 'ABC' x 6 ),
'foo.dat' => scalar( 'def' x 3 ),
'bar.txt' => scalar( 'GHI' x 2 )
}
);
}
sub test_plugin_order_and_atomicity : Tests {
my $self = shift;
my @plugins = map {
(
%ReverseFoo,
test_plugin("UpperText $_") => { select => '**/*.txt' },
test_plugin("CheckUpper $_") => { select => '**/*.txt' },
# note without the weight here this would run first, and the
# letters in the photetic words themselves would be reversed
test_plugin('AlwaysPhonetic') => { select => '**/*.txt', weight => 51 }
)
} ( 1 .. 3 );
$self->tidy(
plugins => {@plugins},
options => { verbose => 1 },
source => { 'foo.txt' => 'abc' },
dest => { 'foo.txt' => 'CHARLIE-BRAVO-ALFA' },
like_output =>
qr/.*ReverseFoo, .*UpperText 1, .*UpperText 2, .*UpperText 3, .*CheckUpper 1, .*CheckUpper 2, .*CheckUpper 3/
);
$self->tidy(
plugins => { %AToZ, %ReverseFoo, %CheckUpper },
options => { verbose => 1 },
source => { 'foo.txt' => 'abc' },
dest => { 'foo.txt' => 'abc' },
errors => qr/lowercase found/,
like_output => qr/foo.txt (.*ReverseFoo, .*CheckUpper)/
);
}
( run in 0.861 second using v1.01-cache-2.11-cpan-39bf76dae61 )