Skip to content

Commit

Permalink
Added some append tests and moving nodes between document tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
cfis committed Mar 22, 2009
1 parent 43e4102 commit 81853a6
Showing 1 changed file with 28 additions and 4 deletions.
32 changes: 28 additions & 4 deletions test/tc_node_edit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@ def setup
def teardown
@doc = nil
end

def first_node
@doc.root.child
end

def second_node
first_node.next
end

def third_node
second_node.next
end

def test_add_next_01
first_node.next = XML::Node.new('num', 'one-and-a-half')
assert_equal('<test><num>one</num><num>one-and-a-half</num><num>two</num><num>three</num></test>',
Expand Down Expand Up @@ -97,6 +97,30 @@ def test_reuse_removed_node
@doc.root.to_s.gsub(/\n\s*/,''))
end

def test_append_existing_node
doc = XML::Parser.string('<top>a<bottom>b<one>first</one><two>second</two>c</bottom>d</top>').parse
node1 = doc.find_first('//two')

doc.root << node1
assert_equal('<top>a<bottom>b<one>first</one>c</bottom>d<two>second</two></top>',
doc.root.to_s)
end

def test_wrong_doc
doc1 = XML::Parser.string('<nums><one></one></nums>').parse
doc2 = XML::Parser.string('<nums><two></two></nums>').parse

node = doc1.root.child

error = assert_raise(XML::Error) do
doc2.root << node
end

assert_equal(' Nodes belong to different documents. You must first import the by calling XML::Document.import.',
error.to_s)
end


# This test is to verify that an earlier reported bug has been fixed
def test_merge
documents = []
Expand Down

0 comments on commit 81853a6

Please sign in to comment.