Mercurial > pub > Impl
diff _test/Test/DOM/Node.pm @ 18:818c74b038ae
DOM Schema + tests
author | Sergey |
---|---|
date | Thu, 10 Sep 2009 17:42:47 +0400 |
parents | 65a7bb156fb7 |
children | 7f00786f8210 |
line wrap: on
line diff
--- a/_test/Test/DOM/Node.pm Wed Sep 09 17:43:31 2009 +0400 +++ b/_test/Test/DOM/Node.pm Thu Sep 10 17:42:47 2009 +0400 @@ -3,7 +3,7 @@ use warnings; use base qw(IMPL::Test::Unit); -use IMPL::Test qw(test shared failed); +use IMPL::Test qw(test shared failed cmparray); use IMPL::Class::Property; require IMPL::DOM::Node; @@ -20,14 +20,105 @@ $this->Root(new IMPL::DOM::Node(nodeName => 'Root')) or failed "Failed to create a node"; }; +test InsertNode => sub { + my ($this) = @_; + my $child = $this->Root->insertNode(new IMPL::DOM::Node(nodeName => 'Child')) or failed "Failed to insert a child node"; + failed "fiestChild returned incorrect results" unless ($this->Root->firstChild || 0) == $child; +}; + test AppendNode => sub { my ($this) = @_; my $child = $this->Root->appendNode(new IMPL::DOM::Node(nodeName => 'Child')) or failed "Failed to append a child node"; - my $firstChild = $this->Root->firstChild; + my $lastChild = $this->Root->removeLast; + + failed "removeLast returned incorrect results" unless $lastChild == $child; +}; + +test GetRootNode => sub { + my ($this) = @_; + + my $child = $this->Root->firstChild->appendNode(new IMPL::DOM::Node(nodeName => 'GrandChild')) or failed "Failed to append a child node"; + + failed "rootNode is undef" unless $child->rootNode; + failed "rootNode returned incorrect value" unless $child->rootNode == $this->Root; +}; + +test MoveNode => sub { + my ($this) = @_; + + my $grandChild = $this->Root->firstChild->firstChild; + $this->Root->appendNode($grandChild); + + failed "incorrect new parentNode value" unless ($grandChild->parentNode || 0) == $this->Root; + failed "incorrect new rootNode value" unless ($grandChild->rootNode || 0) == $this->Root; +}; + +test AppendRange => sub { + my ($this) = @_; + + my $count = $this->Root->childNodes->Count; + + $this->Root->appendRange( + map IMPL::DOM::Node->new(nodeName => "Item", nodeValue => $_),1..10 + ); + + failed + "Wrong number of a child nodes", + "Expected: ".($count+10), + "Actual: ".$this->Root->childNodes->Count + unless $count + 10 == $this->Root->childNodes->Count; +}; + +test SelectNodes => sub { + my ($this) = @_; - failed "firstChild returned incorrect results" unless $firstChild == $child; + my @result = $this->Root->selectNodes("Item"); + + failed + "Wrong number of a selected nodes", + "Expected: 10", + "Actual: ".scalar(@result) + unless @result == 10; +}; + +test SelectNodesByQuery => sub { + my ($this) = @_; + + my @result = $this->Root->selectNodes(sub { $_[0]->nodeName =~ /child/i } ); + failed + "Wrong number of a selected nodes", + "Expected: 2", + "Actual: ".scalar(@result) + unless @result == 2; +}; + +test CheckNodesValues => sub { + my ($this) = @_; + + my @expected = (1..10); + + my @result = map $_->nodeValue, grep $_->nodeValue, $this->Root->selectNodes("Item"); + + failed + "Some nodes returned wrong node values or in a wrong order", + "Expected: ".join(', ',@expected), + "Recieved: ".join(', ',@result) + unless cmparray(\@expected,\@result); + + failed + "a text property of a root node returned a wrong value", + "Expected: @expected", + "Recieved: ". $this->Root->text + unless $this->Root->text eq join '',@expected; +}; + +test isComplex => sub { + my ($this) = @_; + + failed "property isComplex returned false for the root node" unless $this->Root->isComplex; + failed "property isComplex returned true for a simple node", $this->Root->firstChild->nodeName if $this->Root->firstChild->isComplex; }; 1;