# File test/core_test.rb, line 254 def test_parent parent = Parent.new begin parent << "Something" rescue parent << Comment.new("Some comment") assert parent.size == 1, "size of parent should be 1" else assert_fail "should have gotten an exception trying to add a "+ "String to a Parent" end source = "<a><one/><three/><five/></a>" doc = Document.new source three = doc.root.elements["three"] doc.root.insert_before( three, Element.new("two") ) nxt = doc.root.elements["one"] string = "" while nxt string << nxt.name nxt = nxt.next_sibling end assert_equal "onetwothreefive", string doc.root.insert_after( three, Element.new("four") ) string = "" doc.root.each { |element| string << element.name } assert_equal "onetwothreefourfive", string string = "" nxt = doc.root.elements["five"] while nxt string << nxt.name nxt = nxt.previous_sibling end assert_equal "fivefourthreetwoone", string doc.insert_after "//two", Element.new("two-and-half") string = doc.root.elements.collect {|x| x.name}.join assert_equal "onetwotwo-and-halfthreefourfive", string doc.elements["/a/five"].insert_before "../four", Element.new("three-and-half") string = doc.root.elements.collect {|x| x.name}.join assert_equal "onetwotwo-and-halfthreethree-and-halffourfive", string doc.elements["/a/five"].previous_sibling = Element.new("four-and-half") string = doc.root.elements.collect {|x| x.name}.join assert_equal "onetwotwo-and-halfthreethree-and-halffourfour-and-halffive", string doc.elements["/a/one"].next_sibling = Element.new("one-and-half") string = doc.root.elements.collect {|x| x.name}.join assert_equal "oneone-and-halftwotwo-and-halfthreethree-and-halffourfour-and-halffive", string doc = Document.new "<a><one/><three/></a>" doc.root[1,0] = Element.new "two" string = "" doc.root.each { |el| string << el.name } assert_equal "onetwothree", string end