App-SimpleScan
view release on metacpan or search on metacpan
t/48subs_base.t view on Meta::CPAN
use Test::More tests=>24;
use Test::Exception;
use Test::Differences;
use App::SimpleScan::Substitution;
use App::SimpleScan::Substitution::Line;
# new() tests
my %hash;
my $substitution;
lives_ok { $substitution = new App::SimpleScan::Substitution; } 'simplest object';
dies_ok { $substitution = new App::SimpleScan::Substitution 'bad' }
'die on simple scalar';
like $@, qr/Argument to new is not a hash reference/, 'right message';
dies_ok { $substitution = new App::SimpleScan::Substitution [] }
'die on non-hash ref';
like $@, qr/Argument to new is not a hash reference/, 'right message';
dies_ok { $substitution =
new App::SimpleScan::Substitution {dictionary =>'bad' } }
'die on non-hash dictionary';
like $@, qr/'dictionary' must be a hash reference/, 'right message';
dies_ok { $substitution =
new App::SimpleScan::Substitution {find_vars_callback =>'bad' } }
'die on non-code find_vars_callback';
like $@, qr/'find_vars_callback' must be a code reference/, 'right message';
lives_ok { $substitution =
new App::SimpleScan::Substitution {dictionary =>\%hash } }
'good dictionary';
lives_ok { $substitution =
new App::SimpleScan::Substitution {find_vars_callback => sub {} } }
'good find_vars_callback';
# insert_value_callback test
my $insert = $substitution->insert_value_callback();
my($which, $result) = $insert->("this is <a> test", "the","the");
is $which, "", "not inserted";
is $result, "this is <a> test", "no change";
($which, $result) = $insert->("this is <a> test", "a","the");
is $which, 1, "inserted";
is $result, "this is the test", "changed";
# _find_angle_bracketed test
my $find_sub_ref = $substitution->find_vars_callback();
my $test_string;
$test_string = 'this is a test';
eq_or_diff [$find_sub_ref->($test_string)], [],
'no angle-bracketed item';
$test_string = 'this is a <test>';
eq_or_diff [$find_sub_ref->($test_string)], [qw(test)],
'one angle-bracketed item';
$test_string = 'this is a <more_complex_<test>> than <before>';
my @result = sort $find_sub_ref->($test_string);
eq_or_diff \@result,
[sort qw(before more_complex_<test> test)],
'nested angle-bracketed item';
# _deepest_substitution test
( run in 0.544 second using v1.01-cache-2.11-cpan-6aa56a78535 )