libxml-jruby 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/History.txt +4 -0
- data/README.txt +50 -0
- data/Rakefile +19 -0
- data/VERSION +1 -0
- data/VERSION.yml +5 -0
- data/lib/libxml-jruby.rb +84 -0
- data/lib/libxml-jruby/xml.rb +1 -0
- data/lib/libxml-jruby/xml/attr.rb +46 -0
- data/lib/libxml-jruby/xml/attributes.rb +68 -0
- data/lib/libxml-jruby/xml/document.rb +52 -0
- data/lib/libxml-jruby/xml/dtd.rb +25 -0
- data/lib/libxml-jruby/xml/node.rb +285 -0
- data/lib/libxml-jruby/xml/ns.rb +19 -0
- data/lib/libxml-jruby/xml/parser.rb +121 -0
- data/lib/libxml-jruby/xml/xpath.rb +98 -0
- data/lib/libxml.rb +1 -0
- data/lib/xml.rb +13 -0
- data/lib/xml/libxml.rb +8 -0
- data/test/etc_doc_to_s.rb +19 -0
- data/test/ets_copy_bug.rb +21 -0
- data/test/ets_copy_bug3.rb +38 -0
- data/test/ets_doc_file.rb +15 -0
- data/test/ets_doc_to_s.rb +21 -0
- data/test/ets_gpx.rb +26 -0
- data/test/ets_node_gc.rb +21 -0
- data/test/ets_tsr.rb +9 -0
- data/test/model/default_validation_bug.rb +0 -0
- data/test/tc_attributes.rb +110 -0
- data/test/tc_deprecated_require.rb +13 -0
- data/test/tc_document.rb +97 -0
- data/test/tc_document_write.rb +139 -0
- data/test/tc_dtd.rb +70 -0
- data/test/tc_html_parser.rb +63 -0
- data/test/tc_node.rb +108 -0
- data/test/tc_node_attr.rb +176 -0
- data/test/tc_node_cdata.rb +51 -0
- data/test/tc_node_comment.rb +32 -0
- data/test/tc_node_copy.rb +40 -0
- data/test/tc_node_edit.rb +98 -0
- data/test/tc_node_set.rb +24 -0
- data/test/tc_node_set2.rb +37 -0
- data/test/tc_node_text.rb +17 -0
- data/test/tc_node_xlink.rb +28 -0
- data/test/tc_ns.rb +18 -0
- data/test/tc_parser.rb +308 -0
- data/test/tc_parser_context.rb +126 -0
- data/test/tc_properties.rb +37 -0
- data/test/tc_reader.rb +112 -0
- data/test/tc_relaxng.rb +39 -0
- data/test/tc_sax_parser.rb +113 -0
- data/test/tc_schema.rb +39 -0
- data/test/tc_traversal.rb +220 -0
- data/test/tc_well_formed.rb +11 -0
- data/test/tc_xinclude.rb +26 -0
- data/test/tc_xpath.rb +130 -0
- data/test/tc_xpath_context.rb +72 -0
- data/test/tc_xpointer.rb +78 -0
- data/test/test_libxml-jruby.rb +0 -0
- data/test/test_suite.rb +31 -0
- data/test/ts_working.rb +31 -0
- metadata +121 -0
data/test/tc_node.rb
ADDED
@@ -0,0 +1,108 @@
|
|
1
|
+
require "xml"
|
2
|
+
require 'test/unit'
|
3
|
+
|
4
|
+
class TestNode < Test::Unit::TestCase
|
5
|
+
def setup
|
6
|
+
xp = XML::Parser.new()
|
7
|
+
str = '<ruby_array uga="booga" foo="bar"><fixnum>one</fixnum><fixnum>two</fixnum></ruby_array>'
|
8
|
+
assert_equal(str, xp.string = str)
|
9
|
+
@doc = xp.parse
|
10
|
+
end
|
11
|
+
|
12
|
+
def teardown
|
13
|
+
@doc = nil
|
14
|
+
end
|
15
|
+
|
16
|
+
def nodes
|
17
|
+
@doc.find('/ruby_array/fixnum')
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_doc_class
|
21
|
+
assert_instance_of(XML::Document, @doc)
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_root_class
|
25
|
+
assert_instance_of(XML::Node, @doc.root)
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_node_class
|
29
|
+
for n in nodes
|
30
|
+
assert_instance_of(XML::Node, n)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_find_class
|
35
|
+
set = @doc.find('/ruby_array/fixnum')
|
36
|
+
assert_instance_of(XML::XPath::Object, set)
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_node_child_get
|
40
|
+
assert_instance_of(TrueClass, @doc.root.child?)
|
41
|
+
assert_instance_of(XML::Node, @doc.root.child)
|
42
|
+
assert_equal('fixnum', @doc.root.child.name)
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_node_doc
|
46
|
+
for n in nodes
|
47
|
+
assert_instance_of(XML::Document, n.doc) if n.document?
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_node_type_name
|
52
|
+
assert_equal('element', nodes[0].node_type_name)
|
53
|
+
assert_equal('element', nodes[1].node_type_name)
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_node_find
|
57
|
+
set = @doc.root.find('./fixnum').set
|
58
|
+
assert_instance_of(XML::Node::Set, set)
|
59
|
+
for node in set
|
60
|
+
assert_instance_of(XML::Node, node)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_equality
|
65
|
+
node_a = @doc.find('/ruby_array/fixnum').first
|
66
|
+
node_b = @doc.root.child
|
67
|
+
assert(node_a == node_b)
|
68
|
+
assert(node_a.eql?(node_b))
|
69
|
+
assert(node_a.equal?(node_b))
|
70
|
+
|
71
|
+
xp2 = XML::Parser.new()
|
72
|
+
xp2.string = '<ruby_array uga="booga" foo="bar"><fixnum>one</fixnum><fixnum>two</fixnum></ruby_array>'
|
73
|
+
doc2 = xp2.parse
|
74
|
+
|
75
|
+
node_a2 = doc2.find('/ruby_array/fixnum').first
|
76
|
+
|
77
|
+
assert(node_a.to_s == node_a2.to_s)
|
78
|
+
assert(node_a == node_a2)
|
79
|
+
assert(node_a.eql?(node_a2))
|
80
|
+
assert(!node_a.equal?(node_a2))
|
81
|
+
end
|
82
|
+
|
83
|
+
def test_equality_nil
|
84
|
+
node = @doc.root
|
85
|
+
assert(node != nil)
|
86
|
+
end
|
87
|
+
|
88
|
+
def test_equality_wrong_type
|
89
|
+
node = @doc.root
|
90
|
+
|
91
|
+
assert_raises(TypeError) do
|
92
|
+
assert(node != 'abc')
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
def test_content()
|
97
|
+
assert_equal('onetwo', @doc.root.content)
|
98
|
+
|
99
|
+
first = @doc.root.child
|
100
|
+
assert_equal('one', first.content)
|
101
|
+
assert_equal('two', first.next.content)
|
102
|
+
end
|
103
|
+
|
104
|
+
def test_base
|
105
|
+
doc = XML::Parser.string('<person />').parse
|
106
|
+
assert_nil(doc.root.base)
|
107
|
+
end
|
108
|
+
end
|
@@ -0,0 +1,176 @@
|
|
1
|
+
require "xml"
|
2
|
+
require 'test/unit'
|
3
|
+
|
4
|
+
class AttrNodeTest < Test::Unit::TestCase
|
5
|
+
def setup()
|
6
|
+
xp = XML::Parser.string(<<-EOS)
|
7
|
+
<CityModel
|
8
|
+
xmlns="http://www.opengis.net/examples"
|
9
|
+
xmlns:city="http://www.opengis.net/examples"
|
10
|
+
xmlns:gml="http://www.opengis.net/gml"
|
11
|
+
xmlns:xlink="http://www.w3.org/1999/xlink"
|
12
|
+
xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance"
|
13
|
+
xsi:schemaLocation="http://www.opengis.net/examples city.xsd">
|
14
|
+
<type>City</type>
|
15
|
+
<cityMember name="Cambridge"
|
16
|
+
xlink:type="simple"
|
17
|
+
xlink:title="Trinity Lane"
|
18
|
+
xlink:href="http://www.foo.net/cgi-bin/wfs?FeatureID=C10239"
|
19
|
+
gml:remoteSchema="city.xsd#xpointer(//complexType[@name='RoadType'])"/>
|
20
|
+
</CityModel>
|
21
|
+
EOS
|
22
|
+
|
23
|
+
@doc = xp.parse
|
24
|
+
end
|
25
|
+
|
26
|
+
def teardown()
|
27
|
+
@doc = nil
|
28
|
+
end
|
29
|
+
|
30
|
+
def city_member
|
31
|
+
@doc.find('/city:CityModel/city:cityMember').first
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_types
|
35
|
+
attribute = city_member.attributes.get_attribute('name')
|
36
|
+
assert_instance_of(XML::Attr, attribute)
|
37
|
+
assert_equal('attribute', attribute.node_type_name)
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_name
|
41
|
+
attribute = city_member.attributes.get_attribute('name')
|
42
|
+
assert_equal('name', attribute.name)
|
43
|
+
|
44
|
+
# FIXME Namespaced attribute, without namespace specified
|
45
|
+
# attribute = city_member.attributes.get_attribute('href')
|
46
|
+
# assert_equal('href', attribute.name)
|
47
|
+
# assert_equal('xlink', attribute.ns.prefix)
|
48
|
+
# assert_equal('http://www.w3.org/1999/xlink', attribute.ns.href)
|
49
|
+
|
50
|
+
# FIXME This should be working, review ASAP
|
51
|
+
# attribute = city_member.attributes.get_attribute_ns('http://www.w3.org/1999/xlink', 'href')
|
52
|
+
# assert_equal('href', attribute.name)
|
53
|
+
# assert_equal('xlink', attribute.ns.prefix)
|
54
|
+
# assert_equal('http://www.w3.org/1999/xlink', attribute.ns.href)
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_value
|
58
|
+
attribute = city_member.attributes.get_attribute('name')
|
59
|
+
assert_equal('Cambridge', attribute.value)
|
60
|
+
|
61
|
+
# FIXME Namespaced attribute, without namespace specified
|
62
|
+
# attribute = city_member.attributes.get_attribute('href')
|
63
|
+
# assert_equal('http://www.foo.net/cgi-bin/wfs?FeatureID=C10239', attribute.value)
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_set_value
|
67
|
+
attribute = city_member.attributes.get_attribute('name')
|
68
|
+
attribute.value = 'London'
|
69
|
+
assert_equal('London', attribute.value)
|
70
|
+
|
71
|
+
# FIXME Namespaced attribute, without namespace specified
|
72
|
+
# attribute = city_member.attributes.get_attribute('href')
|
73
|
+
# attribute.value = 'http://i.have.changed'
|
74
|
+
# assert_equal('http://i.have.changed', attribute.value)
|
75
|
+
end
|
76
|
+
|
77
|
+
def test_set_nil
|
78
|
+
attribute = city_member.attributes.get_attribute('name')
|
79
|
+
assert_raise(TypeError) do
|
80
|
+
attribute.value = nil
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def test_create
|
85
|
+
attributes = city_member.attributes
|
86
|
+
assert_equal(5, attributes.length)
|
87
|
+
|
88
|
+
attr = XML::Attr.new(city_member, 'size', '50,000')
|
89
|
+
assert_instance_of(XML::Attr, attr)
|
90
|
+
|
91
|
+
attributes = city_member.attributes
|
92
|
+
assert_equal(6, attributes.length)
|
93
|
+
|
94
|
+
assert_equal(attributes['size'], '50,000')
|
95
|
+
end
|
96
|
+
|
97
|
+
def test_create_on_node
|
98
|
+
attributes = city_member.attributes
|
99
|
+
assert_equal(5, attributes.length)
|
100
|
+
|
101
|
+
attributes['country'] = 'England'
|
102
|
+
|
103
|
+
attributes = city_member.attributes
|
104
|
+
assert_equal(6, attributes.length)
|
105
|
+
|
106
|
+
assert_equal(attributes['country'], 'England')
|
107
|
+
end
|
108
|
+
|
109
|
+
def test_create_ns
|
110
|
+
assert_equal(5, city_member.attributes.length)
|
111
|
+
|
112
|
+
ns = XML::NS.new(city_member, 'my_namepace', 'http://www.mynamespace.com')
|
113
|
+
attr = XML::Attr.new(city_member, 'rating', 'rocks', ns)
|
114
|
+
assert_instance_of(XML::Attr, attr)
|
115
|
+
# FIXME I'm not sure what is going on here, look at Attr#initialize
|
116
|
+
# assert_equal('rating', attr.name)
|
117
|
+
# assert_equal('rocks', attr.value)
|
118
|
+
|
119
|
+
attributes = city_member.attributes
|
120
|
+
assert_equal(6, attributes.length)
|
121
|
+
|
122
|
+
assert_equal('rocks', city_member['rating'])
|
123
|
+
end
|
124
|
+
|
125
|
+
def test_remove
|
126
|
+
attributes = city_member.attributes
|
127
|
+
assert_equal(5, attributes.length)
|
128
|
+
|
129
|
+
attribute = attributes.get_attribute('name')
|
130
|
+
assert_not_nil(attribute.parent)
|
131
|
+
assert(attribute.parent?)
|
132
|
+
|
133
|
+
attribute.remove!
|
134
|
+
assert_equal(4, attributes.length)
|
135
|
+
assert_nil(attribute.parent)
|
136
|
+
assert(!attribute.parent?)
|
137
|
+
end
|
138
|
+
|
139
|
+
# FIXME Ordering of Attributes is not implemented yet
|
140
|
+
# def test_first
|
141
|
+
# attribute = city_member.attributes.first
|
142
|
+
# assert_instance_of(XML::Attr, attribute)
|
143
|
+
# assert_equal('name', attribute.name)
|
144
|
+
# assert_equal('Cambridge', attribute.value)
|
145
|
+
#
|
146
|
+
# attribute = attribute.next
|
147
|
+
# assert_instance_of(XML::Attr, attribute)
|
148
|
+
# assert_equal('type', attribute.name)
|
149
|
+
# assert_equal('simple', attribute.value)
|
150
|
+
#
|
151
|
+
# attribute = attribute.next
|
152
|
+
# assert_instance_of(XML::Attr, attribute)
|
153
|
+
# assert_equal('title', attribute.name)
|
154
|
+
# assert_equal('Trinity Lane', attribute.value)
|
155
|
+
#
|
156
|
+
# attribute = attribute.next
|
157
|
+
# assert_instance_of(XML::Attr, attribute)
|
158
|
+
# assert_equal('href', attribute.name)
|
159
|
+
# assert_equal('http://www.foo.net/cgi-bin/wfs?FeatureID=C10239', attribute.value)
|
160
|
+
#
|
161
|
+
# attribute = attribute.next
|
162
|
+
# assert_instance_of(XML::Attr, attribute)
|
163
|
+
# assert_equal('remoteSchema', attribute.name)
|
164
|
+
# assert_equal("city.xsd#xpointer(//complexType[@name='RoadType'])", attribute.value)
|
165
|
+
#
|
166
|
+
# attribute = attribute.next
|
167
|
+
# assert_nil(attribute)
|
168
|
+
# end
|
169
|
+
|
170
|
+
def test_no_attributes
|
171
|
+
element = @doc.find('/city:CityModel/city:type').first
|
172
|
+
|
173
|
+
assert_not_nil(element.attributes)
|
174
|
+
assert_equal(0, element.attributes.length)
|
175
|
+
end
|
176
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'xml'
|
2
|
+
require 'test/unit'
|
3
|
+
|
4
|
+
class CDataCommentTest < Test::Unit::TestCase
|
5
|
+
def setup
|
6
|
+
xp = XML::Parser.new()
|
7
|
+
str = '<root></root>'
|
8
|
+
assert_equal(str, xp.string = str)
|
9
|
+
@doc = xp.parse
|
10
|
+
assert_instance_of(XML::Document, @doc)
|
11
|
+
@root = @doc.root
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_node_type
|
15
|
+
cnode = XML::Node.new_cdata('test cdata')
|
16
|
+
assert_equal(XML::Node::CDATA_SECTION_NODE, cnode.node_type)
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_add_cdata
|
20
|
+
@root << XML::Node.new_cdata('mycdata')
|
21
|
+
assert_equal '<root><![CDATA[mycdata]]></root>',
|
22
|
+
@root.to_s.gsub(/\n\s*/,'')
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_add_cdata_2
|
26
|
+
@root << XML::Node.new_cdata('mycdata')
|
27
|
+
assert_equal 'cdata',
|
28
|
+
@root.child.node_type_name
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_add_cdata_3
|
32
|
+
@root << el = XML::Node.new_cdata('mycdata')
|
33
|
+
el << "_this_is_added"
|
34
|
+
assert_equal '<root><![CDATA[mycdata_this_is_added]]></root>',
|
35
|
+
@root.to_s.gsub(/\n\s*/,'')
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_attributes
|
39
|
+
cnode = XML::Node.new_cdata('test cdata')
|
40
|
+
assert_equal(0, cnode.attributes.length)
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_set_cdata_attribute
|
44
|
+
cnode = XML::Node.new_cdata('test cdata')
|
45
|
+
|
46
|
+
# Can't create attributes on non-element nodes
|
47
|
+
assert_raise(ArgumentError) do
|
48
|
+
cnode['attr'] = '123'
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require "xml"
|
2
|
+
require 'test/unit'
|
3
|
+
|
4
|
+
class NodeCommentTest < Test::Unit::TestCase
|
5
|
+
def setup()
|
6
|
+
xp = XML::Parser.new()
|
7
|
+
str = '<root></root>'
|
8
|
+
assert_equal(str, xp.string = str)
|
9
|
+
@doc = xp.parse
|
10
|
+
assert_instance_of(XML::Document, @doc)
|
11
|
+
@root = @doc.root
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_libxml_node_add_comment_01
|
15
|
+
@root << XML::Node.new_comment('mycomment')
|
16
|
+
assert_equal '<root><!--mycomment--></root>',
|
17
|
+
@root.to_s.gsub(/\n\s*/,'')
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_libxml_node_add_comment_02
|
21
|
+
@root << XML::Node.new_comment('mycomment')
|
22
|
+
assert_equal 'comment',
|
23
|
+
@root.child.node_type_name
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_libxml_node_add_comment_03
|
27
|
+
@root << el = XML::Node.new_comment('mycomment')
|
28
|
+
el << "_this_is_added"
|
29
|
+
assert_equal '<root><!--mycomment_this_is_added--></root>',
|
30
|
+
@root.to_s.gsub(/\n\s*/,'')
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require "xml"
|
2
|
+
require 'test/unit'
|
3
|
+
|
4
|
+
# see mailing list archive
|
5
|
+
# [libxml-devel] Segmentation fault when add the cloned/copied node
|
6
|
+
# 2007/11/27 20:51
|
7
|
+
|
8
|
+
class TC_XML_Node_Copy < Test::Unit::TestCase
|
9
|
+
def setup
|
10
|
+
str = <<-STR
|
11
|
+
<html><body>
|
12
|
+
<div class="textarea" id="t1" style="STATIC">foo</div>
|
13
|
+
<div class="textarea" id="t2" style="STATIC">bar</div>
|
14
|
+
</body></html>
|
15
|
+
STR
|
16
|
+
|
17
|
+
doc = XML::Parser.string(str).parse
|
18
|
+
|
19
|
+
xpath = "//div"
|
20
|
+
@div1 = doc.find(xpath).to_a[0]
|
21
|
+
@div2 = doc.find(xpath).to_a[1]
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_libxml_node_copy_not_segv
|
25
|
+
@div2.each do |child|
|
26
|
+
c = child.copy(false)
|
27
|
+
@div1.child_add(c)
|
28
|
+
end
|
29
|
+
assert @div1.to_s =~ /foo/
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_libxml_node_clone_not_segv
|
33
|
+
@div2.each do |child|
|
34
|
+
c = child.clone
|
35
|
+
@div1.child_add(c)
|
36
|
+
end
|
37
|
+
assert @div1.to_s =~ /foo/
|
38
|
+
end
|
39
|
+
|
40
|
+
end # TC_XML_Node_Copy
|
@@ -0,0 +1,98 @@
|
|
1
|
+
require "xml"
|
2
|
+
require 'test/unit'
|
3
|
+
|
4
|
+
class TestNodeEdit < Test::Unit::TestCase
|
5
|
+
def setup
|
6
|
+
xp = XML::Parser.new()
|
7
|
+
xp.string = '<test><num>one</num><num>two</num><num>three</num></test>'
|
8
|
+
@doc = xp.parse
|
9
|
+
end
|
10
|
+
|
11
|
+
def teardown
|
12
|
+
@doc = nil
|
13
|
+
end
|
14
|
+
|
15
|
+
def first_node
|
16
|
+
@doc.root.child
|
17
|
+
end
|
18
|
+
|
19
|
+
def second_node
|
20
|
+
first_node.next
|
21
|
+
end
|
22
|
+
|
23
|
+
def third_node
|
24
|
+
second_node.next
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_add_next_01
|
28
|
+
first_node.next = XML::Node.new('num', 'one-and-a-half')
|
29
|
+
assert_equal('<test><num>one</num><num>one-and-a-half</num><num>two</num><num>three</num></test>',
|
30
|
+
@doc.root.to_s.gsub(/\n\s*/,''))
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_add_next_02
|
34
|
+
second_node.next = XML::Node.new('num', 'two-and-a-half')
|
35
|
+
assert_equal('<test><num>one</num><num>two</num><num>two-and-a-half</num><num>three</num></test>',
|
36
|
+
@doc.root.to_s.gsub(/\n\s*/,''))
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_add_next_03
|
40
|
+
third_node.next = XML::Node.new('num', 'four')
|
41
|
+
assert_equal '<test><num>one</num><num>two</num><num>three</num><num>four</num></test>',
|
42
|
+
@doc.root.to_s.gsub(/\n\s*/,'')
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_add_prev_01
|
46
|
+
first_node.prev = XML::Node.new('num', 'half')
|
47
|
+
assert_equal '<test><num>half</num><num>one</num><num>two</num><num>three</num></test>',
|
48
|
+
@doc.root.to_s.gsub(/\n\s*/,'')
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_add_prev_02
|
52
|
+
second_node.prev = XML::Node.new('num', 'one-and-a-half')
|
53
|
+
assert_equal '<test><num>one</num><num>one-and-a-half</num><num>two</num><num>three</num></test>',
|
54
|
+
@doc.root.to_s.gsub(/\n\s*/,'')
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_add_prev_03
|
58
|
+
third_node.prev = XML::Node.new('num', 'two-and-a-half')
|
59
|
+
assert_equal '<test><num>one</num><num>two</num><num>two-and-a-half</num><num>three</num></test>',
|
60
|
+
@doc.root.to_s.gsub(/\n\s*/,'')
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_remove_node()
|
64
|
+
first_node.remove!
|
65
|
+
assert_equal('<test><num>two</num><num>three</num></test>',
|
66
|
+
@doc.root.to_s.gsub(/\n\s*/,''))
|
67
|
+
end
|
68
|
+
|
69
|
+
# This test is to verify that an earlier reported bug has been fixed
|
70
|
+
def test_merge
|
71
|
+
documents = []
|
72
|
+
|
73
|
+
# Read in 500 documents
|
74
|
+
500.times do
|
75
|
+
documents << XML::Parser.string(File.read(File.join(File.dirname(__FILE__), 'model', 'merge_bug_data.xml'))).parse
|
76
|
+
end
|
77
|
+
|
78
|
+
master_doc = documents.shift
|
79
|
+
documents.inject(master_doc) do |master_doc, child_doc|
|
80
|
+
master_body = master_doc.find("//body").first
|
81
|
+
child_body = child_doc.find("//body").first
|
82
|
+
|
83
|
+
child_element = child_body.detect do |node|
|
84
|
+
node.element?
|
85
|
+
end
|
86
|
+
|
87
|
+
master_body << child_element.copy(true)
|
88
|
+
master_doc
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
def test_append_chain
|
93
|
+
node = XML::Node.new('foo') << XML::Node.new('bar') << "bars contents"
|
94
|
+
assert_equal('bars contents',
|
95
|
+
node.to_s)
|
96
|
+
assert_equal("<foo>\n <bar>bars contents</bar>\n</foo>", node.parent.parent.to_s)
|
97
|
+
end
|
98
|
+
end
|