libxml-ruby 5.0.6 → 6.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.
- checksums.yaml +4 -4
- data/{HISTORY → CHANGELOG.md} +875 -930
- data/LICENSE +20 -20
- data/README.md +67 -0
- data/Rakefile +13 -34
- data/ext/libxml/extconf.rb +34 -20
- data/ext/libxml/libxml.c +2 -14
- data/ext/libxml/ruby_libxml.h +1 -1
- data/ext/libxml/ruby_xml_attr.c +27 -22
- data/ext/libxml/ruby_xml_attr.h +1 -0
- data/ext/libxml/ruby_xml_attr_decl.c +19 -12
- data/ext/libxml/ruby_xml_attributes.c +18 -9
- data/ext/libxml/ruby_xml_document.c +111 -98
- data/ext/libxml/ruby_xml_document.h +1 -0
- data/ext/libxml/ruby_xml_dtd.c +49 -19
- data/ext/libxml/ruby_xml_dtd.h +1 -0
- data/ext/libxml/ruby_xml_html_parser.c +1 -1
- data/ext/libxml/ruby_xml_html_parser_context.c +19 -6
- data/ext/libxml/ruby_xml_html_parser_context.h +1 -0
- data/ext/libxml/ruby_xml_input_cbg.c +45 -17
- data/ext/libxml/ruby_xml_io.c +3 -1
- data/ext/libxml/ruby_xml_namespace.c +20 -12
- data/ext/libxml/ruby_xml_namespace.h +1 -0
- data/ext/libxml/ruby_xml_namespaces.c +40 -20
- data/ext/libxml/ruby_xml_node.c +71 -32
- data/ext/libxml/ruby_xml_node.h +2 -0
- data/ext/libxml/ruby_xml_parser.c +1 -1
- data/ext/libxml/ruby_xml_parser_context.c +54 -47
- data/ext/libxml/ruby_xml_parser_context.h +1 -0
- data/ext/libxml/ruby_xml_reader.c +25 -15
- data/ext/libxml/ruby_xml_registry.c +31 -0
- data/ext/libxml/ruby_xml_registry.h +22 -0
- data/ext/libxml/ruby_xml_relaxng.c +21 -5
- data/ext/libxml/ruby_xml_relaxng.h +1 -0
- data/ext/libxml/ruby_xml_sax_parser.c +1 -1
- data/ext/libxml/ruby_xml_schema.c +18 -11
- data/ext/libxml/ruby_xml_schema.h +1 -0
- data/ext/libxml/ruby_xml_schema_attribute.c +7 -7
- data/ext/libxml/ruby_xml_schema_element.c +8 -8
- data/ext/libxml/ruby_xml_schema_facet.c +7 -7
- data/ext/libxml/ruby_xml_schema_type.c +12 -19
- data/ext/libxml/ruby_xml_version.h +4 -4
- data/ext/libxml/ruby_xml_writer.c +18 -6
- data/ext/libxml/ruby_xml_xpath.c +2 -2
- data/ext/libxml/ruby_xml_xpath.h +1 -1
- data/ext/libxml/ruby_xml_xpath_context.c +72 -26
- data/ext/libxml/ruby_xml_xpath_expression.c +11 -5
- data/ext/libxml/ruby_xml_xpath_expression.h +1 -0
- data/ext/libxml/ruby_xml_xpath_object.c +69 -54
- data/ext/libxml/ruby_xml_xpath_object.h +3 -1
- data/ext/vc/libxml_ruby/libxml_ruby.vcxproj +271 -0
- data/ext/xcode/libxml-ruby.xcodeproj/project.pbxproj +633 -0
- data/ext/xcode/libxml-ruby.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
- data/ext/xcode/libxml-ruby.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -0
- data/ext/xcode/libxml-ruby.xcodeproj/xcshareddata/xcschemes/libxml-ruby.xcscheme +80 -0
- data/lib/libxml/document.rb +0 -29
- data/lib/libxml/error.rb +30 -3
- data/lib/libxml/html_parser.rb +0 -16
- data/lib/libxml/node.rb +1 -3
- data/lib/libxml/parser.rb +0 -8
- data/lib/libxml/schema/attribute.rb +27 -19
- data/lib/libxml/schema/element.rb +20 -0
- data/lib/libxml/schema/type.rb +44 -21
- data/lib/libxml/schema.rb +47 -47
- data/lib/libxml-ruby.rb +30 -30
- data/libxml-ruby.gemspec +12 -16
- data/test/c14n/result/1-1-without-comments/example-1 +3 -3
- data/test/c14n/result/1-1-without-comments/example-2 +10 -10
- data/test/c14n/result/1-1-without-comments/example-3 +13 -13
- data/test/c14n/result/1-1-without-comments/example-4 +8 -8
- data/test/c14n/result/1-1-without-comments/example-5 +2 -2
- data/test/c14n/result/with-comments/example-1 +5 -5
- data/test/c14n/result/with-comments/example-2 +10 -10
- data/test/c14n/result/with-comments/example-3 +13 -13
- data/test/c14n/result/with-comments/example-4 +8 -8
- data/test/c14n/result/with-comments/example-5 +3 -3
- data/test/c14n/result/without-comments/example-1 +3 -3
- data/test/c14n/result/without-comments/example-2 +10 -10
- data/test/c14n/result/without-comments/example-3 +13 -13
- data/test/c14n/result/without-comments/example-4 +8 -8
- data/test/c14n/result/without-comments/example-5 +2 -2
- data/test/test_attr.rb +179 -180
- data/test/test_attr_decl.rb +131 -131
- data/test/test_attributes.rb +135 -135
- data/test/test_canonicalize.rb +122 -120
- data/test/test_document.rb +2 -4
- data/test/test_dtd.rb +12 -4
- data/test/test_encoding_sax.rb +114 -114
- data/test/test_error.rb +1 -1
- data/test/test_html_parser.rb +6 -2
- data/test/test_html_parser_context.rb +22 -22
- data/test/test_input_callbacks.rb +36 -0
- data/test/test_namespace.rb +1 -1
- data/test/test_namespaces.rb +200 -200
- data/test/test_node.rb +16 -0
- data/test/test_node_cdata.rb +50 -50
- data/test/test_node_comment.rb +32 -32
- data/test/test_node_copy.rb +40 -40
- data/test/test_node_edit.rb +176 -158
- data/test/test_node_pi.rb +37 -37
- data/test/test_node_text.rb +69 -69
- data/test/test_node_xlink.rb +28 -28
- data/test/test_parser.rb +5 -41
- data/test/test_parser_context.rb +198 -198
- data/test/test_properties.rb +38 -38
- data/test/test_reader.rb +55 -6
- data/test/test_relaxng.rb +59 -53
- data/test/test_sax_parser.rb +345 -345
- data/test/test_schema.rb +28 -0
- data/test/test_traversal.rb +152 -152
- data/test/test_writer.rb +0 -31
- data/test/test_xinclude.rb +20 -20
- data/test/test_xml.rb +3 -7
- data/test/test_xpath.rb +244 -244
- data/test/test_xpath_context.rb +87 -87
- data/test/test_xpath_expression.rb +37 -37
- metadata +32 -25
- data/README.rdoc +0 -208
- data/ext/libxml/extconf.h +0 -4
- data/ext/libxml/ruby_xml_cbg.c +0 -85
- data/lib/libxml/hpricot.rb +0 -78
- data/lib/libxml.rb +0 -5
- data/lib/xml/libxml.rb +0 -10
- data/lib/xml.rb +0 -14
- data/script/benchmark/depixelate +0 -634
- data/script/benchmark/hamlet.xml +0 -9055
- data/script/benchmark/parsecount +0 -170
- data/script/benchmark/sock_entries.xml +0 -507
- data/script/benchmark/throughput +0 -41
- data/script/test +0 -6
- data/test/test_deprecated_require.rb +0 -12
data/test/test_node_copy.rb
CHANGED
|
@@ -1,40 +1,40 @@
|
|
|
1
|
-
# encoding: UTF-8
|
|
2
|
-
|
|
3
|
-
require_relative './test_helper'
|
|
4
|
-
|
|
5
|
-
# see mailing list archive
|
|
6
|
-
# [libxml-devel] Segmentation fault when add the cloned/copied node
|
|
7
|
-
# 2007/11/27 20:51
|
|
8
|
-
|
|
9
|
-
class TestNodeCopy < Minitest::Test
|
|
10
|
-
def setup
|
|
11
|
-
str = <<-STR
|
|
12
|
-
<html><body>
|
|
13
|
-
<div class="textarea" id="t1" style="STATIC">foo</div>
|
|
14
|
-
<div class="textarea" id="t2" style="STATIC">bar</div>
|
|
15
|
-
</body></html>
|
|
16
|
-
STR
|
|
17
|
-
|
|
18
|
-
doc = LibXML::XML::Parser.string(str).parse
|
|
19
|
-
|
|
20
|
-
xpath = "//div"
|
|
21
|
-
@div1 = doc.find(xpath).to_a[0]
|
|
22
|
-
@div2 = doc.find(xpath).to_a[1]
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
def test_libxml_node_copy_not_segv
|
|
26
|
-
@div2.each do |child|
|
|
27
|
-
c = child.copy(false)
|
|
28
|
-
@div1 << c
|
|
29
|
-
end
|
|
30
|
-
assert @div1.to_s =~ /foo/
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
def test_libxml_node_clone_not_segv
|
|
34
|
-
@div2.each do |child|
|
|
35
|
-
c = child.clone
|
|
36
|
-
@div1 << c
|
|
37
|
-
end
|
|
38
|
-
assert @div1.to_s =~ /foo/
|
|
39
|
-
end
|
|
40
|
-
end
|
|
1
|
+
# encoding: UTF-8
|
|
2
|
+
|
|
3
|
+
require_relative './test_helper'
|
|
4
|
+
|
|
5
|
+
# see mailing list archive
|
|
6
|
+
# [libxml-devel] Segmentation fault when add the cloned/copied node
|
|
7
|
+
# 2007/11/27 20:51
|
|
8
|
+
|
|
9
|
+
class TestNodeCopy < Minitest::Test
|
|
10
|
+
def setup
|
|
11
|
+
str = <<-STR
|
|
12
|
+
<html><body>
|
|
13
|
+
<div class="textarea" id="t1" style="STATIC">foo</div>
|
|
14
|
+
<div class="textarea" id="t2" style="STATIC">bar</div>
|
|
15
|
+
</body></html>
|
|
16
|
+
STR
|
|
17
|
+
|
|
18
|
+
doc = LibXML::XML::Parser.string(str).parse
|
|
19
|
+
|
|
20
|
+
xpath = "//div"
|
|
21
|
+
@div1 = doc.find(xpath).to_a[0]
|
|
22
|
+
@div2 = doc.find(xpath).to_a[1]
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def test_libxml_node_copy_not_segv
|
|
26
|
+
@div2.each do |child|
|
|
27
|
+
c = child.copy(false)
|
|
28
|
+
@div1 << c
|
|
29
|
+
end
|
|
30
|
+
assert @div1.to_s =~ /foo/
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def test_libxml_node_clone_not_segv
|
|
34
|
+
@div2.each do |child|
|
|
35
|
+
c = child.clone
|
|
36
|
+
@div1 << c
|
|
37
|
+
end
|
|
38
|
+
assert @div1.to_s =~ /foo/
|
|
39
|
+
end
|
|
40
|
+
end
|
data/test/test_node_edit.rb
CHANGED
|
@@ -1,158 +1,176 @@
|
|
|
1
|
-
# encoding: UTF-8
|
|
2
|
-
|
|
3
|
-
require_relative './test_helper'
|
|
4
|
-
|
|
5
|
-
class TestNodeEdit < Minitest::Test
|
|
6
|
-
def setup
|
|
7
|
-
xp = LibXML::XML::Parser.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 = LibXML::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 = LibXML::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 = LibXML::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 = LibXML::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 = LibXML::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 = LibXML::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
|
-
def test_remove_node_gc
|
|
70
|
-
xp = LibXML::XML::Parser.string('<test><num>one</num><num>two</num><num>three</num></test>')
|
|
71
|
-
doc = xp.parse
|
|
72
|
-
doc.root.child.remove!
|
|
73
|
-
GC.start
|
|
74
|
-
refute_nil(doc)
|
|
75
|
-
end
|
|
76
|
-
|
|
77
|
-
def test_remove_node_iteration
|
|
78
|
-
nodes = Array.new
|
|
79
|
-
@doc.root.each_element do |node|
|
|
80
|
-
if node.name == 'num'
|
|
81
|
-
nodes << node
|
|
82
|
-
node.remove!
|
|
83
|
-
end
|
|
84
|
-
end
|
|
85
|
-
assert_equal(3, nodes.length)
|
|
86
|
-
end
|
|
87
|
-
|
|
88
|
-
def test_reuse_removed_node
|
|
89
|
-
# Remove the node
|
|
90
|
-
node = @doc.root.first.remove!
|
|
91
|
-
refute_nil(node)
|
|
92
|
-
|
|
93
|
-
# Add it to the end of the document
|
|
94
|
-
@doc.root.last.next = node
|
|
95
|
-
|
|
96
|
-
assert_equal('<test><num>two</num><num>three</num><num>one</num></test>',
|
|
97
|
-
@doc.root.to_s.gsub(/\n\s*/,''))
|
|
98
|
-
end
|
|
99
|
-
|
|
100
|
-
def test_append_existing_node
|
|
101
|
-
doc = LibXML::XML::Parser.string('<top>a<bottom>b<one>first</one><two>second</two>c</bottom>d</top>').parse
|
|
102
|
-
node1 = doc.find_first('//two')
|
|
103
|
-
|
|
104
|
-
doc.root << node1
|
|
105
|
-
assert_equal('<top>a<bottom>b<one>first</one>c</bottom>d<two>second</two></top>',
|
|
106
|
-
doc.root.to_s)
|
|
107
|
-
end
|
|
108
|
-
|
|
109
|
-
def test_wrong_doc
|
|
110
|
-
doc1 = LibXML::XML::Parser.string('<nums><one></one></nums>').parse
|
|
111
|
-
doc2 = LibXML::XML::Parser.string('<nums><two></two></nums>').parse
|
|
112
|
-
|
|
113
|
-
node = doc1.root.child
|
|
114
|
-
|
|
115
|
-
error = assert_raises(LibXML::XML::Error) do
|
|
116
|
-
doc2.root << node
|
|
117
|
-
end
|
|
118
|
-
|
|
119
|
-
GC.start
|
|
120
|
-
assert_equal(' Nodes belong to different documents. You must first import the node by calling LibXML::XML::Document.import.',
|
|
121
|
-
error.to_s)
|
|
122
|
-
end
|
|
123
|
-
|
|
124
|
-
# This test is to verify that an earlier reported bug has been fixed
|
|
125
|
-
def test_merge
|
|
126
|
-
documents = []
|
|
127
|
-
|
|
128
|
-
# Read in 500 documents
|
|
129
|
-
500.times do
|
|
130
|
-
documents << LibXML::XML::Parser.string(File.read(File.join(File.dirname(__FILE__), 'model', 'merge_bug_data.xml'))).parse
|
|
131
|
-
end
|
|
132
|
-
|
|
133
|
-
master_doc = documents.shift
|
|
134
|
-
|
|
135
|
-
documents.each do |child_doc|
|
|
136
|
-
master_body = master_doc.find("//body").first
|
|
137
|
-
child_body = child_doc.find("//body").first
|
|
138
|
-
|
|
139
|
-
child_element = child_body.detect do |node|
|
|
140
|
-
node.element?
|
|
141
|
-
end
|
|
142
|
-
|
|
143
|
-
master_body << child_element.copy(true)
|
|
144
|
-
end
|
|
145
|
-
end
|
|
146
|
-
|
|
147
|
-
def test_append_chain
|
|
148
|
-
node = LibXML::XML::Node.new('foo') << LibXML::XML::Node.new('bar') << "bars contents"
|
|
149
|
-
assert_equal('<foo><bar/>bars contents</foo>',
|
|
150
|
-
node.to_s)
|
|
151
|
-
end
|
|
152
|
-
|
|
153
|
-
def test_set_base
|
|
154
|
-
@doc.root.base_uri = 'http://www.rubynet.org/'
|
|
155
|
-
assert_equal("<test xml:base=\"http://www.rubynet.org/\">\n <num>one</num>\n <num>two</num>\n <num>three</num>\n</test>",
|
|
156
|
-
@doc.root.to_s)
|
|
157
|
-
end
|
|
158
|
-
|
|
1
|
+
# encoding: UTF-8
|
|
2
|
+
|
|
3
|
+
require_relative './test_helper'
|
|
4
|
+
|
|
5
|
+
class TestNodeEdit < Minitest::Test
|
|
6
|
+
def setup
|
|
7
|
+
xp = LibXML::XML::Parser.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 = LibXML::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 = LibXML::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 = LibXML::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 = LibXML::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 = LibXML::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 = LibXML::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
|
+
def test_remove_node_gc
|
|
70
|
+
xp = LibXML::XML::Parser.string('<test><num>one</num><num>two</num><num>three</num></test>')
|
|
71
|
+
doc = xp.parse
|
|
72
|
+
doc.root.child.remove!
|
|
73
|
+
GC.start
|
|
74
|
+
refute_nil(doc)
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
def test_remove_node_iteration
|
|
78
|
+
nodes = Array.new
|
|
79
|
+
@doc.root.each_element do |node|
|
|
80
|
+
if node.name == 'num'
|
|
81
|
+
nodes << node
|
|
82
|
+
node.remove!
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
assert_equal(3, nodes.length)
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
def test_reuse_removed_node
|
|
89
|
+
# Remove the node
|
|
90
|
+
node = @doc.root.first.remove!
|
|
91
|
+
refute_nil(node)
|
|
92
|
+
|
|
93
|
+
# Add it to the end of the document
|
|
94
|
+
@doc.root.last.next = node
|
|
95
|
+
|
|
96
|
+
assert_equal('<test><num>two</num><num>three</num><num>one</num></test>',
|
|
97
|
+
@doc.root.to_s.gsub(/\n\s*/,''))
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
def test_append_existing_node
|
|
101
|
+
doc = LibXML::XML::Parser.string('<top>a<bottom>b<one>first</one><two>second</two>c</bottom>d</top>').parse
|
|
102
|
+
node1 = doc.find_first('//two')
|
|
103
|
+
|
|
104
|
+
doc.root << node1
|
|
105
|
+
assert_equal('<top>a<bottom>b<one>first</one>c</bottom>d<two>second</two></top>',
|
|
106
|
+
doc.root.to_s)
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
def test_wrong_doc
|
|
110
|
+
doc1 = LibXML::XML::Parser.string('<nums><one></one></nums>').parse
|
|
111
|
+
doc2 = LibXML::XML::Parser.string('<nums><two></two></nums>').parse
|
|
112
|
+
|
|
113
|
+
node = doc1.root.child
|
|
114
|
+
|
|
115
|
+
error = assert_raises(LibXML::XML::Error) do
|
|
116
|
+
doc2.root << node
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
GC.start
|
|
120
|
+
assert_equal(' Nodes belong to different documents. You must first import the node by calling LibXML::XML::Document.import.',
|
|
121
|
+
error.to_s)
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
# This test is to verify that an earlier reported bug has been fixed
|
|
125
|
+
def test_merge
|
|
126
|
+
documents = []
|
|
127
|
+
|
|
128
|
+
# Read in 500 documents
|
|
129
|
+
500.times do
|
|
130
|
+
documents << LibXML::XML::Parser.string(File.read(File.join(File.dirname(__FILE__), 'model', 'merge_bug_data.xml'))).parse
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
master_doc = documents.shift
|
|
134
|
+
|
|
135
|
+
documents.each do |child_doc|
|
|
136
|
+
master_body = master_doc.find("//body").first
|
|
137
|
+
child_body = child_doc.find("//body").first
|
|
138
|
+
|
|
139
|
+
child_element = child_body.detect do |node|
|
|
140
|
+
node.element?
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
master_body << child_element.copy(true)
|
|
144
|
+
end
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
def test_append_chain
|
|
148
|
+
node = LibXML::XML::Node.new('foo') << LibXML::XML::Node.new('bar') << "bars contents"
|
|
149
|
+
assert_equal('<foo><bar/>bars contents</foo>',
|
|
150
|
+
node.to_s)
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
def test_set_base
|
|
154
|
+
@doc.root.base_uri = 'http://www.rubynet.org/'
|
|
155
|
+
assert_equal("<test xml:base=\"http://www.rubynet.org/\">\n <num>one</num>\n <num>two</num>\n <num>three</num>\n</test>",
|
|
156
|
+
@doc.root.to_s)
|
|
157
|
+
end
|
|
158
|
+
|
|
159
|
+
def test_detached_subtree_keeps_root_alive
|
|
160
|
+
GC.stress = true
|
|
161
|
+
node = create_detached_subtree_leaf
|
|
162
|
+
assert_equal("leaf", node.name)
|
|
163
|
+
ensure
|
|
164
|
+
GC.stress = false
|
|
165
|
+
end
|
|
166
|
+
|
|
167
|
+
private
|
|
168
|
+
|
|
169
|
+
def create_detached_subtree_leaf
|
|
170
|
+
root = LibXML::XML::Node.new("root")
|
|
171
|
+
mid = LibXML::XML::Node.new("mid")
|
|
172
|
+
root << mid
|
|
173
|
+
mid << LibXML::XML::Node.new("leaf")
|
|
174
|
+
root.children.first.children.first
|
|
175
|
+
end
|
|
176
|
+
end
|
data/test/test_node_pi.rb
CHANGED
|
@@ -1,37 +1,37 @@
|
|
|
1
|
-
# encoding: UTF-8
|
|
2
|
-
|
|
3
|
-
require_relative './test_helper'
|
|
4
|
-
|
|
5
|
-
class NodePiTest < Minitest::Test
|
|
6
|
-
def setup
|
|
7
|
-
xp = LibXML::XML::Parser.string('<root></root>')
|
|
8
|
-
@doc = xp.parse
|
|
9
|
-
assert_instance_of(LibXML::XML::Document, @doc)
|
|
10
|
-
@root = @doc.root
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
def test_libxml_node_add_pi_01
|
|
14
|
-
@root << LibXML::XML::Node.new_pi('mypi')
|
|
15
|
-
assert_equal '<root><?mypi?></root>',
|
|
16
|
-
@root.to_s.gsub(/\n\s*/,'')
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
def test_libxml_node_add_pi_02
|
|
20
|
-
@root << LibXML::XML::Node.new_pi('mypi')
|
|
21
|
-
assert_equal 'pi',
|
|
22
|
-
@root.child.node_type_name
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
def test_libxml_node_add_pi_03
|
|
26
|
-
@root << el = LibXML::XML::Node.new_pi('mypi')
|
|
27
|
-
el << "_this_is_added"
|
|
28
|
-
assert_equal '<root><?mypi _this_is_added?></root>',
|
|
29
|
-
@root.to_s.gsub(/\n\s*/,'')
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
def test_libxml_node_add_pi_04
|
|
33
|
-
@root << LibXML::XML::Node.new_pi('mypi','mycontent')
|
|
34
|
-
assert_equal '<root><?mypi mycontent?></root>',
|
|
35
|
-
@root.to_s.gsub(/\n\s*/,'')
|
|
36
|
-
end
|
|
37
|
-
end
|
|
1
|
+
# encoding: UTF-8
|
|
2
|
+
|
|
3
|
+
require_relative './test_helper'
|
|
4
|
+
|
|
5
|
+
class NodePiTest < Minitest::Test
|
|
6
|
+
def setup
|
|
7
|
+
xp = LibXML::XML::Parser.string('<root></root>')
|
|
8
|
+
@doc = xp.parse
|
|
9
|
+
assert_instance_of(LibXML::XML::Document, @doc)
|
|
10
|
+
@root = @doc.root
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def test_libxml_node_add_pi_01
|
|
14
|
+
@root << LibXML::XML::Node.new_pi('mypi')
|
|
15
|
+
assert_equal '<root><?mypi?></root>',
|
|
16
|
+
@root.to_s.gsub(/\n\s*/,'')
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def test_libxml_node_add_pi_02
|
|
20
|
+
@root << LibXML::XML::Node.new_pi('mypi')
|
|
21
|
+
assert_equal 'pi',
|
|
22
|
+
@root.child.node_type_name
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def test_libxml_node_add_pi_03
|
|
26
|
+
@root << el = LibXML::XML::Node.new_pi('mypi')
|
|
27
|
+
el << "_this_is_added"
|
|
28
|
+
assert_equal '<root><?mypi _this_is_added?></root>',
|
|
29
|
+
@root.to_s.gsub(/\n\s*/,'')
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def test_libxml_node_add_pi_04
|
|
33
|
+
@root << LibXML::XML::Node.new_pi('mypi','mycontent')
|
|
34
|
+
assert_equal '<root><?mypi mycontent?></root>',
|
|
35
|
+
@root.to_s.gsub(/\n\s*/,'')
|
|
36
|
+
end
|
|
37
|
+
end
|
data/test/test_node_text.rb
CHANGED
|
@@ -1,69 +1,69 @@
|
|
|
1
|
-
# encoding: UTF-8
|
|
2
|
-
|
|
3
|
-
require_relative './test_helper'
|
|
4
|
-
|
|
5
|
-
class TestTextNode < Minitest::Test
|
|
6
|
-
def test_content
|
|
7
|
-
node = LibXML::XML::Node.new_text('testdata')
|
|
8
|
-
assert_instance_of(LibXML::XML::Node, node)
|
|
9
|
-
assert_equal('testdata', node.content)
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
def test_invalid_content
|
|
13
|
-
error = assert_raises(TypeError) do
|
|
14
|
-
LibXML::XML::Node.new_text(nil)
|
|
15
|
-
end
|
|
16
|
-
assert_equal('wrong argument type nil (expected String)', error.to_s)
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
# We use the same facility that libXSLT does here to disable output escaping.
|
|
20
|
-
# This lets you specify that the node's content should be rendered unaltered
|
|
21
|
-
# whenever it is being output. This is useful for things like <script> and
|
|
22
|
-
# <style> nodes in HTML documents if you don't want to be forced to wrap them
|
|
23
|
-
# in CDATA nodes. Or if you are sanitizing existing HTML documents and want
|
|
24
|
-
# to preserve the content of any of the text nodes.
|
|
25
|
-
#
|
|
26
|
-
def test_output_escaping
|
|
27
|
-
textnoenc = 'if (a < b || c > d) return "e";'
|
|
28
|
-
text = "if (a < b || c > d) return \"e\";"
|
|
29
|
-
|
|
30
|
-
node = LibXML::XML::Node.new_text(textnoenc)
|
|
31
|
-
assert node.output_escaping?
|
|
32
|
-
assert_equal text, node.to_s
|
|
33
|
-
|
|
34
|
-
node.output_escaping = false
|
|
35
|
-
assert_equal textnoenc, node.to_s
|
|
36
|
-
|
|
37
|
-
node.output_escaping = true
|
|
38
|
-
assert_equal text, node.to_s
|
|
39
|
-
|
|
40
|
-
node.output_escaping = nil
|
|
41
|
-
assert_equal textnoenc, node.to_s
|
|
42
|
-
|
|
43
|
-
node.output_escaping = true
|
|
44
|
-
assert_equal text, node.to_s
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
# Just a sanity check for output escaping.
|
|
48
|
-
def test_output_escaping_sanity
|
|
49
|
-
node = LibXML::XML::Node.new_text('testdata')
|
|
50
|
-
assert_equal 'text', node.name
|
|
51
|
-
assert node.output_escaping?
|
|
52
|
-
|
|
53
|
-
node.output_escaping = false
|
|
54
|
-
assert_equal 'textnoenc', node.name
|
|
55
|
-
assert ! node.output_escaping?
|
|
56
|
-
|
|
57
|
-
node.output_escaping = true
|
|
58
|
-
assert_equal 'text', node.name
|
|
59
|
-
assert node.output_escaping?
|
|
60
|
-
|
|
61
|
-
node.output_escaping = nil
|
|
62
|
-
assert_equal 'textnoenc', node.name
|
|
63
|
-
assert ! node.output_escaping?
|
|
64
|
-
|
|
65
|
-
node.output_escaping = true
|
|
66
|
-
assert_equal 'text', node.name
|
|
67
|
-
assert node.output_escaping?
|
|
68
|
-
end
|
|
69
|
-
end
|
|
1
|
+
# encoding: UTF-8
|
|
2
|
+
|
|
3
|
+
require_relative './test_helper'
|
|
4
|
+
|
|
5
|
+
class TestTextNode < Minitest::Test
|
|
6
|
+
def test_content
|
|
7
|
+
node = LibXML::XML::Node.new_text('testdata')
|
|
8
|
+
assert_instance_of(LibXML::XML::Node, node)
|
|
9
|
+
assert_equal('testdata', node.content)
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def test_invalid_content
|
|
13
|
+
error = assert_raises(TypeError) do
|
|
14
|
+
LibXML::XML::Node.new_text(nil)
|
|
15
|
+
end
|
|
16
|
+
assert_equal('wrong argument type nil (expected String)', error.to_s)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
# We use the same facility that libXSLT does here to disable output escaping.
|
|
20
|
+
# This lets you specify that the node's content should be rendered unaltered
|
|
21
|
+
# whenever it is being output. This is useful for things like <script> and
|
|
22
|
+
# <style> nodes in HTML documents if you don't want to be forced to wrap them
|
|
23
|
+
# in CDATA nodes. Or if you are sanitizing existing HTML documents and want
|
|
24
|
+
# to preserve the content of any of the text nodes.
|
|
25
|
+
#
|
|
26
|
+
def test_output_escaping
|
|
27
|
+
textnoenc = 'if (a < b || c > d) return "e";'
|
|
28
|
+
text = "if (a < b || c > d) return \"e\";"
|
|
29
|
+
|
|
30
|
+
node = LibXML::XML::Node.new_text(textnoenc)
|
|
31
|
+
assert node.output_escaping?
|
|
32
|
+
assert_equal text, node.to_s
|
|
33
|
+
|
|
34
|
+
node.output_escaping = false
|
|
35
|
+
assert_equal textnoenc, node.to_s
|
|
36
|
+
|
|
37
|
+
node.output_escaping = true
|
|
38
|
+
assert_equal text, node.to_s
|
|
39
|
+
|
|
40
|
+
node.output_escaping = nil
|
|
41
|
+
assert_equal textnoenc, node.to_s
|
|
42
|
+
|
|
43
|
+
node.output_escaping = true
|
|
44
|
+
assert_equal text, node.to_s
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
# Just a sanity check for output escaping.
|
|
48
|
+
def test_output_escaping_sanity
|
|
49
|
+
node = LibXML::XML::Node.new_text('testdata')
|
|
50
|
+
assert_equal 'text', node.name
|
|
51
|
+
assert node.output_escaping?
|
|
52
|
+
|
|
53
|
+
node.output_escaping = false
|
|
54
|
+
assert_equal 'textnoenc', node.name
|
|
55
|
+
assert ! node.output_escaping?
|
|
56
|
+
|
|
57
|
+
node.output_escaping = true
|
|
58
|
+
assert_equal 'text', node.name
|
|
59
|
+
assert node.output_escaping?
|
|
60
|
+
|
|
61
|
+
node.output_escaping = nil
|
|
62
|
+
assert_equal 'textnoenc', node.name
|
|
63
|
+
assert ! node.output_escaping?
|
|
64
|
+
|
|
65
|
+
node.output_escaping = true
|
|
66
|
+
assert_equal 'text', node.name
|
|
67
|
+
assert node.output_escaping?
|
|
68
|
+
end
|
|
69
|
+
end
|