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_attr_decl.rb
CHANGED
|
@@ -1,132 +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
|
|
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
132
|
end
|
data/test/test_attributes.rb
CHANGED
|
@@ -1,136 +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
|
|
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
136
|
end
|