Added Node#previous_element and Node#next_element.

These methods can be used similar to #previous and #next expect that they only
return Element instances opposed to all Node instances.
This commit is contained in:
Yorick Peterse committed 2014-07-04 10:18:18 +02:00
1 parent 94965961ce
commit e334e50ca6
2 files changed
+84 -10

No files matched your search

+54 -10
View File
@@ -29,16 +29,6 @@ describe Oga::XML::Node do
end
end
context '#parent' do
example 'return the parent of the node' do
owner = described_class.new
set = Oga::XML::NodeSet.new([], owner)
node = described_class.new(:node_set => set)
node.parent.should == owner
end
end
context '#children=' do
example 'set the child nodes using an Array' do
child = described_class.new
@@ -59,6 +49,16 @@ describe Oga::XML::Node do
end
end
context '#parent' do
example 'return the parent of the node' do
owner = described_class.new
set = Oga::XML::NodeSet.new([], owner)
node = described_class.new(:node_set => set)
node.parent.should == owner
end
end
context '#previous' do
before do
owner = described_class.new
@@ -93,6 +93,50 @@ describe Oga::XML::Node do
end
end
context '#previous_element' do
before do
owner = described_class.new
@n1 = Oga::XML::Element.new
@n2 = Oga::XML::Text.new
@n3 = described_class.new
@set = Oga::XML::NodeSet.new([@n1, @n2, @n3], owner)
end
example 'return the previous element of a generic node' do
@n3.previous_element.should == @n1
end
example 'return the previous element of a text node' do
@n2.previous_element.should == @n1
end
example 'return nil if there is no previous element' do
@n1.previous_element.nil?.should == true
end
end
context '#next_element' do
before do
owner = described_class.new
@n1 = described_class.new
@n2 = Oga::XML::Text.new
@n3 = Oga::XML::Element.new
@set = Oga::XML::NodeSet.new([@n1, @n2, @n3], owner)
end
example 'return the next element of a generic node' do
@n1.next_element.should == @n3
end
example 'return the next element of a text node' do
@n2.next_element.should == @n3
end
example 'return nil if there is no next element' do
@n3.next_element.nil?.should == true
end
end
context '#root_node' do
before do
@n4 = described_class.new