Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
awful but useful Test::TagHive
  • Loading branch information
rjbs committed May 27, 2011
1 parent 5803eb2 commit 39d53ed
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 17 deletions.
42 changes: 42 additions & 0 deletions t/lib/Test/TagHive.pm
@@ -0,0 +1,42 @@
use 5.12.0;
use warnings;
package Test::TagHive;

use Test::More;

use Sub::Exporter -setup => {
groups => { default => \'_gen_group' },
};

sub _gen_group {
my ($self, $name, $arg, $col) = @_;

my %sub;

my $taghive;
$sub{set_taghive} = sub {
$taghive = shift;
};

$sub{taghive} = sub { $taghive };

$sub{has_tag} = sub {
my ($tag) = @_;
ok(
$taghive->has_tag($tag),
"tag <$tag> is present",
);
};

$sub{hasnt_tag} = sub {
my ($tag) = @_;
ok(
! $taghive->has_tag($tag),
"tag <$tag> is absent",
);
};

return \%sub;
}

1;
29 changes: 12 additions & 17 deletions t/taghive.t
Expand Up @@ -5,59 +5,54 @@ use Test::More;
use Test::Fatal;
use Try::Tiny;

use lib 't/lib';
use Test::TagHive;

use Data::TagHive;

my $taghive = Data::TagHive->new;
set_taghive( Data::TagHive->new );

$taghive->add_tag('fauxbox.type:by-seat.seats:17');
taghive->add_tag('fauxbox.type:by-seat.seats:17');

my @has = qw(
has_tag($_) for qw(
fauxbox
fauxbox.type
fauxbox.type:by-seat
fauxbox.type:by-seat.seats
fauxbox.type:by-seat.seats:17
);

for my $str (@has) {
ok($taghive->has_tag($str), "has $str");
}

my @hasnt = qw(
hasnt_tag($_) for qw(
pobox
fauxbox.type:by-seat.seats:92
);

for my $str (@hasnt) {
ok(! $taghive->has_tag($str), "hasn't $str");
}

{
my $error = exception { $taghive->add_tag('fauxbox.type:by-usage') };
my $error = exception { taghive->add_tag('fauxbox.type:by-usage') };
ok($error, "we can't add a tag with a conflicting value");
like($error, qr/conflict at \Qfauxbox.type\E\b/, "...we get expected error");
}

{
my $error = exception { $taghive->add_tag('fauxbox.type:by-usage.seats:17') };
my $error = exception { taghive->add_tag('fauxbox.type:by-usage.seats:17') };
ok($error, "we can't add a tag with a conflicting value");
like($error, qr/conflict at \Qfauxbox.type\E\b/, "...we get expected error");
}

{
my $error = exception { $taghive->add_tag('fauxbox:foo'); };
my $error = exception { taghive->add_tag('fauxbox:foo'); };
ok($error, "we can't add a tag with a value when there was no value");
like($error, qr/conflict at fauxbox\b/, "...we get expected error");
}

{
my $error = exception { $taghive->add_tag('fauxbox.type.xyz'); };
my $error = exception { taghive->add_tag('fauxbox.type.xyz'); };
ok($error, "can't add descend with no value where one is already present");
like($error, qr/conflict at \Qfauxbox.type\E\b/, "...we get expected error");
}

for my $method (qw(add_tag has_tag)) {
my $error = exception { $taghive->$method('not a tag!'); };
my $error = exception { taghive->$method('not a tag!'); };
ok($error, "can't pass invalid tag to $method");
like($error, qr/invalid tagstr/, "...we get expected error");
}
Expand Down

0 comments on commit 39d53ed

Please sign in to comment.