libxml-jruby-fixed 1.0.0-jruby

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.
Files changed (92) hide show
  1. data/History.txt +4 -0
  2. data/Manifest.txt +91 -0
  3. data/README.txt +50 -0
  4. data/Rakefile +40 -0
  5. data/lib/libxml-jruby.rb +84 -0
  6. data/lib/libxml-jruby/xml.rb +1 -0
  7. data/lib/libxml-jruby/xml/attr.rb +46 -0
  8. data/lib/libxml-jruby/xml/attributes.rb +68 -0
  9. data/lib/libxml-jruby/xml/document.rb +52 -0
  10. data/lib/libxml-jruby/xml/dtd.rb +25 -0
  11. data/lib/libxml-jruby/xml/node.rb +285 -0
  12. data/lib/libxml-jruby/xml/ns.rb +19 -0
  13. data/lib/libxml-jruby/xml/parser.rb +121 -0
  14. data/lib/libxml-jruby/xml/xpath.rb +98 -0
  15. data/lib/libxml.rb +1 -0
  16. data/lib/xml.rb +13 -0
  17. data/lib/xml/libxml.rb +8 -0
  18. data/script/benchmark/depixelate.rb +633 -0
  19. data/script/benchmark/hamlet.xml +9055 -0
  20. data/script/benchmark/sock_entries.xml +507 -0
  21. data/script/benchmark/throughput.rb +40 -0
  22. data/script/benchmark/xml_benchmarks.rb +228 -0
  23. data/script/test +6 -0
  24. data/tasks/ann.rake +81 -0
  25. data/tasks/bones.rake +21 -0
  26. data/tasks/gem.rake +126 -0
  27. data/tasks/git.rake +41 -0
  28. data/tasks/manifest.rake +49 -0
  29. data/tasks/notes.rake +28 -0
  30. data/tasks/post_load.rake +39 -0
  31. data/tasks/rdoc.rake +51 -0
  32. data/tasks/rubyforge.rake +57 -0
  33. data/tasks/setup.rb +268 -0
  34. data/tasks/spec.rake +55 -0
  35. data/tasks/svn.rake +48 -0
  36. data/tasks/test.rake +38 -0
  37. data/test/etc_doc_to_s.rb +19 -0
  38. data/test/ets_copy_bug.rb +21 -0
  39. data/test/ets_copy_bug3.rb +38 -0
  40. data/test/ets_doc_file.rb +15 -0
  41. data/test/ets_doc_to_s.rb +21 -0
  42. data/test/ets_gpx.rb +26 -0
  43. data/test/ets_node_gc.rb +21 -0
  44. data/test/ets_test.xml +2 -0
  45. data/test/ets_tsr.rb +9 -0
  46. data/test/model/books.xml +147 -0
  47. data/test/model/default_validation_bug.rb +0 -0
  48. data/test/model/merge_bug_data.xml +58 -0
  49. data/test/model/rubynet.xml +78 -0
  50. data/test/model/rubynet_project +1 -0
  51. data/test/model/saxtest.xml +5 -0
  52. data/test/model/shiporder.rnc +28 -0
  53. data/test/model/shiporder.rng +86 -0
  54. data/test/model/shiporder.xml +23 -0
  55. data/test/model/shiporder.xsd +31 -0
  56. data/test/model/simple.xml +7 -0
  57. data/test/model/soap.xml +27 -0
  58. data/test/model/xinclude.xml +5 -0
  59. data/test/tc_attributes.rb +110 -0
  60. data/test/tc_deprecated_require.rb +13 -0
  61. data/test/tc_document.rb +97 -0
  62. data/test/tc_document_write.rb +139 -0
  63. data/test/tc_dtd.rb +70 -0
  64. data/test/tc_html_parser.rb +63 -0
  65. data/test/tc_node.rb +108 -0
  66. data/test/tc_node_attr.rb +176 -0
  67. data/test/tc_node_cdata.rb +51 -0
  68. data/test/tc_node_comment.rb +32 -0
  69. data/test/tc_node_copy.rb +40 -0
  70. data/test/tc_node_edit.rb +98 -0
  71. data/test/tc_node_set.rb +24 -0
  72. data/test/tc_node_set2.rb +37 -0
  73. data/test/tc_node_text.rb +17 -0
  74. data/test/tc_node_xlink.rb +28 -0
  75. data/test/tc_ns.rb +18 -0
  76. data/test/tc_parser.rb +308 -0
  77. data/test/tc_parser_context.rb +126 -0
  78. data/test/tc_properties.rb +37 -0
  79. data/test/tc_reader.rb +112 -0
  80. data/test/tc_relaxng.rb +39 -0
  81. data/test/tc_sax_parser.rb +113 -0
  82. data/test/tc_schema.rb +39 -0
  83. data/test/tc_traversal.rb +220 -0
  84. data/test/tc_well_formed.rb +11 -0
  85. data/test/tc_xinclude.rb +26 -0
  86. data/test/tc_xpath.rb +130 -0
  87. data/test/tc_xpath_context.rb +72 -0
  88. data/test/tc_xpointer.rb +78 -0
  89. data/test/test_libxml-jruby.rb +0 -0
  90. data/test/test_suite.rb +31 -0
  91. data/test/ts_working.rb +31 -0
  92. metadata +146 -0
@@ -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
@@ -0,0 +1,24 @@
1
+ require "xml"
2
+ require 'test/unit'
3
+
4
+ class TC_XML_Node_Set < 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
+ assert_instance_of(XML::Document, doc)
11
+ @set = doc.find('/ruby_array/fixnum').set
12
+ assert_instance_of(XML::Node::Set, @set)
13
+ end
14
+
15
+ def teardown()
16
+ @set = nil
17
+ end
18
+
19
+ def test_libxml_nodeset_each()
20
+ @set.each do |n|
21
+ assert_instance_of(XML::Node, n)
22
+ end
23
+ end
24
+ end # TC_XML_Document
@@ -0,0 +1,37 @@
1
+ require "xml"
2
+ require 'test/unit'
3
+
4
+ class TC_XML_Node_Set2 < 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
+ assert_instance_of(XML::Document, doc)
11
+ @one = doc.root.child
12
+ @two = @one.next
13
+ @set = doc.find('/ruby_array/fixnum').set
14
+ @emptyset = doc.find('/fixnum').set
15
+ assert_instance_of(XML::Node::Set, @set)
16
+ end
17
+
18
+ def teardown()
19
+ @set, @emptyset, @one, @two = [nil] * 4
20
+ end
21
+
22
+ def test_libxml_nodeset_to_a()
23
+ assert_equal [@one, @two], @set.to_a
24
+ assert_equal [], @emptyset.to_a
25
+ end
26
+
27
+ def test_libxml_nodeset_empty?()
28
+ assert ! @set.empty?
29
+ assert @emptyset.empty?
30
+ end
31
+
32
+ def test_libxml_nodeset_first()
33
+ assert_equal @one.to_s, @set.first.to_s
34
+ assert_equal nil, @emptyset.first
35
+ end
36
+
37
+ end # TC_XML_Document