Data-Hopen
view release on metacpan or search on metacpan
t/008-nameset.t view on Meta::CPAN
#!perl
# t/007-nameset.t: test Data::Hopen::Util::NameSet
use rlib 'lib';
use HopenTest;
use Test::Fatal;
use Data::Hopen::Util::NameSet;
my $s;
# Run the tests twice: once without add() and once with add().
for ( my $iter = 0 ; $iter < 2 ; ++$iter ) {
# Set up this iter's test object
if ( $iter == 0 ) {
$s = Data::Hopen::Util::NameSet->new();
isa_ok( $s, 'Data::Hopen::Util::NameSet' );
ok( !$s->contains('x'), "Empty nameset rejects 'x'" );
$s->add(
'foo', 'bar', qr/bat/,
[ qr/qu+x/i, 'array', ['inner array'] ],
{ key => 'value' },
'ÑÑÑÑкий', 'ÑзÑк'
);
}
elsif ( $iter == 1 ) {
$s = Data::Hopen::Util::NameSet->new(
'foo', 'bar', qr/bat/,
[ qr/qu+x/i, 'array', ['inner array'] ],
{ key => 'value' },
'ÑÑÑÑкий', 'ÑзÑк'
);
isa_ok( $s, 'Data::Hopen::Util::NameSet' );
}
# Accessors
is( ref( $s->strings ), 'ARRAY', 'strings is an arrayref' );
is( ref( $s->regexps ), 'ARRAY', 'regexps is an arrayref' );
# Contains tests
ok( !$s->contains('x'), "Nameset rejects 'x'" );
ok( $s->contains($_), "Nameset accepts literal $_" )
foreach ( qw(foo bar array key), 'inner array' );
ok( $s->contains($_), "Nameset accepts $_" ) foreach qw(bat qux QUX QuUuUx);
# UTF-8 words
ok $s->contains($_), "Nameset accepts UTF8 $_" foreach qw(ÑÑÑÑкий ÑзÑк);
# Some kanji and hiragana
ok !$s->contains($_), "Nameset rejects UTF8 $_" foreach qw(æ¥æ¬èª ã²ãããª);
# Partial words shouldn't succeed
ok( !$s->contains($_), "Nameset rejects $_" )
foreach qw(foobar fooqux fooQUX other_inner_array foofoo batqux batarray);
} #foreach test
# Complex, new()
$s = Data::Hopen::Util::NameSet->new( qw(foo bar), qr/./ );
ok( $s->complex, 'set with regexps is complex' );
$s = Data::Hopen::Util::NameSet->new(qw(foo bar));
ok( !$s->complex, 'set without regexps is not complex' );
# Complex, add()
( run in 1.374 second using v1.01-cache-2.11-cpan-54e63673c56 )