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 69 70 71 72 73 74 75 76 77 78 79 80 81
|
use strict;
use warnings;
use Test::More 0.96;
my $mod = 'Config::MVP::Slicer';
eval "require $mod" or die $@;
my $regexp = new_ok($mod)->separator_regexp;
is_deeply
['goober' =~ $regexp],
[],
'not matched';
is_deeply
[ 'Class::Name.attr' =~ $regexp],
[qw(Class::Name attr), undef],
'simple name.attr match';
is_deeply
[ 'Class::Name.attr[]' =~ $regexp],
[qw(Class::Name attr), '[]'],
'simple match with empty brackets';
is_deeply
[ 'Class::Name.attr[hooey]' =~ $regexp],
[qw(Class::Name attr), '[hooey]'],
'simple match with subscript';
is_deeply
[ 'Class::Name.attr.ibute' =~ $regexp],
[qw(Class::Name attr.ibute), undef],
'attribute with dot';
is_deeply
[ 'Class::Name.-attr' =~ $regexp],
[qw(Class::Name -attr), undef],
'attribute with leading dash';
is_deeply
[ 'Class::Name.-attr[1]' =~ $regexp],
[qw(Class::Name -attr), '[1]'],
'attribute with leading dash and brackets';
is_deeply
[ '-Class::Name.attr' =~ $regexp],
[qw(-Class::Name attr), undef],
'plugin class has string prefix';
$regexp = new_ok($mod, [{prefix => 'slice.'}])->separator_regexp;
is_deeply
[ 'slice.Class::Name.attr.ibute' =~ $regexp],
[qw(Class::Name attr.ibute), undef],
'prefix has a dot';
is_deeply
[ 'sliceXClass::Name.attr.ibute' =~ $regexp],
[qw(Class::Name attr.ibute), undef],
'prefix is a regexp';
is_deeply
[ 'sliceX-Class::Name.attr.ibute' =~ $regexp],
[qw(-Class::Name attr.ibute), undef],
'regexp prefix followed by class name with string prefix';
$regexp = new_ok($mod, [{separator => '(.+?)\W+(\w+)'}])->separator_regexp;
is_deeply
[ 'Class::Name->attr' =~ $regexp],
[qw(Class::Name attr), undef],
'alternate separator';
$regexp = new_ok($mod, [{prefix => qr/foo./, separator => '(.+?)\W+(\w+)'}])->separator_regexp;
is_deeply
[ 'foo:Class::Name->attr' =~ $regexp],
[qw(Class::Name attr), undef],
'alternate separator and prefix';
done_testing;
|