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.
Files changed (131) hide show
  1. checksums.yaml +4 -4
  2. data/{HISTORY → CHANGELOG.md} +875 -930
  3. data/LICENSE +20 -20
  4. data/README.md +67 -0
  5. data/Rakefile +13 -34
  6. data/ext/libxml/extconf.rb +34 -20
  7. data/ext/libxml/libxml.c +2 -14
  8. data/ext/libxml/ruby_libxml.h +1 -1
  9. data/ext/libxml/ruby_xml_attr.c +27 -22
  10. data/ext/libxml/ruby_xml_attr.h +1 -0
  11. data/ext/libxml/ruby_xml_attr_decl.c +19 -12
  12. data/ext/libxml/ruby_xml_attributes.c +18 -9
  13. data/ext/libxml/ruby_xml_document.c +111 -98
  14. data/ext/libxml/ruby_xml_document.h +1 -0
  15. data/ext/libxml/ruby_xml_dtd.c +49 -19
  16. data/ext/libxml/ruby_xml_dtd.h +1 -0
  17. data/ext/libxml/ruby_xml_html_parser.c +1 -1
  18. data/ext/libxml/ruby_xml_html_parser_context.c +19 -6
  19. data/ext/libxml/ruby_xml_html_parser_context.h +1 -0
  20. data/ext/libxml/ruby_xml_input_cbg.c +45 -17
  21. data/ext/libxml/ruby_xml_io.c +3 -1
  22. data/ext/libxml/ruby_xml_namespace.c +20 -12
  23. data/ext/libxml/ruby_xml_namespace.h +1 -0
  24. data/ext/libxml/ruby_xml_namespaces.c +40 -20
  25. data/ext/libxml/ruby_xml_node.c +71 -32
  26. data/ext/libxml/ruby_xml_node.h +2 -0
  27. data/ext/libxml/ruby_xml_parser.c +1 -1
  28. data/ext/libxml/ruby_xml_parser_context.c +54 -47
  29. data/ext/libxml/ruby_xml_parser_context.h +1 -0
  30. data/ext/libxml/ruby_xml_reader.c +25 -15
  31. data/ext/libxml/ruby_xml_registry.c +31 -0
  32. data/ext/libxml/ruby_xml_registry.h +22 -0
  33. data/ext/libxml/ruby_xml_relaxng.c +21 -5
  34. data/ext/libxml/ruby_xml_relaxng.h +1 -0
  35. data/ext/libxml/ruby_xml_sax_parser.c +1 -1
  36. data/ext/libxml/ruby_xml_schema.c +18 -11
  37. data/ext/libxml/ruby_xml_schema.h +1 -0
  38. data/ext/libxml/ruby_xml_schema_attribute.c +7 -7
  39. data/ext/libxml/ruby_xml_schema_element.c +8 -8
  40. data/ext/libxml/ruby_xml_schema_facet.c +7 -7
  41. data/ext/libxml/ruby_xml_schema_type.c +12 -19
  42. data/ext/libxml/ruby_xml_version.h +4 -4
  43. data/ext/libxml/ruby_xml_writer.c +18 -6
  44. data/ext/libxml/ruby_xml_xpath.c +2 -2
  45. data/ext/libxml/ruby_xml_xpath.h +1 -1
  46. data/ext/libxml/ruby_xml_xpath_context.c +72 -26
  47. data/ext/libxml/ruby_xml_xpath_expression.c +11 -5
  48. data/ext/libxml/ruby_xml_xpath_expression.h +1 -0
  49. data/ext/libxml/ruby_xml_xpath_object.c +69 -54
  50. data/ext/libxml/ruby_xml_xpath_object.h +3 -1
  51. data/ext/vc/libxml_ruby/libxml_ruby.vcxproj +271 -0
  52. data/ext/xcode/libxml-ruby.xcodeproj/project.pbxproj +633 -0
  53. data/ext/xcode/libxml-ruby.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
  54. data/ext/xcode/libxml-ruby.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -0
  55. data/ext/xcode/libxml-ruby.xcodeproj/xcshareddata/xcschemes/libxml-ruby.xcscheme +80 -0
  56. data/lib/libxml/document.rb +0 -29
  57. data/lib/libxml/error.rb +30 -3
  58. data/lib/libxml/html_parser.rb +0 -16
  59. data/lib/libxml/node.rb +1 -3
  60. data/lib/libxml/parser.rb +0 -8
  61. data/lib/libxml/schema/attribute.rb +27 -19
  62. data/lib/libxml/schema/element.rb +20 -0
  63. data/lib/libxml/schema/type.rb +44 -21
  64. data/lib/libxml/schema.rb +47 -47
  65. data/lib/libxml-ruby.rb +30 -30
  66. data/libxml-ruby.gemspec +12 -16
  67. data/test/c14n/result/1-1-without-comments/example-1 +3 -3
  68. data/test/c14n/result/1-1-without-comments/example-2 +10 -10
  69. data/test/c14n/result/1-1-without-comments/example-3 +13 -13
  70. data/test/c14n/result/1-1-without-comments/example-4 +8 -8
  71. data/test/c14n/result/1-1-without-comments/example-5 +2 -2
  72. data/test/c14n/result/with-comments/example-1 +5 -5
  73. data/test/c14n/result/with-comments/example-2 +10 -10
  74. data/test/c14n/result/with-comments/example-3 +13 -13
  75. data/test/c14n/result/with-comments/example-4 +8 -8
  76. data/test/c14n/result/with-comments/example-5 +3 -3
  77. data/test/c14n/result/without-comments/example-1 +3 -3
  78. data/test/c14n/result/without-comments/example-2 +10 -10
  79. data/test/c14n/result/without-comments/example-3 +13 -13
  80. data/test/c14n/result/without-comments/example-4 +8 -8
  81. data/test/c14n/result/without-comments/example-5 +2 -2
  82. data/test/test_attr.rb +179 -180
  83. data/test/test_attr_decl.rb +131 -131
  84. data/test/test_attributes.rb +135 -135
  85. data/test/test_canonicalize.rb +122 -120
  86. data/test/test_document.rb +2 -4
  87. data/test/test_dtd.rb +12 -4
  88. data/test/test_encoding_sax.rb +114 -114
  89. data/test/test_error.rb +1 -1
  90. data/test/test_html_parser.rb +6 -2
  91. data/test/test_html_parser_context.rb +22 -22
  92. data/test/test_input_callbacks.rb +36 -0
  93. data/test/test_namespace.rb +1 -1
  94. data/test/test_namespaces.rb +200 -200
  95. data/test/test_node.rb +16 -0
  96. data/test/test_node_cdata.rb +50 -50
  97. data/test/test_node_comment.rb +32 -32
  98. data/test/test_node_copy.rb +40 -40
  99. data/test/test_node_edit.rb +176 -158
  100. data/test/test_node_pi.rb +37 -37
  101. data/test/test_node_text.rb +69 -69
  102. data/test/test_node_xlink.rb +28 -28
  103. data/test/test_parser.rb +5 -41
  104. data/test/test_parser_context.rb +198 -198
  105. data/test/test_properties.rb +38 -38
  106. data/test/test_reader.rb +55 -6
  107. data/test/test_relaxng.rb +59 -53
  108. data/test/test_sax_parser.rb +345 -345
  109. data/test/test_schema.rb +28 -0
  110. data/test/test_traversal.rb +152 -152
  111. data/test/test_writer.rb +0 -31
  112. data/test/test_xinclude.rb +20 -20
  113. data/test/test_xml.rb +3 -7
  114. data/test/test_xpath.rb +244 -244
  115. data/test/test_xpath_context.rb +87 -87
  116. data/test/test_xpath_expression.rb +37 -37
  117. metadata +32 -25
  118. data/README.rdoc +0 -208
  119. data/ext/libxml/extconf.h +0 -4
  120. data/ext/libxml/ruby_xml_cbg.c +0 -85
  121. data/lib/libxml/hpricot.rb +0 -78
  122. data/lib/libxml.rb +0 -5
  123. data/lib/xml/libxml.rb +0 -10
  124. data/lib/xml.rb +0 -14
  125. data/script/benchmark/depixelate +0 -634
  126. data/script/benchmark/hamlet.xml +0 -9055
  127. data/script/benchmark/parsecount +0 -170
  128. data/script/benchmark/sock_entries.xml +0 -507
  129. data/script/benchmark/throughput +0 -41
  130. data/script/test +0 -6
  131. 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