12_Tree_Simple_exceptions_test.t [plain text]
use strict;
use warnings;
use Test::More tests => 52;
use Test::Exception;
use Tree::Simple;
my $BAD_OBJECT = bless({}, "Fail");
my $TEST_SUB_TREE = Tree::Simple->new("test");
throws_ok {
Tree::Simple->new("test", 0);
} qr/^Insufficient Arguments \:/, '... this should die';
throws_ok {
Tree::Simple->new("test", []);
} qr/^Insufficient Arguments \:/, '... this should die';
throws_ok {
Tree::Simple->new("test", $BAD_OBJECT);
} qr/^Insufficient Arguments \:/, '... this should die';
my $tree = Tree::Simple->new(Tree::Simple->ROOT);
throws_ok {
$tree->setNodeValue();
} qr/^Insufficient Arguments \: must supply a value for node/, '... this should die';
throws_ok {
$tree->addChild();
} qr/^Insufficient Arguments : no tree\(s\) to insert/, '... this should die';
throws_ok {
$tree->addChild("fail");
} qr/^Insufficient Arguments \: Child must be a Tree\:\:Simple object/, '... this should die';
throws_ok {
$tree->addChild([]);
} qr/^Insufficient Arguments \: Child must be a Tree\:\:Simple object/, '... this should die';
throws_ok {
$tree->addChild($BAD_OBJECT);
} qr/^Insufficient Arguments \: Child must be a Tree\:\:Simple object/, '... this should die';
throws_ok {
$tree->insertChild();
} qr/^Insufficient Arguments \: Cannot insert child without index/, '... this should die';
throws_ok {
$tree->insertChild(5);
} qr/^Index Out of Bounds \: got \(5\) expected no more than \(0\)/, '... this should die';
throws_ok {
$tree->insertChild(0);
} qr/^Insufficient Arguments \: no tree\(s\) to insert/, '... this should die';
throws_ok {
$tree->insertChild(0, undef);
} qr/^Insufficient Arguments \: Child must be a Tree\:\:Simple object/, '... this should die';
throws_ok {
$tree->insertChild(0, "Fail");
} qr/^Insufficient Arguments \: Child must be a Tree\:\:Simple object/, '... this should die';
throws_ok {
$tree->insertChild(0, []);
} qr/^Insufficient Arguments \: Child must be a Tree\:\:Simple object/, '... this should die';
throws_ok {
$tree->insertChild(0, $BAD_OBJECT);
} qr/^Insufficient Arguments \: Child must be a Tree\:\:Simple object/, '... this should die';
throws_ok {
$tree->insertChildren();
} qr/^Insufficient Arguments \: Cannot insert child without index/, '... this should die';
throws_ok {
$tree->insertChildren(5);
} qr/^Index Out of Bounds \: got \(5\) expected no more than \(0\)/, '... this should die';
throws_ok {
$tree->insertChildren(0);
} qr/^Insufficient Arguments \: no tree\(s\) to insert/, '... this should die';
throws_ok {
$tree->insertChildren(0, undef);
} qr/^Insufficient Arguments \: Child must be a Tree\:\:Simple object/, '... this should die';
throws_ok {
$tree->insertChildren(0, "Fail");
} qr/^Insufficient Arguments \: Child must be a Tree\:\:Simple object/, '... this should die';
throws_ok {
$tree->insertChildren(0, []);
} qr/^Insufficient Arguments \: Child must be a Tree\:\:Simple object/, '... this should die';
throws_ok {
$tree->insertChildren(0, $BAD_OBJECT);
} qr/^Insufficient Arguments \: Child must be a Tree\:\:Simple object/, '... this should die';
throws_ok {
$tree->removeChildAt();
} qr/^Insufficient Arguments \: Cannot remove child without index/, '... this should die';
throws_ok {
$tree->removeChildAt(5);
} qr/^Illegal Operation \: There are no children to remove/, '... this should die';
$tree->addChild($TEST_SUB_TREE);
throws_ok {
$tree->removeChildAt(5);
} qr/^Index Out of Bounds \: got \(5\) expected no more than \(1\)/, '... this should die';
is($tree->removeChildAt(0), $TEST_SUB_TREE, '... these should be the same');
throws_ok {
$tree->removeChild();
} qr/^Insufficient Arguments \: /, '... this should die';
throws_ok {
$tree->removeChild([]);
} qr/^Insufficient Arguments \: /, '... this should die';
throws_ok {
$tree->removeChild($BAD_OBJECT);
} qr/^Insufficient Arguments \: /, '... this should die';
throws_ok {
$tree->removeChild($TEST_SUB_TREE);
} qr/^Child Not Found \: /, '... this should die';
throws_ok {
$tree->addSibling($TEST_SUB_TREE);
} qr/^Insufficient Arguments \: cannot add a sibling to a ROOT tree/, '... this should die';
throws_ok {
$tree->addSiblings($TEST_SUB_TREE);
} qr/^Insufficient Arguments \: cannot add siblings to a ROOT tree/, '... this should die';
throws_ok {
$tree->insertSibling(0, $TEST_SUB_TREE);
} qr/^Insufficient Arguments \: cannot insert sibling\(s\) to a ROOT tree/, '... this should die';
throws_ok {
$tree->insertSiblings(0, $TEST_SUB_TREE);
} qr/^Insufficient Arguments \: cannot insert sibling\(s\) to a ROOT tree/, '... this should die';
throws_ok {
$tree->getChild();
} qr/^Insufficient Arguments \: Cannot get child without index/, '... this should die';
throws_ok {
$tree->getSibling();
} qr/^Insufficient Arguments \: cannot get siblings from a ROOT tree/, '... this should die';
throws_ok {
$tree->getAllSiblings();
} qr/^Insufficient Arguments \: cannot get siblings from a ROOT tree/, '... this should die';
throws_ok {
$tree->traverse();
} qr/^Insufficient Arguments \: Cannot traverse without traversal function/, '... this should die';
throws_ok {
$tree->traverse("Fail");
} qr/^Incorrect Object Type \: traversal function is not a function/, '... this should die';
throws_ok {
$tree->traverse($BAD_OBJECT);
} qr/^Incorrect Object Type \: traversal function is not a function/, '... this should die';
throws_ok {
$tree->traverse(sub {}, "Fail");
} qr/^Incorrect Object Type \: post traversal function is not a function/, '... this should die';
throws_ok {
$tree->traverse(sub {}, $BAD_OBJECT);
} qr/^Incorrect Object Type \: post traversal function is not a function/, '... this should die';
throws_ok {
$tree->accept();
} qr/^Insufficient Arguments \: You must supply a valid Visitor object/, '... this should die';
throws_ok {
$tree->accept("Fail");
} qr/^Insufficient Arguments \: You must supply a valid Visitor object/, '... this should die';
throws_ok {
$tree->accept([]);
} qr/^Insufficient Arguments \: You must supply a valid Visitor object/, '... this should die';
throws_ok {
$tree->accept($BAD_OBJECT);
} qr/^Insufficient Arguments \: You must supply a valid Visitor object/, '... this should die';
{
package TestPackage;
sub visit {}
}
lives_ok {
$tree->accept(bless({}, "TestPackage"));
} '... but, this should live';
throws_ok {
$tree->_setParent();
} qr/^Insufficient Arguments/, '... this should croak';
throws_ok {
$tree->_setParent("Test");
} qr/^Insufficient Arguments/, '... this should croak';
throws_ok {
$tree->_setParent([]);
} qr/^Insufficient Arguments/, '... this should croak';
throws_ok {
$tree->_setParent($BAD_OBJECT);
} qr/^Insufficient Arguments/, '... this should croak';
throws_ok {
$tree->setUID();
} qr/^Insufficient Arguments/, '... this should croak';