libxml-ruby 4.1.2 → 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.
Files changed (172) hide show
  1. checksums.yaml +4 -4
  2. data/{HISTORY → CHANGELOG.md} +875 -887
  3. data/LICENSE +20 -20
  4. data/README.md +67 -0
  5. data/Rakefile +77 -98
  6. data/ext/libxml/extconf.rb +39 -20
  7. data/ext/libxml/libxml.c +67 -79
  8. data/ext/libxml/ruby_libxml.h +43 -44
  9. data/ext/libxml/ruby_xml.c +556 -899
  10. data/ext/libxml/ruby_xml.h +9 -10
  11. data/ext/libxml/ruby_xml_attr.c +338 -333
  12. data/ext/libxml/ruby_xml_attr.h +13 -12
  13. data/ext/libxml/ruby_xml_attr_decl.c +19 -12
  14. data/ext/libxml/ruby_xml_attr_decl.h +11 -11
  15. data/ext/libxml/ruby_xml_attributes.c +18 -9
  16. data/ext/libxml/ruby_xml_attributes.h +17 -15
  17. data/ext/libxml/ruby_xml_document.c +1142 -1129
  18. data/ext/libxml/ruby_xml_document.h +12 -11
  19. data/ext/libxml/ruby_xml_dtd.c +287 -248
  20. data/ext/libxml/ruby_xml_dtd.h +10 -9
  21. data/ext/libxml/ruby_xml_encoding.c +250 -250
  22. data/ext/libxml/ruby_xml_encoding.h +20 -18
  23. data/ext/libxml/ruby_xml_error.c +1003 -996
  24. data/ext/libxml/ruby_xml_error.h +14 -14
  25. data/ext/libxml/ruby_xml_html_parser.c +91 -91
  26. data/ext/libxml/ruby_xml_html_parser.h +10 -10
  27. data/ext/libxml/ruby_xml_html_parser_context.c +364 -337
  28. data/ext/libxml/ruby_xml_html_parser_context.h +11 -10
  29. data/ext/libxml/ruby_xml_html_parser_options.c +48 -48
  30. data/ext/libxml/ruby_xml_html_parser_options.h +10 -10
  31. data/ext/libxml/ruby_xml_input_cbg.c +216 -188
  32. data/ext/libxml/ruby_xml_input_cbg.h +20 -20
  33. data/ext/libxml/ruby_xml_io.c +49 -47
  34. data/ext/libxml/ruby_xml_io.h +10 -10
  35. data/ext/libxml/ruby_xml_namespace.c +159 -154
  36. data/ext/libxml/ruby_xml_namespace.h +11 -10
  37. data/ext/libxml/ruby_xml_namespaces.c +313 -293
  38. data/ext/libxml/ruby_xml_namespaces.h +9 -9
  39. data/ext/libxml/ruby_xml_node.c +1433 -1398
  40. data/ext/libxml/ruby_xml_node.h +15 -13
  41. data/ext/libxml/ruby_xml_parser.c +91 -91
  42. data/ext/libxml/ruby_xml_parser.h +10 -10
  43. data/ext/libxml/ruby_xml_parser_context.c +1016 -1001
  44. data/ext/libxml/ruby_xml_parser_context.h +11 -10
  45. data/ext/libxml/ruby_xml_parser_options.c +74 -66
  46. data/ext/libxml/ruby_xml_parser_options.h +10 -10
  47. data/ext/libxml/ruby_xml_reader.c +40 -31
  48. data/ext/libxml/ruby_xml_reader.h +14 -14
  49. data/ext/libxml/ruby_xml_registry.c +31 -0
  50. data/ext/libxml/ruby_xml_registry.h +22 -0
  51. data/ext/libxml/ruby_xml_relaxng.c +21 -5
  52. data/ext/libxml/ruby_xml_relaxng.h +9 -8
  53. data/ext/libxml/ruby_xml_sax2_handler.c +326 -326
  54. data/ext/libxml/ruby_xml_sax2_handler.h +10 -10
  55. data/ext/libxml/ruby_xml_sax_parser.c +108 -116
  56. data/ext/libxml/ruby_xml_sax_parser.h +10 -10
  57. data/ext/libxml/ruby_xml_schema.c +22 -15
  58. data/ext/libxml/ruby_xml_schema.h +26 -25
  59. data/ext/libxml/ruby_xml_schema_attribute.c +7 -7
  60. data/ext/libxml/ruby_xml_schema_attribute.h +37 -37
  61. data/ext/libxml/ruby_xml_schema_element.c +8 -8
  62. data/ext/libxml/ruby_xml_schema_element.h +11 -11
  63. data/ext/libxml/ruby_xml_schema_facet.c +50 -50
  64. data/ext/libxml/ruby_xml_schema_facet.h +9 -9
  65. data/ext/libxml/ruby_xml_schema_type.c +12 -19
  66. data/ext/libxml/ruby_xml_schema_type.h +9 -9
  67. data/ext/libxml/ruby_xml_version.h +9 -9
  68. data/ext/libxml/ruby_xml_writer.c +183 -185
  69. data/ext/libxml/ruby_xml_writer.h +6 -6
  70. data/ext/libxml/ruby_xml_xinclude.c +20 -20
  71. data/ext/libxml/ruby_xml_xinclude.h +11 -11
  72. data/ext/libxml/ruby_xml_xpath.c +195 -195
  73. data/ext/libxml/ruby_xml_xpath.h +15 -15
  74. data/ext/libxml/ruby_xml_xpath_context.c +408 -362
  75. data/ext/libxml/ruby_xml_xpath_context.h +9 -9
  76. data/ext/libxml/ruby_xml_xpath_expression.c +12 -6
  77. data/ext/libxml/ruby_xml_xpath_expression.h +11 -10
  78. data/ext/libxml/ruby_xml_xpath_object.c +69 -54
  79. data/ext/libxml/ruby_xml_xpath_object.h +19 -17
  80. data/ext/vc/libxml_ruby/libxml_ruby.vcxproj +271 -0
  81. data/ext/xcode/libxml-ruby.xcodeproj/project.pbxproj +633 -0
  82. data/ext/xcode/libxml-ruby.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
  83. data/ext/xcode/libxml-ruby.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -0
  84. data/ext/xcode/libxml-ruby.xcodeproj/xcshareddata/xcschemes/libxml-ruby.xcscheme +80 -0
  85. data/lib/libxml/attr.rb +122 -122
  86. data/lib/libxml/attr_decl.rb +80 -80
  87. data/lib/libxml/attributes.rb +13 -13
  88. data/lib/libxml/document.rb +165 -194
  89. data/lib/libxml/error.rb +122 -95
  90. data/lib/libxml/html_parser.rb +80 -96
  91. data/lib/libxml/namespace.rb +61 -61
  92. data/lib/libxml/namespaces.rb +37 -37
  93. data/lib/libxml/node.rb +321 -323
  94. data/lib/libxml/parser.rb +94 -100
  95. data/lib/libxml/sax_callbacks.rb +179 -179
  96. data/lib/libxml/sax_parser.rb +40 -40
  97. data/lib/libxml/schema/attribute.rb +27 -19
  98. data/lib/libxml/schema/element.rb +20 -0
  99. data/lib/libxml/schema/type.rb +44 -21
  100. data/lib/libxml/schema.rb +47 -47
  101. data/lib/libxml/tree.rb +28 -28
  102. data/lib/libxml-ruby.rb +30 -30
  103. data/libxml-ruby.gemspec +46 -48
  104. data/test/c14n/result/1-1-without-comments/example-1 +3 -3
  105. data/test/c14n/result/1-1-without-comments/example-2 +10 -10
  106. data/test/c14n/result/1-1-without-comments/example-3 +13 -13
  107. data/test/c14n/result/1-1-without-comments/example-4 +8 -8
  108. data/test/c14n/result/1-1-without-comments/example-5 +2 -2
  109. data/test/c14n/result/with-comments/example-1 +5 -5
  110. data/test/c14n/result/with-comments/example-2 +10 -10
  111. data/test/c14n/result/with-comments/example-3 +13 -13
  112. data/test/c14n/result/with-comments/example-4 +8 -8
  113. data/test/c14n/result/with-comments/example-5 +3 -3
  114. data/test/c14n/result/without-comments/example-1 +3 -3
  115. data/test/c14n/result/without-comments/example-2 +10 -10
  116. data/test/c14n/result/without-comments/example-3 +13 -13
  117. data/test/c14n/result/without-comments/example-4 +8 -8
  118. data/test/c14n/result/without-comments/example-5 +2 -2
  119. data/test/test_attr.rb +179 -180
  120. data/test/test_attr_decl.rb +131 -131
  121. data/test/test_attributes.rb +135 -135
  122. data/test/test_canonicalize.rb +122 -120
  123. data/test/test_document.rb +138 -132
  124. data/test/test_document_write.rb +142 -145
  125. data/test/test_dtd.rb +134 -129
  126. data/test/test_encoding.rb +126 -129
  127. data/test/test_encoding_sax.rb +114 -114
  128. data/test/test_error.rb +197 -194
  129. data/test/test_helper.rb +21 -13
  130. data/test/test_html_parser.rb +166 -162
  131. data/test/test_html_parser_context.rb +22 -22
  132. data/test/test_input_callbacks.rb +36 -0
  133. data/test/test_namespace.rb +58 -60
  134. data/test/test_namespaces.rb +200 -200
  135. data/test/test_node.rb +251 -237
  136. data/test/test_node_cdata.rb +50 -50
  137. data/test/test_node_comment.rb +32 -32
  138. data/test/test_node_copy.rb +40 -40
  139. data/test/test_node_edit.rb +176 -158
  140. data/test/test_node_pi.rb +37 -37
  141. data/test/test_node_text.rb +69 -69
  142. data/test/test_node_write.rb +93 -96
  143. data/test/test_node_xlink.rb +28 -28
  144. data/test/test_parser.rb +297 -324
  145. data/test/test_parser_context.rb +198 -198
  146. data/test/test_properties.rb +38 -38
  147. data/test/test_reader.rb +413 -364
  148. data/test/test_relaxng.rb +59 -53
  149. data/test/test_sax_parser.rb +345 -326
  150. data/test/test_schema.rb +28 -0
  151. data/test/test_traversal.rb +152 -152
  152. data/test/test_writer.rb +469 -468
  153. data/test/test_xinclude.rb +20 -20
  154. data/test/test_xml.rb +164 -267
  155. data/test/test_xpath.rb +244 -244
  156. data/test/test_xpath_context.rb +87 -87
  157. data/test/test_xpath_expression.rb +37 -37
  158. metadata +49 -31
  159. data/README.rdoc +0 -217
  160. data/ext/libxml/extconf.h +0 -3
  161. data/ext/libxml/ruby_xml_cbg.c +0 -85
  162. data/lib/libxml/hpricot.rb +0 -78
  163. data/lib/libxml.rb +0 -5
  164. data/lib/xml/libxml.rb +0 -10
  165. data/lib/xml.rb +0 -14
  166. data/script/benchmark/depixelate +0 -634
  167. data/script/benchmark/hamlet.xml +0 -9055
  168. data/script/benchmark/parsecount +0 -170
  169. data/script/benchmark/sock_entries.xml +0 -507
  170. data/script/benchmark/throughput +0 -41
  171. data/script/test +0 -6
  172. data/test/test_deprecated_require.rb +0 -12
@@ -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
@@ -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