libxml-ruby 3.2.2-x64-mingw-ucrt
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/HISTORY +848 -0
- data/LICENSE +21 -0
- data/MANIFEST +166 -0
- data/README.rdoc +217 -0
- data/Rakefile +99 -0
- data/ext/libxml/extconf.rb +61 -0
- data/ext/libxml/libxml.c +80 -0
- data/ext/libxml/libxml_ruby.def +35 -0
- data/ext/libxml/ruby_libxml.h +67 -0
- data/ext/libxml/ruby_xml.c +933 -0
- data/ext/libxml/ruby_xml.h +10 -0
- data/ext/libxml/ruby_xml_attr.c +333 -0
- data/ext/libxml/ruby_xml_attr.h +12 -0
- data/ext/libxml/ruby_xml_attr_decl.c +153 -0
- data/ext/libxml/ruby_xml_attr_decl.h +11 -0
- data/ext/libxml/ruby_xml_attributes.c +275 -0
- data/ext/libxml/ruby_xml_attributes.h +15 -0
- data/ext/libxml/ruby_xml_cbg.c +85 -0
- data/ext/libxml/ruby_xml_document.c +1123 -0
- data/ext/libxml/ruby_xml_document.h +11 -0
- data/ext/libxml/ruby_xml_dtd.c +248 -0
- data/ext/libxml/ruby_xml_dtd.h +9 -0
- data/ext/libxml/ruby_xml_encoding.c +250 -0
- data/ext/libxml/ruby_xml_encoding.h +16 -0
- data/ext/libxml/ruby_xml_error.c +996 -0
- data/ext/libxml/ruby_xml_error.h +12 -0
- data/ext/libxml/ruby_xml_html_parser.c +89 -0
- data/ext/libxml/ruby_xml_html_parser.h +10 -0
- data/ext/libxml/ruby_xml_html_parser_context.c +337 -0
- data/ext/libxml/ruby_xml_html_parser_context.h +10 -0
- data/ext/libxml/ruby_xml_html_parser_options.c +46 -0
- data/ext/libxml/ruby_xml_html_parser_options.h +10 -0
- data/ext/libxml/ruby_xml_input_cbg.c +191 -0
- data/ext/libxml/ruby_xml_input_cbg.h +20 -0
- data/ext/libxml/ruby_xml_io.c +47 -0
- data/ext/libxml/ruby_xml_io.h +10 -0
- data/ext/libxml/ruby_xml_namespace.c +153 -0
- data/ext/libxml/ruby_xml_namespace.h +10 -0
- data/ext/libxml/ruby_xml_namespaces.c +293 -0
- data/ext/libxml/ruby_xml_namespaces.h +9 -0
- data/ext/libxml/ruby_xml_node.c +1402 -0
- data/ext/libxml/ruby_xml_node.h +13 -0
- data/ext/libxml/ruby_xml_parser.c +91 -0
- data/ext/libxml/ruby_xml_parser.h +12 -0
- data/ext/libxml/ruby_xml_parser_context.c +999 -0
- data/ext/libxml/ruby_xml_parser_context.h +10 -0
- data/ext/libxml/ruby_xml_parser_options.c +66 -0
- data/ext/libxml/ruby_xml_parser_options.h +12 -0
- data/ext/libxml/ruby_xml_reader.c +1239 -0
- data/ext/libxml/ruby_xml_reader.h +17 -0
- data/ext/libxml/ruby_xml_relaxng.c +110 -0
- data/ext/libxml/ruby_xml_relaxng.h +10 -0
- data/ext/libxml/ruby_xml_sax2_handler.c +326 -0
- data/ext/libxml/ruby_xml_sax2_handler.h +10 -0
- data/ext/libxml/ruby_xml_sax_parser.c +116 -0
- data/ext/libxml/ruby_xml_sax_parser.h +10 -0
- data/ext/libxml/ruby_xml_schema.c +278 -0
- data/ext/libxml/ruby_xml_schema.h +809 -0
- data/ext/libxml/ruby_xml_schema_attribute.c +109 -0
- data/ext/libxml/ruby_xml_schema_attribute.h +15 -0
- data/ext/libxml/ruby_xml_schema_element.c +95 -0
- data/ext/libxml/ruby_xml_schema_element.h +14 -0
- data/ext/libxml/ruby_xml_schema_facet.c +52 -0
- data/ext/libxml/ruby_xml_schema_facet.h +13 -0
- data/ext/libxml/ruby_xml_schema_type.c +232 -0
- data/ext/libxml/ruby_xml_schema_type.h +9 -0
- data/ext/libxml/ruby_xml_version.h +9 -0
- data/ext/libxml/ruby_xml_writer.c +1133 -0
- data/ext/libxml/ruby_xml_writer.h +10 -0
- data/ext/libxml/ruby_xml_xinclude.c +16 -0
- data/ext/libxml/ruby_xml_xinclude.h +11 -0
- data/ext/libxml/ruby_xml_xpath.c +194 -0
- data/ext/libxml/ruby_xml_xpath.h +13 -0
- data/ext/libxml/ruby_xml_xpath_context.c +360 -0
- data/ext/libxml/ruby_xml_xpath_context.h +9 -0
- data/ext/libxml/ruby_xml_xpath_expression.c +81 -0
- data/ext/libxml/ruby_xml_xpath_expression.h +10 -0
- data/ext/libxml/ruby_xml_xpath_object.c +338 -0
- data/ext/libxml/ruby_xml_xpath_object.h +17 -0
- data/ext/libxml/ruby_xml_xpointer.c +99 -0
- data/ext/libxml/ruby_xml_xpointer.h +11 -0
- data/ext/vc/libxml_ruby.sln +28 -0
- data/lib/3.1/libxml_ruby.so +0 -0
- data/lib/libxml/attr.rb +123 -0
- data/lib/libxml/attr_decl.rb +80 -0
- data/lib/libxml/attributes.rb +14 -0
- data/lib/libxml/document.rb +194 -0
- data/lib/libxml/error.rb +95 -0
- data/lib/libxml/hpricot.rb +78 -0
- data/lib/libxml/html_parser.rb +96 -0
- data/lib/libxml/namespace.rb +62 -0
- data/lib/libxml/namespaces.rb +38 -0
- data/lib/libxml/node.rb +323 -0
- data/lib/libxml/parser.rb +101 -0
- data/lib/libxml/sax_callbacks.rb +180 -0
- data/lib/libxml/sax_parser.rb +41 -0
- data/lib/libxml/schema/attribute.rb +19 -0
- data/lib/libxml/schema/element.rb +19 -0
- data/lib/libxml/schema/type.rb +21 -0
- data/lib/libxml/schema.rb +48 -0
- data/lib/libxml/tree.rb +29 -0
- data/lib/libxml-ruby.rb +30 -0
- data/lib/libxml.rb +5 -0
- data/lib/xml/libxml.rb +10 -0
- data/lib/xml.rb +14 -0
- data/libxml-ruby.gemspec +48 -0
- data/script/benchmark/depixelate +634 -0
- data/script/benchmark/hamlet.xml +9055 -0
- data/script/benchmark/parsecount +170 -0
- data/script/benchmark/sock_entries.xml +507 -0
- data/script/benchmark/throughput +41 -0
- data/script/test +6 -0
- data/setup.rb +1584 -0
- data/test/c14n/given/doc.dtd +1 -0
- data/test/c14n/given/example-1.xml +14 -0
- data/test/c14n/given/example-2.xml +11 -0
- data/test/c14n/given/example-3.xml +18 -0
- data/test/c14n/given/example-4.xml +9 -0
- data/test/c14n/given/example-5.xml +12 -0
- data/test/c14n/given/example-6.xml +2 -0
- data/test/c14n/given/example-7.xml +11 -0
- data/test/c14n/given/example-8.xml +11 -0
- data/test/c14n/given/example-8.xpath +10 -0
- data/test/c14n/given/world.txt +1 -0
- data/test/c14n/result/1-1-without-comments/example-1 +4 -0
- data/test/c14n/result/1-1-without-comments/example-2 +11 -0
- data/test/c14n/result/1-1-without-comments/example-3 +14 -0
- data/test/c14n/result/1-1-without-comments/example-4 +9 -0
- data/test/c14n/result/1-1-without-comments/example-5 +3 -0
- data/test/c14n/result/1-1-without-comments/example-6 +1 -0
- data/test/c14n/result/1-1-without-comments/example-7 +1 -0
- data/test/c14n/result/1-1-without-comments/example-8 +1 -0
- data/test/c14n/result/with-comments/example-1 +6 -0
- data/test/c14n/result/with-comments/example-2 +11 -0
- data/test/c14n/result/with-comments/example-3 +14 -0
- data/test/c14n/result/with-comments/example-4 +9 -0
- data/test/c14n/result/with-comments/example-5 +4 -0
- data/test/c14n/result/with-comments/example-6 +1 -0
- data/test/c14n/result/with-comments/example-7 +1 -0
- data/test/c14n/result/without-comments/example-1 +4 -0
- data/test/c14n/result/without-comments/example-2 +11 -0
- data/test/c14n/result/without-comments/example-3 +14 -0
- data/test/c14n/result/without-comments/example-4 +9 -0
- data/test/c14n/result/without-comments/example-5 +3 -0
- data/test/c14n/result/without-comments/example-6 +1 -0
- data/test/c14n/result/without-comments/example-7 +1 -0
- data/test/model/atom.xml +13 -0
- data/test/model/bands.iso-8859-1.xml +5 -0
- data/test/model/bands.utf-8.xml +5 -0
- data/test/model/bands.xml +5 -0
- data/test/model/books.xml +154 -0
- data/test/model/cwm_1_0.xml +11336 -0
- data/test/model/merge_bug_data.xml +58 -0
- data/test/model/ruby-lang.html +238 -0
- data/test/model/rubynet.xml +79 -0
- data/test/model/rubynet_project +1 -0
- data/test/model/shiporder.rnc +28 -0
- data/test/model/shiporder.rng +86 -0
- data/test/model/shiporder.xml +23 -0
- data/test/model/shiporder.xsd +40 -0
- data/test/model/soap.xml +27 -0
- data/test/model/xinclude.xml +5 -0
- data/test/test_attr.rb +181 -0
- data/test/test_attr_decl.rb +132 -0
- data/test/test_attributes.rb +136 -0
- data/test/test_canonicalize.rb +120 -0
- data/test/test_deprecated_require.rb +12 -0
- data/test/test_document.rb +132 -0
- data/test/test_document_write.rb +146 -0
- data/test/test_dtd.rb +129 -0
- data/test/test_encoding.rb +129 -0
- data/test/test_encoding_sax.rb +115 -0
- data/test/test_error.rb +178 -0
- data/test/test_helper.rb +9 -0
- data/test/test_html_parser.rb +162 -0
- data/test/test_html_parser_context.rb +23 -0
- data/test/test_namespace.rb +60 -0
- data/test/test_namespaces.rb +200 -0
- data/test/test_node.rb +237 -0
- data/test/test_node_cdata.rb +50 -0
- data/test/test_node_comment.rb +32 -0
- data/test/test_node_copy.rb +40 -0
- data/test/test_node_edit.rb +158 -0
- data/test/test_node_pi.rb +37 -0
- data/test/test_node_text.rb +69 -0
- data/test/test_node_write.rb +97 -0
- data/test/test_node_xlink.rb +28 -0
- data/test/test_parser.rb +324 -0
- data/test/test_parser_context.rb +198 -0
- data/test/test_properties.rb +38 -0
- data/test/test_reader.rb +364 -0
- data/test/test_relaxng.rb +53 -0
- data/test/test_sax_parser.rb +326 -0
- data/test/test_schema.rb +168 -0
- data/test/test_suite.rb +48 -0
- data/test/test_traversal.rb +152 -0
- data/test/test_writer.rb +468 -0
- data/test/test_xinclude.rb +20 -0
- data/test/test_xml.rb +263 -0
- data/test/test_xpath.rb +244 -0
- data/test/test_xpath_context.rb +88 -0
- data/test/test_xpath_expression.rb +37 -0
- data/test/test_xpointer.rb +72 -0
- metadata +325 -0
data/test/test_attr.rb
ADDED
@@ -0,0 +1,181 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require_relative './test_helper'
|
4
|
+
|
5
|
+
class AttrNodeTest < Minitest::Test
|
6
|
+
def setup
|
7
|
+
xp = LibXML::XML::Parser.string(<<-EOS)
|
8
|
+
<CityModel
|
9
|
+
xmlns="http://www.opengis.net/examples"
|
10
|
+
xmlns:city="http://www.opengis.net/examples"
|
11
|
+
xmlns:gml="http://www.opengis.net/gml"
|
12
|
+
xmlns:xlink="http://www.w3.org/1999/xlink"
|
13
|
+
xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance"
|
14
|
+
xsi:schemaLocation="http://www.opengis.net/examples city.xsd">
|
15
|
+
<type>City</type>
|
16
|
+
<cityMember name="Cambridge"
|
17
|
+
xlink:type="simple"
|
18
|
+
xlink:title="Trinity Lane"
|
19
|
+
xlink:href="http://www.foo.net/cgi-bin/wfs?FeatureID=C10239"
|
20
|
+
gml:remoteSchema="city.xsd#xpointer(//complexType[@name='RoadType'])"/>
|
21
|
+
</CityModel>
|
22
|
+
EOS
|
23
|
+
|
24
|
+
@doc = xp.parse
|
25
|
+
end
|
26
|
+
|
27
|
+
def teardown
|
28
|
+
@doc = nil
|
29
|
+
end
|
30
|
+
|
31
|
+
def city_member
|
32
|
+
@doc.find('/city:CityModel/city:cityMember').first
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_doc
|
36
|
+
refute_nil(@doc)
|
37
|
+
assert_equal(LibXML::XML::Encoding::NONE, @doc.encoding)
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_types
|
41
|
+
attribute = city_member.attributes.get_attribute('name')
|
42
|
+
assert_instance_of(LibXML::XML::Attr, attribute)
|
43
|
+
assert_equal('attribute', attribute.node_type_name)
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_name
|
47
|
+
attribute = city_member.attributes.get_attribute('name')
|
48
|
+
assert_equal('name', attribute.name)
|
49
|
+
assert_equal(Encoding::UTF_8, attribute.name.encoding)
|
50
|
+
|
51
|
+
attribute = city_member.attributes.get_attribute('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
|
+
|
56
|
+
attribute = city_member.attributes.get_attribute_ns('http://www.w3.org/1999/xlink', 'href')
|
57
|
+
assert_equal('href', attribute.name)
|
58
|
+
assert_equal('xlink', attribute.ns.prefix)
|
59
|
+
assert_equal('http://www.w3.org/1999/xlink', attribute.ns.href)
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_value
|
63
|
+
attribute = city_member.attributes.get_attribute('name')
|
64
|
+
assert_equal('Cambridge', attribute.value)
|
65
|
+
assert_equal(Encoding::UTF_8, attribute.value.encoding)
|
66
|
+
|
67
|
+
attribute = city_member.attributes.get_attribute('href')
|
68
|
+
assert_equal('http://www.foo.net/cgi-bin/wfs?FeatureID=C10239', attribute.value)
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_set_value
|
72
|
+
attribute = city_member.attributes.get_attribute('name')
|
73
|
+
attribute.value = 'London'
|
74
|
+
assert_equal('London', attribute.value)
|
75
|
+
assert_equal(Encoding::UTF_8, attribute.value.encoding)
|
76
|
+
|
77
|
+
attribute = city_member.attributes.get_attribute('href')
|
78
|
+
attribute.value = 'http://i.have.changed'
|
79
|
+
assert_equal('http://i.have.changed', attribute.value)
|
80
|
+
assert_equal(Encoding::UTF_8, attribute.value.encoding)
|
81
|
+
end
|
82
|
+
|
83
|
+
def test_set_nil
|
84
|
+
attribute = city_member.attributes.get_attribute('name')
|
85
|
+
assert_raises(TypeError) do
|
86
|
+
attribute.value = nil
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
def test_create
|
91
|
+
attributes = city_member.attributes
|
92
|
+
assert_equal(5, attributes.length)
|
93
|
+
|
94
|
+
attr = LibXML::XML::Attr.new(city_member, 'size', '50,000')
|
95
|
+
assert_instance_of(LibXML::XML::Attr, attr)
|
96
|
+
|
97
|
+
attributes = city_member.attributes
|
98
|
+
assert_equal(6, attributes.length)
|
99
|
+
|
100
|
+
assert_equal(attributes['size'], '50,000')
|
101
|
+
end
|
102
|
+
|
103
|
+
def test_create_on_node
|
104
|
+
attributes = city_member.attributes
|
105
|
+
assert_equal(5, attributes.length)
|
106
|
+
|
107
|
+
attributes['country'] = 'England'
|
108
|
+
|
109
|
+
attributes = city_member.attributes
|
110
|
+
assert_equal(6, attributes.length)
|
111
|
+
|
112
|
+
assert_equal(attributes['country'], 'England')
|
113
|
+
end
|
114
|
+
|
115
|
+
def test_create_ns
|
116
|
+
assert_equal(5, city_member.attributes.length)
|
117
|
+
|
118
|
+
ns = LibXML::XML::Namespace.new(city_member, 'my_namepace', 'http://www.mynamespace.com')
|
119
|
+
attr = LibXML::XML::Attr.new(city_member, 'rating', 'rocks', ns)
|
120
|
+
assert_instance_of(LibXML::XML::Attr, attr)
|
121
|
+
assert_equal('rating', attr.name)
|
122
|
+
assert_equal('rocks', attr.value)
|
123
|
+
|
124
|
+
attributes = city_member.attributes
|
125
|
+
assert_equal(6, attributes.length)
|
126
|
+
|
127
|
+
assert_equal('rocks', city_member['rating'])
|
128
|
+
end
|
129
|
+
|
130
|
+
def test_remove
|
131
|
+
attributes = city_member.attributes
|
132
|
+
assert_equal(5, attributes.length)
|
133
|
+
|
134
|
+
attribute = attributes.get_attribute('name')
|
135
|
+
refute_nil(attribute.parent)
|
136
|
+
assert(attribute.parent?)
|
137
|
+
|
138
|
+
attribute.remove!
|
139
|
+
assert_equal(4, attributes.length)
|
140
|
+
|
141
|
+
attribute = attributes.get_attribute('name')
|
142
|
+
assert_nil(attribute)
|
143
|
+
end
|
144
|
+
|
145
|
+
def test_first
|
146
|
+
attribute = city_member.attributes.first
|
147
|
+
assert_instance_of(LibXML::XML::Attr, attribute)
|
148
|
+
assert_equal('name', attribute.name)
|
149
|
+
assert_equal('Cambridge', attribute.value)
|
150
|
+
|
151
|
+
attribute = attribute.next
|
152
|
+
assert_instance_of(LibXML::XML::Attr, attribute)
|
153
|
+
assert_equal('type', attribute.name)
|
154
|
+
assert_equal('simple', attribute.value)
|
155
|
+
|
156
|
+
attribute = attribute.next
|
157
|
+
assert_instance_of(LibXML::XML::Attr, attribute)
|
158
|
+
assert_equal('title', attribute.name)
|
159
|
+
assert_equal('Trinity Lane', attribute.value)
|
160
|
+
|
161
|
+
attribute = attribute.next
|
162
|
+
assert_instance_of(LibXML::XML::Attr, attribute)
|
163
|
+
assert_equal('href', attribute.name)
|
164
|
+
assert_equal('http://www.foo.net/cgi-bin/wfs?FeatureID=C10239', attribute.value)
|
165
|
+
|
166
|
+
attribute = attribute.next
|
167
|
+
assert_instance_of(LibXML::XML::Attr, attribute)
|
168
|
+
assert_equal('remoteSchema', attribute.name)
|
169
|
+
assert_equal("city.xsd#xpointer(//complexType[@name='RoadType'])", attribute.value)
|
170
|
+
|
171
|
+
attribute = attribute.next
|
172
|
+
assert_nil(attribute)
|
173
|
+
end
|
174
|
+
|
175
|
+
def test_no_attributes
|
176
|
+
element = @doc.find('/city:CityModel/city:type').first
|
177
|
+
|
178
|
+
refute_nil(element.attributes)
|
179
|
+
assert_equal(0, element.attributes.length)
|
180
|
+
end
|
181
|
+
end
|
@@ -0,0 +1,132 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require_relative './test_helper'
|
4
|
+
|
5
|
+
class AttrDeclTest < Minitest::Test
|
6
|
+
def setup
|
7
|
+
xp = LibXML::XML::Parser.string(<<-EOS)
|
8
|
+
<!DOCTYPE test [
|
9
|
+
<!ELEMENT root (property*)>
|
10
|
+
<!ELEMENT property EMPTY>
|
11
|
+
<!ATTLIST property name NMTOKEN #REQUIRED>
|
12
|
+
<!ATTLIST property access (r | w | rw) "rw">
|
13
|
+
]>
|
14
|
+
<root>
|
15
|
+
<property name="readonly" access="r" />
|
16
|
+
<property name="readwrite" />
|
17
|
+
</root>
|
18
|
+
EOS
|
19
|
+
@doc = xp.parse
|
20
|
+
end
|
21
|
+
|
22
|
+
def teardown
|
23
|
+
@doc = nil
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_attributes
|
27
|
+
# Get a element with an access attribute
|
28
|
+
elem = @doc.find_first('/root/property[@name="readonly"]')
|
29
|
+
assert_equal(2, elem.attributes.length)
|
30
|
+
refute_nil(elem['access'])
|
31
|
+
|
32
|
+
# Get a element node without a access attribute
|
33
|
+
elem = @doc.find_first('/root/property[@name="readwrite"]')
|
34
|
+
assert_equal(1, elem.attributes.length)
|
35
|
+
assert_nil(elem['access'])
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_attr
|
39
|
+
# Get a property node without a access attribute
|
40
|
+
elem = @doc.find_first('/root/property[@name="readonly"]')
|
41
|
+
|
42
|
+
# Get the attr_decl
|
43
|
+
attr = elem.attributes.get_attribute('access')
|
44
|
+
refute_nil(attr)
|
45
|
+
assert_equal(LibXML::XML::Node::ATTRIBUTE_NODE, attr.node_type)
|
46
|
+
assert_equal('attribute', attr.node_type_name)
|
47
|
+
|
48
|
+
# Get its value
|
49
|
+
assert_equal('r', attr.value)
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_attr_decl
|
53
|
+
# Get a property node without a access attribute
|
54
|
+
elem = @doc.find_first('/root/property[@name="readwrite"]')
|
55
|
+
|
56
|
+
# Get the attr_decl
|
57
|
+
attr_decl = elem.attributes.get_attribute('access')
|
58
|
+
refute_nil(attr_decl)
|
59
|
+
assert_equal(LibXML::XML::Node::ATTRIBUTE_DECL, attr_decl.node_type)
|
60
|
+
assert_equal('attribute declaration', attr_decl.node_type_name)
|
61
|
+
|
62
|
+
# Get its value
|
63
|
+
assert_equal('rw', attr_decl.value)
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_type
|
67
|
+
# Get a property node without a access attribute
|
68
|
+
elem = @doc.find_first('/root/property[@name="readwrite"]')
|
69
|
+
attr_decl = elem.attributes.get_attribute('access')
|
70
|
+
|
71
|
+
refute_nil(attr_decl)
|
72
|
+
assert_equal(LibXML::XML::Node::ATTRIBUTE_DECL, attr_decl.node_type)
|
73
|
+
assert_equal('attribute declaration', attr_decl.node_type_name)
|
74
|
+
end
|
75
|
+
|
76
|
+
def test_name
|
77
|
+
elem = @doc.find_first('/root/property[@name="readwrite"]')
|
78
|
+
attr_decl = elem.attributes.get_attribute('access')
|
79
|
+
|
80
|
+
assert_equal('access', attr_decl.name)
|
81
|
+
end
|
82
|
+
|
83
|
+
def test_value
|
84
|
+
elem = @doc.find_first('/root/property[@name="readwrite"]')
|
85
|
+
attr_decl = elem.attributes.get_attribute('access')
|
86
|
+
|
87
|
+
assert_equal('rw', attr_decl.value)
|
88
|
+
end
|
89
|
+
|
90
|
+
def test_to_s
|
91
|
+
elem = @doc.find_first('/root/property[@name="readwrite"]')
|
92
|
+
attr_decl = elem.attributes.get_attribute('access')
|
93
|
+
|
94
|
+
assert_equal('access = rw', attr_decl.to_s)
|
95
|
+
end
|
96
|
+
|
97
|
+
def test_prev
|
98
|
+
elem = @doc.find_first('/root/property[@name="readwrite"]')
|
99
|
+
attr_decl = elem.attributes.get_attribute('access')
|
100
|
+
|
101
|
+
first_decl = attr_decl.prev
|
102
|
+
assert_equal(LibXML::XML::Node::ATTRIBUTE_DECL, first_decl.node_type)
|
103
|
+
assert_equal('name', first_decl.name)
|
104
|
+
assert_nil(first_decl.value)
|
105
|
+
|
106
|
+
elem_decl = first_decl.prev
|
107
|
+
assert_equal(LibXML::XML::Node::ELEMENT_DECL, elem_decl.node_type)
|
108
|
+
end
|
109
|
+
|
110
|
+
def test_next
|
111
|
+
elem = @doc.find_first('/root/property[@name="readwrite"]')
|
112
|
+
attr_decl = elem.attributes.get_attribute('access')
|
113
|
+
|
114
|
+
next_decl = attr_decl.next
|
115
|
+
assert_nil(next_decl)
|
116
|
+
end
|
117
|
+
|
118
|
+
def test_doc
|
119
|
+
elem = @doc.find_first('/root/property[@name="readwrite"]')
|
120
|
+
attr_decl = elem.attributes.get_attribute('access')
|
121
|
+
|
122
|
+
assert_same(@doc, attr_decl.doc)
|
123
|
+
end
|
124
|
+
|
125
|
+
def test_parent
|
126
|
+
elem = @doc.find_first('/root/property[@name="readwrite"]')
|
127
|
+
attr_decl = elem.attributes.get_attribute('access')
|
128
|
+
|
129
|
+
parent = attr_decl.parent
|
130
|
+
assert_instance_of(LibXML::XML::Dtd, parent)
|
131
|
+
end
|
132
|
+
end
|
@@ -0,0 +1,136 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require_relative './test_helper'
|
4
|
+
|
5
|
+
class AttributesTest < Minitest::Test
|
6
|
+
def setup
|
7
|
+
xp = LibXML::XML::Parser.string(<<-EOS)
|
8
|
+
<CityModel name="value"
|
9
|
+
xmlns="http://www.opengis.net/examples"
|
10
|
+
xmlns:city="http://www.opengis.net/examples"
|
11
|
+
xmlns:gml="http://www.opengis.net/gml"
|
12
|
+
xmlns:xlink="http://www.w3.org/1999/xlink"
|
13
|
+
xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance"
|
14
|
+
xsi:schemaLocation="http://www.opengis.net/examples city.xsd">
|
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_attributes
|
35
|
+
attributes = city_member.attributes
|
36
|
+
assert_instance_of(LibXML::XML::Attributes, attributes)
|
37
|
+
assert_equal(5, attributes.length)
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_each
|
41
|
+
attributes = city_member.attributes
|
42
|
+
length = attributes.inject(0) do |result, attr|
|
43
|
+
assert_instance_of(LibXML::XML::Attr, attr)
|
44
|
+
result + 1
|
45
|
+
end
|
46
|
+
assert_equal(5, length)
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_get_attribute
|
50
|
+
attributes = city_member.attributes
|
51
|
+
|
52
|
+
attr = attributes.get_attribute('name')
|
53
|
+
assert_instance_of(LibXML::XML::Attr, attr)
|
54
|
+
|
55
|
+
attr = attributes.get_attribute('does_not_exist')
|
56
|
+
assert_nil(attr)
|
57
|
+
|
58
|
+
attr = attributes.get_attribute('name')
|
59
|
+
assert_instance_of(LibXML::XML::Attr, attr)
|
60
|
+
|
61
|
+
attr = attributes.get_attribute('href')
|
62
|
+
assert_instance_of(LibXML::XML::Attr, attr)
|
63
|
+
assert_instance_of(LibXML::XML::Namespace, attr.ns)
|
64
|
+
assert_equal('xlink', attr.ns.prefix)
|
65
|
+
assert_equal('http://www.w3.org/1999/xlink', attr.ns.href)
|
66
|
+
|
67
|
+
attr = attributes.get_attribute_ns('http://www.w3.org/1999/xlink', 'href')
|
68
|
+
assert_instance_of(LibXML::XML::Attr, attr)
|
69
|
+
|
70
|
+
attr = attributes.get_attribute_ns('http://www.opengis.net/gml', 'remoteSchema')
|
71
|
+
assert_instance_of(LibXML::XML::Attr, attr)
|
72
|
+
|
73
|
+
attr = attributes.get_attribute_ns('http://i.dont.exist', 'nor do i')
|
74
|
+
assert_nil(attr)
|
75
|
+
end
|
76
|
+
|
77
|
+
def test_get_values
|
78
|
+
assert_equal('Cambridge', city_member[:name])
|
79
|
+
assert_equal('http://www.foo.net/cgi-bin/wfs?FeatureID=C10239', city_member[:href])
|
80
|
+
|
81
|
+
attributes = city_member.attributes
|
82
|
+
assert_equal('Cambridge', attributes[:name])
|
83
|
+
assert_equal('http://www.foo.net/cgi-bin/wfs?FeatureID=C10239', attributes[:href])
|
84
|
+
end
|
85
|
+
|
86
|
+
def test_get_values_gc
|
87
|
+
# There used to be a bug caused by accessing an
|
88
|
+
# attribute over and over and over again.
|
89
|
+
20000.times do
|
90
|
+
@doc.root.attributes["key"]
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
def test_set_values
|
95
|
+
city_member[:name] = 'London'
|
96
|
+
assert_equal('London', city_member[:name])
|
97
|
+
|
98
|
+
city_member[:href] = 'foo'
|
99
|
+
assert_equal('foo', city_member[:href])
|
100
|
+
|
101
|
+
attributes = city_member.attributes
|
102
|
+
|
103
|
+
attributes[:name] = 'London'
|
104
|
+
assert_equal('London', attributes[:name])
|
105
|
+
|
106
|
+
attributes[:href] = 'foo'
|
107
|
+
assert_equal('foo', attributes[:href])
|
108
|
+
end
|
109
|
+
|
110
|
+
def test_str_sym()
|
111
|
+
attributes = city_member.attributes
|
112
|
+
assert_equal('Cambridge', attributes[:name])
|
113
|
+
assert_equal('Cambridge', attributes['name'])
|
114
|
+
end
|
115
|
+
|
116
|
+
def test_remove_first
|
117
|
+
attributes = @doc.find_first('/city:CityModel/city:cityMember').attributes
|
118
|
+
assert_equal(5, attributes.length)
|
119
|
+
attr = attributes.first
|
120
|
+
attr.remove!
|
121
|
+
assert_equal(4, attributes.length)
|
122
|
+
end
|
123
|
+
|
124
|
+
def test_remove_all
|
125
|
+
node = @doc.find_first('/city:CityModel/city:cityMember')
|
126
|
+
assert_equal(5, node.attributes.length)
|
127
|
+
|
128
|
+
attrs = Array.new
|
129
|
+
node.attributes.each do |attr|
|
130
|
+
attrs << attr
|
131
|
+
attr.remove!
|
132
|
+
end
|
133
|
+
assert_equal(5, attrs.length)
|
134
|
+
assert_equal(0, node.attributes.length)
|
135
|
+
end
|
136
|
+
end
|
@@ -0,0 +1,120 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require_relative './test_helper'
|
3
|
+
|
4
|
+
class TestCanonicalize < Minitest::Test
|
5
|
+
def path(file)
|
6
|
+
File.join(File.dirname(__FILE__), file)
|
7
|
+
end
|
8
|
+
|
9
|
+
# (www.w3.org) 3.1 PIs, Comments, and Outside of Document Element
|
10
|
+
# http://www.w3.org/TR/xml-c14n#Example-OutsideDoc
|
11
|
+
def test_canonicalize_with_w3c_c14n_3_1
|
12
|
+
given_doc = LibXML::XML::Document.file(self.path('c14n/given/example-1.xml'))
|
13
|
+
|
14
|
+
# With Comments
|
15
|
+
expected_with_comments = IO.read(self.path('c14n/result/with-comments/example-1'))
|
16
|
+
assert_equal(expected_with_comments, given_doc.canonicalize(:comments => true))
|
17
|
+
|
18
|
+
# Without Comments
|
19
|
+
expected_without_comments = IO.read(self.path('c14n/result/without-comments/example-1'))
|
20
|
+
assert_equal(expected_without_comments, given_doc.canonicalize)
|
21
|
+
assert_equal(expected_without_comments, given_doc.canonicalize(:comments => false))
|
22
|
+
|
23
|
+
# Without Comments (XML_C14N_1_1)
|
24
|
+
expected_1_1_without_comments = IO.read(self.path('c14n/result/1-1-without-comments/example-1'))
|
25
|
+
mode = LibXML::XML::Document::XML_C14N_1_1
|
26
|
+
assert_equal(expected_1_1_without_comments, given_doc.canonicalize(:mode => mode))
|
27
|
+
end#test_canonicalize_with_w3c_c14n_3_1
|
28
|
+
|
29
|
+
|
30
|
+
# (www.w3.org) 3.2 Whitespace in Document Content
|
31
|
+
# http://www.w3.org/TR/xml-c14n#Example-WhitespaceInContent
|
32
|
+
def test_canonicalize_with_w3c_c14n_3_2
|
33
|
+
given_doc = LibXML::XML::Document.file(self.path('c14n/given/example-2.xml'))
|
34
|
+
expected = IO.read(self.path('c14n/result/without-comments/example-2'))
|
35
|
+
assert_equal(expected, given_doc.canonicalize)
|
36
|
+
|
37
|
+
expected_1_1_without_comments = IO.read(self.path('c14n/result/1-1-without-comments/example-2'))
|
38
|
+
mode = LibXML::XML::Document::XML_C14N_1_1
|
39
|
+
assert_equal(expected_1_1_without_comments, given_doc.canonicalize(:mode => mode))
|
40
|
+
end
|
41
|
+
|
42
|
+
# (www.w3.org) 3.3 Start and End Tags
|
43
|
+
# http://www.w3.org/TR/xml-c14n#Example-SETags
|
44
|
+
# (2012-02-20) Test failing due to missing 'attr' in 'e9' node.
|
45
|
+
# - Embedded DTD not parsed out of XML, therefore default attributes are
|
46
|
+
# not applied to canonicalization.
|
47
|
+
def test_canonicalize_with_w3c_c14n_3_3
|
48
|
+
given_doc = LibXML::XML::Document.file(self.path('c14n/given/example-3.xml'))
|
49
|
+
expected = IO.read(self.path('c14n/result/without-comments/example-3'))
|
50
|
+
assert_equal(expected, given_doc.canonicalize)
|
51
|
+
|
52
|
+
expected_1_1_without_comments = IO.read(self.path('c14n/result/1-1-without-comments/example-3'))
|
53
|
+
mode = LibXML::XML::Document::XML_C14N_1_1
|
54
|
+
assert_equal(expected_1_1_without_comments, given_doc.canonicalize(:mode => mode))
|
55
|
+
end
|
56
|
+
|
57
|
+
# (www.w3.org) 3.4 Character Modifications and Character References
|
58
|
+
# http://www.w3.org/TR/xml-c14n#Example-Chars
|
59
|
+
def test_canonicalize_with_w3c_c14n_3_4
|
60
|
+
given_doc = LibXML::XML::Document.file(self.path('c14n/given/example-4.xml'))
|
61
|
+
expected = IO.read(self.path('c14n/result/without-comments/example-4'))
|
62
|
+
assert_equal(expected, given_doc.canonicalize)
|
63
|
+
|
64
|
+
expected_1_1_without_comments = IO.read(self.path('c14n/result/1-1-without-comments/example-4'))
|
65
|
+
mode = LibXML::XML::Document::XML_C14N_1_1
|
66
|
+
assert_equal(expected_1_1_without_comments, given_doc.canonicalize(:mode => mode))
|
67
|
+
end
|
68
|
+
|
69
|
+
# (www.w3.org) 3.5 Entity References
|
70
|
+
# http://www.w3.org/TR/xml-c14n#Example-Entities
|
71
|
+
# (2012-02-20) Failing likely due to a logic error
|
72
|
+
# - libxml2(c14n.c:1788) XML_ENTITY_REF_NODE is invalid node for parsing.
|
73
|
+
def test_canonicalize_with_w3c_c14n_3_5
|
74
|
+
#given_doc = LibXML::XML::Document.file(self.path('c14n/given/example-5.xml'))
|
75
|
+
|
76
|
+
# With Comments
|
77
|
+
#expected_with_comments = IO.read(self.path('c14n/result/with-comments/example-5'))
|
78
|
+
|
79
|
+
# TODO - CANNOT COMPLETE TEST unless libxml2 supports additional node types.
|
80
|
+
#assert_equal(expected_with_comments, given_doc.canonicalize(:comments => true))
|
81
|
+
|
82
|
+
# Without Comments
|
83
|
+
#expected_without_comments = IO.read(self.path('c14n/result/without-comments/example-5'))
|
84
|
+
# TODO - CANNOT COMPLETE TEST unless libxml2 supports additional node types.
|
85
|
+
#assert_equal(expected_without_comments, given_doc.canonicalize(:comments => false))
|
86
|
+
#expected_1_1_without_comments = IO.read(self.path('c14n/result/1-1-without-comments/example-5'))
|
87
|
+
#mode = LibXML::XML::Document::XML_C14N_1_1
|
88
|
+
|
89
|
+
# TODO - CANNOT COMPLETE TEST unless libxml2 supports additional node types.
|
90
|
+
#assert_equal(expected_1_1_without_comments, given_doc.canonicalize(:mode => mode))
|
91
|
+
end
|
92
|
+
|
93
|
+
# (www.w3.org) 3.6 UTF-8 Encoding
|
94
|
+
# http://www.w3.org/TR/xml-c14n#Example-UTF8
|
95
|
+
def test_canonicalize_with_w3c_c14n_3_6
|
96
|
+
given_doc = LibXML::XML::Document.file(self.path('c14n/given/example-6.xml'))
|
97
|
+
expected = IO.read(self.path('c14n/result/without-comments/example-6'), :encoding => Encoding::UTF_8)
|
98
|
+
assert_equal(expected, given_doc.canonicalize)
|
99
|
+
|
100
|
+
expected_1_1_without_comments = IO.read(self.path('c14n/result/1-1-without-comments/example-6'), :encoding => Encoding::UTF_8)
|
101
|
+
mode = LibXML::XML::Document::XML_C14N_1_1
|
102
|
+
assert_equal(expected_1_1_without_comments, given_doc.canonicalize(:mode => mode))
|
103
|
+
end
|
104
|
+
|
105
|
+
# (www.w3.org) 3.7 Document Subsets
|
106
|
+
# http://www.w3.org/TR/xml-c14n#Example-DocSubsets
|
107
|
+
def test_canonicalize_with_w3c_c14n_3_7
|
108
|
+
# Non Canonicalized Document
|
109
|
+
# given_doc = LibXML::XML::Document.file(self.path('c14n/given/example-7.xml'))
|
110
|
+
#expected = IO.read(self.path('c14n/result/without-comments/example-7'))
|
111
|
+
|
112
|
+
# e1_node = given_doc.find_first('ietf:e1', 'ietf:http://www.ietf.org')
|
113
|
+
|
114
|
+
# Select current node, all child nodes, all attributes and namespace nodes
|
115
|
+
#subdoc_nodes = e1_node.find("(.//.|.//@id|namespace::*)")
|
116
|
+
|
117
|
+
# TODO - This fails because the namespace nodes aren't taken into account
|
118
|
+
# assert_equal(expected, given_doc.canonicalize(:nodes => subdoc_nodes))
|
119
|
+
end
|
120
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require 'xml/libxml'
|
4
|
+
|
5
|
+
class TestDeprecatedRequire < Minitest::Test
|
6
|
+
def test_basic
|
7
|
+
xp = LibXML::XML::Parser.string('<ruby_array uga="booga" foo="bar"><fixnum>one</fixnum><fixnum>two</fixnum></ruby_array>')
|
8
|
+
assert_instance_of(LibXML::XML::Parser, xp)
|
9
|
+
@doc = xp.parse
|
10
|
+
assert_instance_of(LibXML::XML::Document, @doc)
|
11
|
+
end
|
12
|
+
end
|