1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
|
# $Id: tc_xml_node4.rb 142 2007-08-29 18:56:22Z danj $
require "libxml_test"
require 'test/unit'
class TC_XML_Node4 < Test::Unit::TestCase
def setup()
xp = XML::Parser.new()
@str = '<ruby_array uga="booga" foo="bar"><fixnum>one</fixnum><fixnum>two</fixnum></ruby_array>'
assert_equal(@str, xp.string = @str)
doc = xp.parse
xp2=XML::Parser.new()
xp2.string=@str
@doc2 = xp2.parse
assert_instance_of(XML::Document, doc)
assert_instance_of(XML::Node, doc.root)
@root = doc.root
assert_instance_of(XML::Node, @root)
end
def teardown()
@root = nil
end
def test_xml_node_eql?()
first1 = @root.child
first2 = @doc2.root.child
assert_not_equal first1.object_id, first2.object_id
assert first1.eql?(first2)
assert first2.eql?(first1)
assert_equal first1, first2
end
def test_xml_node_hash()
first1 = @root.child
first2 = @doc2.root.child
assert_not_equal first1.object_id, first2.object_id
assert_equal first1.hash, first2.hash
end
def test_01_xml_node_remove!()
first = @root.child
assert_equal 'fixnum', first.name
assert_equal 'fixnum', first.next.name
first.next.remove!
assert_equal 'fixnum', first.name
assert_equal nil, first.next
end
def test_02_xml_node_remove!()
first = @root.child
assert_equal 'fixnum', first.name
assert_equal 'fixnum', first.next.name
assert_equal 'one', first.content
first.remove!
first = @root.child
assert_equal 'fixnum', first.name
assert_equal nil, first.next
assert_equal 'two', first.content
end
# TODO need to test namespace support
def test_xml_node_find_first()
first = @root.find_first('//fixnum')
assert_equal 'one', first.content
end
def test_xml_node_property_set_remove()
assert_equal 'booga', @root['uga']
@root['uga'] = nil
assert_equal nil , @root['uga']
assert_equal "<ruby_array foo=\"bar\">\n <fixnum>one</fixnum>\n <fixnum>two</fixnum>\n</ruby_array>",
@root.to_s
end
end
|