rubysl-rexml 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (179) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +17 -0
  3. data/.travis.yml +8 -0
  4. data/Gemfile +4 -0
  5. data/LICENSE +25 -0
  6. data/README.md +29 -0
  7. data/Rakefile +1 -0
  8. data/lib/rexml/attlistdecl.rb +62 -0
  9. data/lib/rexml/attribute.rb +185 -0
  10. data/lib/rexml/cdata.rb +67 -0
  11. data/lib/rexml/child.rb +96 -0
  12. data/lib/rexml/comment.rb +80 -0
  13. data/lib/rexml/doctype.rb +271 -0
  14. data/lib/rexml/document.rb +230 -0
  15. data/lib/rexml/dtd/attlistdecl.rb +10 -0
  16. data/lib/rexml/dtd/dtd.rb +51 -0
  17. data/lib/rexml/dtd/elementdecl.rb +17 -0
  18. data/lib/rexml/dtd/entitydecl.rb +56 -0
  19. data/lib/rexml/dtd/notationdecl.rb +39 -0
  20. data/lib/rexml/element.rb +1227 -0
  21. data/lib/rexml/encoding.rb +71 -0
  22. data/lib/rexml/encodings/CP-1252.rb +103 -0
  23. data/lib/rexml/encodings/EUC-JP.rb +35 -0
  24. data/lib/rexml/encodings/ICONV.rb +22 -0
  25. data/lib/rexml/encodings/ISO-8859-1.rb +7 -0
  26. data/lib/rexml/encodings/ISO-8859-15.rb +72 -0
  27. data/lib/rexml/encodings/SHIFT-JIS.rb +37 -0
  28. data/lib/rexml/encodings/SHIFT_JIS.rb +1 -0
  29. data/lib/rexml/encodings/UNILE.rb +34 -0
  30. data/lib/rexml/encodings/US-ASCII.rb +30 -0
  31. data/lib/rexml/encodings/UTF-16.rb +35 -0
  32. data/lib/rexml/encodings/UTF-8.rb +18 -0
  33. data/lib/rexml/entity.rb +166 -0
  34. data/lib/rexml/formatters/default.rb +109 -0
  35. data/lib/rexml/formatters/pretty.rb +138 -0
  36. data/lib/rexml/formatters/transitive.rb +56 -0
  37. data/lib/rexml/functions.rb +382 -0
  38. data/lib/rexml/instruction.rb +70 -0
  39. data/lib/rexml/light/node.rb +196 -0
  40. data/lib/rexml/namespace.rb +47 -0
  41. data/lib/rexml/node.rb +75 -0
  42. data/lib/rexml/output.rb +24 -0
  43. data/lib/rexml/parent.rb +166 -0
  44. data/lib/rexml/parseexception.rb +51 -0
  45. data/lib/rexml/parsers/baseparser.rb +503 -0
  46. data/lib/rexml/parsers/lightparser.rb +60 -0
  47. data/lib/rexml/parsers/pullparser.rb +196 -0
  48. data/lib/rexml/parsers/sax2parser.rb +238 -0
  49. data/lib/rexml/parsers/streamparser.rb +46 -0
  50. data/lib/rexml/parsers/treeparser.rb +97 -0
  51. data/lib/rexml/parsers/ultralightparser.rb +56 -0
  52. data/lib/rexml/parsers/xpathparser.rb +698 -0
  53. data/lib/rexml/quickpath.rb +266 -0
  54. data/lib/rexml/rexml.rb +32 -0
  55. data/lib/rexml/sax2listener.rb +97 -0
  56. data/lib/rexml/source.rb +251 -0
  57. data/lib/rexml/streamlistener.rb +92 -0
  58. data/lib/rexml/syncenumerator.rb +33 -0
  59. data/lib/rexml/text.rb +344 -0
  60. data/lib/rexml/undefinednamespaceexception.rb +8 -0
  61. data/lib/rexml/validation/relaxng.rb +559 -0
  62. data/lib/rexml/validation/validation.rb +155 -0
  63. data/lib/rexml/validation/validationexception.rb +9 -0
  64. data/lib/rexml/xmldecl.rb +119 -0
  65. data/lib/rexml/xmltokens.rb +18 -0
  66. data/lib/rexml/xpath.rb +66 -0
  67. data/lib/rexml/xpath_parser.rb +792 -0
  68. data/lib/rubysl/rexml.rb +1 -0
  69. data/lib/rubysl/rexml/version.rb +5 -0
  70. data/rubysl-rexml.gemspec +23 -0
  71. data/spec/attribute/clone_spec.rb +10 -0
  72. data/spec/attribute/element_spec.rb +22 -0
  73. data/spec/attribute/equal_value_spec.rb +17 -0
  74. data/spec/attribute/hash_spec.rb +12 -0
  75. data/spec/attribute/initialize_spec.rb +28 -0
  76. data/spec/attribute/inspect_spec.rb +19 -0
  77. data/spec/attribute/namespace_spec.rb +23 -0
  78. data/spec/attribute/node_type_spec.rb +9 -0
  79. data/spec/attribute/prefix_spec.rb +17 -0
  80. data/spec/attribute/remove_spec.rb +19 -0
  81. data/spec/attribute/to_s_spec.rb +13 -0
  82. data/spec/attribute/to_string_spec.rb +14 -0
  83. data/spec/attribute/value_spec.rb +14 -0
  84. data/spec/attribute/write_spec.rb +22 -0
  85. data/spec/attribute/xpath_spec.rb +19 -0
  86. data/spec/attributes/add_spec.rb +6 -0
  87. data/spec/attributes/append_spec.rb +6 -0
  88. data/spec/attributes/delete_all_spec.rb +30 -0
  89. data/spec/attributes/delete_spec.rb +26 -0
  90. data/spec/attributes/each_attribute_spec.rb +24 -0
  91. data/spec/attributes/each_spec.rb +24 -0
  92. data/spec/attributes/element_reference_spec.rb +18 -0
  93. data/spec/attributes/element_set_spec.rb +25 -0
  94. data/spec/attributes/get_attribute_ns_spec.rb +13 -0
  95. data/spec/attributes/get_attribute_spec.rb +28 -0
  96. data/spec/attributes/initialize_spec.rb +18 -0
  97. data/spec/attributes/length_spec.rb +6 -0
  98. data/spec/attributes/namespaces_spec.rb +5 -0
  99. data/spec/attributes/prefixes_spec.rb +23 -0
  100. data/spec/attributes/shared/add.rb +17 -0
  101. data/spec/attributes/shared/length.rb +12 -0
  102. data/spec/attributes/size_spec.rb +6 -0
  103. data/spec/attributes/to_a_spec.rb +20 -0
  104. data/spec/cdata/clone_spec.rb +9 -0
  105. data/spec/cdata/initialize_spec.rb +24 -0
  106. data/spec/cdata/shared/to_s.rb +11 -0
  107. data/spec/cdata/to_s_spec.rb +6 -0
  108. data/spec/cdata/value_spec.rb +6 -0
  109. data/spec/document/add_element_spec.rb +30 -0
  110. data/spec/document/add_spec.rb +60 -0
  111. data/spec/document/clone_spec.rb +19 -0
  112. data/spec/document/doctype_spec.rb +14 -0
  113. data/spec/document/encoding_spec.rb +21 -0
  114. data/spec/document/expanded_name_spec.rb +15 -0
  115. data/spec/document/new_spec.rb +37 -0
  116. data/spec/document/node_type_spec.rb +7 -0
  117. data/spec/document/root_spec.rb +11 -0
  118. data/spec/document/stand_alone_spec.rb +18 -0
  119. data/spec/document/version_spec.rb +13 -0
  120. data/spec/document/write_spec.rb +38 -0
  121. data/spec/document/xml_decl_spec.rb +14 -0
  122. data/spec/element/add_attribute_spec.rb +40 -0
  123. data/spec/element/add_attributes_spec.rb +21 -0
  124. data/spec/element/add_element_spec.rb +38 -0
  125. data/spec/element/add_namespace_spec.rb +23 -0
  126. data/spec/element/add_text_spec.rb +23 -0
  127. data/spec/element/attribute_spec.rb +16 -0
  128. data/spec/element/attributes_spec.rb +18 -0
  129. data/spec/element/cdatas_spec.rb +23 -0
  130. data/spec/element/clone_spec.rb +28 -0
  131. data/spec/element/comments_spec.rb +20 -0
  132. data/spec/element/delete_attribute_spec.rb +38 -0
  133. data/spec/element/delete_element_spec.rb +50 -0
  134. data/spec/element/delete_namespace_spec.rb +24 -0
  135. data/spec/element/document_spec.rb +17 -0
  136. data/spec/element/each_element_with_attribute_spec.rb +34 -0
  137. data/spec/element/each_element_with_text_spec.rb +30 -0
  138. data/spec/element/get_text_spec.rb +17 -0
  139. data/spec/element/has_attributes_spec.rb +16 -0
  140. data/spec/element/has_elements_spec.rb +17 -0
  141. data/spec/element/has_text_spec.rb +15 -0
  142. data/spec/element/inspect_spec.rb +26 -0
  143. data/spec/element/instructions_spec.rb +20 -0
  144. data/spec/element/namespace_spec.rb +26 -0
  145. data/spec/element/namespaces_spec.rb +31 -0
  146. data/spec/element/new_spec.rb +34 -0
  147. data/spec/element/next_element_spec.rb +18 -0
  148. data/spec/element/node_type_spec.rb +7 -0
  149. data/spec/element/prefixes_spec.rb +22 -0
  150. data/spec/element/previous_element_spec.rb +19 -0
  151. data/spec/element/raw_spec.rb +23 -0
  152. data/spec/element/root_spec.rb +27 -0
  153. data/spec/element/text_spec.rb +45 -0
  154. data/spec/element/texts_spec.rb +15 -0
  155. data/spec/element/whitespace_spec.rb +22 -0
  156. data/spec/node/each_recursive_spec.rb +20 -0
  157. data/spec/node/find_first_recursive_spec.rb +24 -0
  158. data/spec/node/index_in_parent_spec.rb +14 -0
  159. data/spec/node/next_sibling_node_spec.rb +20 -0
  160. data/spec/node/parent_spec.rb +20 -0
  161. data/spec/node/previous_sibling_node_spec.rb +20 -0
  162. data/spec/shared/each_element.rb +35 -0
  163. data/spec/shared/elements_to_a.rb +35 -0
  164. data/spec/text/append_spec.rb +9 -0
  165. data/spec/text/clone_spec.rb +9 -0
  166. data/spec/text/comparison_spec.rb +24 -0
  167. data/spec/text/empty_spec.rb +11 -0
  168. data/spec/text/indent_text_spec.rb +23 -0
  169. data/spec/text/inspect_spec.rb +7 -0
  170. data/spec/text/new_spec.rb +48 -0
  171. data/spec/text/node_type_spec.rb +7 -0
  172. data/spec/text/normalize_spec.rb +7 -0
  173. data/spec/text/read_with_substitution_spec.rb +12 -0
  174. data/spec/text/to_s_spec.rb +17 -0
  175. data/spec/text/unnormalize_spec.rb +7 -0
  176. data/spec/text/value_spec.rb +36 -0
  177. data/spec/text/wrap_spec.rb +20 -0
  178. data/spec/text/write_with_substitution_spec.rb +32 -0
  179. metadata +385 -0
@@ -0,0 +1 @@
1
+ require "rubysl/rexml/version"
@@ -0,0 +1,5 @@
1
+ module RubySL
2
+ module REXML
3
+ VERSION = "1.0.0"
4
+ end
5
+ end
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ require './lib/rubysl/rexml/version'
3
+
4
+ Gem::Specification.new do |spec|
5
+ spec.name = "rubysl-rexml"
6
+ spec.version = RubySL::REXML::VERSION
7
+ spec.authors = ["Brian Shirai"]
8
+ spec.email = ["brixen@gmail.com"]
9
+ spec.description = %q{Ruby standard library rexml.}
10
+ spec.summary = %q{Ruby standard library rexml.}
11
+ spec.homepage = "https://github.com/rubysl/rubysl-rexml"
12
+ spec.license = "BSD"
13
+
14
+ spec.files = `git ls-files`.split($/)
15
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
16
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
17
+ spec.require_paths = ["lib"]
18
+
19
+ spec.add_development_dependency "bundler", "~> 1.3"
20
+ spec.add_development_dependency "rake", "~> 10.0"
21
+ spec.add_development_dependency "mspec", "~> 1.5"
22
+ spec.add_development_dependency "rubysl-prettyprint", "~> 1.0"
23
+ end
@@ -0,0 +1,10 @@
1
+ require 'rexml/document'
2
+
3
+ describe "REXML::Attribute#clone" do
4
+ it "returns a copy of this Attribute" do
5
+ orig = REXML::Attribute.new("name", "value&&")
6
+ orig.should == orig.clone
7
+ orig.clone.to_s.should == orig.to_s
8
+ orig.clone.to_string.should == orig.to_string
9
+ end
10
+ end
@@ -0,0 +1,22 @@
1
+ require 'rexml/document'
2
+
3
+ describe "REXML::Attribute#element" do
4
+ it "returns the parent element" do
5
+ e = REXML::Element.new "root"
6
+
7
+ REXML::Attribute.new("name", "value", e).element.should == e
8
+ REXML::Attribute.new("name", "default_constructor").element.should == nil
9
+ end
10
+ end
11
+
12
+ describe "REXML::Attribute#element=" do
13
+ it "sets the parent element" do
14
+ e = REXML::Element.new "root"
15
+ f = REXML::Element.new "temp"
16
+ a = REXML::Attribute.new("name", "value", e)
17
+ a.element.should == e
18
+
19
+ a.element = f
20
+ a.element.should == f
21
+ end
22
+ end
@@ -0,0 +1,17 @@
1
+ require 'rexml/document'
2
+
3
+ describe "REXML::Attribute#==" do
4
+ it "returns true if other has equal name and value" do
5
+ a1 = REXML::Attribute.new("foo", "bar")
6
+ a1.should == a1.clone
7
+
8
+ a2 = REXML::Attribute.new("foo", "bar")
9
+ a1.should == a2
10
+
11
+ a3 = REXML::Attribute.new("foo", "bla")
12
+ a1.should_not == a3
13
+
14
+ a4 = REXML::Attribute.new("baz", "bar")
15
+ a1.should_not == a4
16
+ end
17
+ end
@@ -0,0 +1,12 @@
1
+ require 'rexml/document'
2
+
3
+ describe "REXML::Attribute#hash" do
4
+ # These are not really complete, any idea on how to make them more
5
+ # "testable" will be appreciated.
6
+ it "returns a hashcode made of the name and value of self" do
7
+ a = REXML::Attribute.new("name", "value")
8
+ a.hash.should be_kind_of(Numeric)
9
+ b = REXML::Attribute.new(a)
10
+ a.hash.should == b.hash
11
+ end
12
+ end
@@ -0,0 +1,28 @@
1
+ require 'rexml/document'
2
+
3
+ describe "REXML::Attribute#initialize" do
4
+ before :each do
5
+ @e = REXML::Element.new "root"
6
+ @name = REXML::Attribute.new("name", "Nicko")
7
+ @e.add_attribute @name
8
+ end
9
+
10
+ it "receives two strings for name and value" do
11
+ @e.attributes["name"].should == "Nicko"
12
+ @e.add_attribute REXML::Attribute.new("last_name", nil)
13
+ @e.attributes["last_name"].should == ""
14
+ end
15
+
16
+ it "receives an Attribute and clones it" do
17
+ copy = REXML::Attribute.new(@name)
18
+ copy.should == @name
19
+ end
20
+
21
+ it "recives a parent node" do
22
+ last_name = REXML::Attribute.new("last_name", "McBrain", @e)
23
+ last_name.element.should == @e
24
+
25
+ last_name = REXML::Attribute.new(@name, @e)
26
+ last_name.element.should == @e
27
+ end
28
+ end
@@ -0,0 +1,19 @@
1
+ require 'rexml/document'
2
+
3
+ describe "REXML::Attribute#inspect" do
4
+ it "returns the name and value as a string" do
5
+ a = REXML::Attribute.new("my_name", "my_value")
6
+ a.inspect.should == "my_name='my_value'"
7
+ end
8
+
9
+ it "accepts attributes with no value" do
10
+ a = REXML::Attribute.new("my_name")
11
+ a.inspect.should == "my_name=''"
12
+ end
13
+
14
+ it "does not escape text" do
15
+ a = REXML::Attribute.new("&&", "<>")
16
+ a.inspect.should == "&&='<>'"
17
+ end
18
+ end
19
+
@@ -0,0 +1,23 @@
1
+ require 'rexml/document'
2
+
3
+ describe "REXML::Attribute#namespace" do
4
+ it "returns the namespace url" do
5
+ e = REXML::Element.new("root")
6
+ e.add_attribute REXML::Attribute.new("xmlns:ns", "http://some_uri")
7
+ e.namespace("ns").should == "http://some_uri"
8
+ end
9
+
10
+ it "returns nil if namespace is not defined" do
11
+ e = REXML::Element.new("root")
12
+ e.add_attribute REXML::Attribute.new("test", "value")
13
+ e.namespace("test").should == nil
14
+ e.namespace("ns").should == nil
15
+ end
16
+
17
+ it "defaults arg to nil" do
18
+ e = REXML::Element.new("root")
19
+ e.add_attribute REXML::Attribute.new("xmlns:ns", "http://some_uri")
20
+ e.namespace.should == ""
21
+ e.namespace("ns").should == "http://some_uri"
22
+ end
23
+ end
@@ -0,0 +1,9 @@
1
+ require 'rexml/document'
2
+
3
+ describe "REXML::Attribute#node_type" do
4
+ it "always returns :attribute" do
5
+ attr = REXML::Attribute.new("foo", "bar")
6
+ attr.node_type.should == :attribute
7
+ REXML::Attribute.new(attr).node_type.should == :attribute
8
+ end
9
+ end
@@ -0,0 +1,17 @@
1
+ require 'rexml/document'
2
+
3
+ describe "REXML::Attribute#prefix" do
4
+ it "returns the namespace of the Attribute" do
5
+ ans = REXML::Attribute.new("ns:someattr", "some_value")
6
+ out = REXML::Attribute.new("out:something", "some_other_value")
7
+
8
+ ans.prefix.should == "ns"
9
+ out.prefix.should == "out"
10
+ end
11
+
12
+ it "returns an empty string for Attributes with no prefixes" do
13
+ attr = REXML::Attribute.new("foo", "bar")
14
+
15
+ attr.prefix.should == ""
16
+ end
17
+ end
@@ -0,0 +1,19 @@
1
+ require 'rexml/document'
2
+
3
+ describe "REXML::Attribute#remove" do
4
+ before :each do
5
+ @e = REXML::Element.new "Root"
6
+ @attr = REXML::Attribute.new("foo", "bar")
7
+ end
8
+
9
+ it "deletes this Attribute from parent" do
10
+ @e.add_attribute(@attr)
11
+ @e.attributes["foo"].should_not == nil
12
+ @attr.remove
13
+ @e.attributes["foo"].should == nil
14
+ end
15
+
16
+ it "does not anything if element has no parent" do
17
+ lambda {@attr.remove}.should_not raise_error(Exception)
18
+ end
19
+ end
@@ -0,0 +1,13 @@
1
+ require 'rexml/document'
2
+
3
+ describe "REXML::Attribute#to_s" do
4
+ it "returns the value of the Attribute" do
5
+ REXML::Attribute.new("name", "some_value").to_s.should == "some_value"
6
+ end
7
+
8
+ it "returns the escaped value if it was created from Attribute" do
9
+ orig = REXML::Attribute.new("name", "<&>")
10
+ copy = REXML::Attribute.new(orig)
11
+ copy.to_s.should == "&lt;&amp;&gt;"
12
+ end
13
+ end
@@ -0,0 +1,14 @@
1
+ require 'rexml/document'
2
+
3
+ describe "REXML::Attribute#to_string" do
4
+ it "returns the attribute as XML" do
5
+ attr = REXML::Attribute.new("name", "value")
6
+ attr_empty = REXML::Attribute.new("name")
7
+ attr_ns = REXML::Attribute.new("xmlns:ns", "http://uri")
8
+
9
+ attr.to_string.should == "name='value'"
10
+ attr_empty.to_string.should == "name=''"
11
+ attr_ns.to_string.should == "xmlns:ns='http://uri'"
12
+ end
13
+ end
14
+
@@ -0,0 +1,14 @@
1
+ require 'rexml/document'
2
+
3
+ describe "REXML::Attribute#value" do
4
+ it "returns the value of the Attribute unnormalized" do
5
+ attr = REXML::Attribute.new("name", "value")
6
+ attr_ents = REXML::Attribute.new("name", "<&>")
7
+ attr_empty = REXML::Attribute.new("name")
8
+
9
+ attr.value.should == "value"
10
+ attr_ents.value.should == "<&>"
11
+ attr_empty.value.should == ""
12
+ end
13
+ end
14
+
@@ -0,0 +1,22 @@
1
+ require 'rexml/document'
2
+
3
+ describe "REXML::Attribute#write" do
4
+ before :each do
5
+ @attr = REXML::Attribute.new("name", "Charlotte")
6
+ @s = ""
7
+ end
8
+
9
+ it "writes the name and value to output" do
10
+ @attr.write(@s)
11
+ @s.should == "name='Charlotte'"
12
+ end
13
+
14
+ it "currently ignores the second argument" do
15
+ @attr.write(@s, 3)
16
+ @s.should == "name='Charlotte'"
17
+
18
+ @s = ""
19
+ @attr.write(@s, "foo")
20
+ @s.should == "name='Charlotte'"
21
+ end
22
+ end
@@ -0,0 +1,19 @@
1
+ require 'rexml/document'
2
+
3
+ describe "REXML::Attribute#xpath" do
4
+
5
+ before :each do
6
+ @e = REXML::Element.new "root"
7
+ @attr = REXML::Attribute.new("year", "1989")
8
+ end
9
+
10
+ it "returns the path for Attribute" do
11
+ @e.add_attribute @attr
12
+ @attr.xpath.should == "root/@year"
13
+ end
14
+
15
+ it "raises an error if attribute has no parent" do
16
+ lambda { @attr.xpath }.should raise_error(Exception)
17
+ end
18
+ end
19
+
@@ -0,0 +1,6 @@
1
+ require File.expand_path('../shared/add', __FILE__)
2
+ require 'rexml/document'
3
+
4
+ describe "REXML::Attributes#add" do
5
+ it_behaves_like :rexml_attribute_add, :add
6
+ end
@@ -0,0 +1,6 @@
1
+ require File.expand_path('../shared/add', __FILE__)
2
+ require 'rexml/document'
3
+
4
+ describe "REXML::Attributes#<<" do
5
+ it_behaves_like :rexml_attribute_add, :<<
6
+ end
@@ -0,0 +1,30 @@
1
+ require 'rexml/document'
2
+
3
+ describe "REXML::Attributes#delete_all" do
4
+ before :each do
5
+ @e = REXML::Element.new("root")
6
+ end
7
+
8
+ it "deletes all attributes that match name" do
9
+ uri = REXML::Attribute.new("uri", "http://something")
10
+ @e.attributes << uri
11
+ @e.attributes.delete_all("uri")
12
+ @e.attributes.should be_empty
13
+ @e.attributes["uri"].should == nil
14
+ end
15
+
16
+ it "deletes all attributes that match name with a namespace" do
17
+ ns_uri = REXML::Attribute.new("xmlns:uri", "http://something_here_too")
18
+ @e.attributes << ns_uri
19
+ @e.attributes.delete_all("xmlns:uri")
20
+ @e.attributes.should be_empty
21
+ @e.attributes["xmlns:uri"].should == nil
22
+ end
23
+
24
+ it "returns the removed attribute" do
25
+ uri = REXML::Attribute.new("uri", "http://something_here_too")
26
+ @e.attributes << uri
27
+ attrs = @e.attributes.delete_all("uri")
28
+ attrs.first.should == uri
29
+ end
30
+ end
@@ -0,0 +1,26 @@
1
+ require 'rexml/document'
2
+
3
+ describe "REXML::Attributes#delete" do
4
+ before :each do
5
+ @e = REXML::Element.new("root")
6
+ @name = REXML::Attribute.new("name", "Pepe")
7
+ end
8
+
9
+ it "takes an attribute name and deletes the attribute" do
10
+ @e.attributes.delete("name")
11
+ @e.attributes["name"].should be_nil
12
+ @e.attributes.should be_empty
13
+ end
14
+
15
+ it "takes an Attribute and deletes it" do
16
+ @e.attributes.delete(@name)
17
+ @e.attributes["name"].should be_nil
18
+ @e.attributes.should be_empty
19
+ end
20
+
21
+ it "returns the element with the attribute removed" do
22
+ ret_val = @e.attributes.delete(@name)
23
+ ret_val.should == @e
24
+ ret_val.attributes.should be_empty
25
+ end
26
+ end
@@ -0,0 +1,24 @@
1
+ require 'rexml/document'
2
+
3
+ describe "REXML::Attributes#each_attribute" do
4
+ it "iterates over the attributes yielding actual Attribute objects" do
5
+ e = REXML::Element.new("root")
6
+ name = REXML::Attribute.new("name", "Joe")
7
+ ns_uri = REXML::Attribute.new("xmlns:ns", "http://some_uri")
8
+ e.add_attribute name
9
+ e.add_attribute ns_uri
10
+
11
+ attributes = []
12
+
13
+ e.attributes.each_attribute do |attr|
14
+ attributes << attr
15
+ end
16
+
17
+ attributes = attributes.sort_by {|a| a.name }
18
+ attributes.first.should == name
19
+ attributes.last.should == ns_uri
20
+ end
21
+ end
22
+
23
+
24
+
@@ -0,0 +1,24 @@
1
+ require 'rexml/document'
2
+
3
+ describe "REXML::Attributes#each" do
4
+ before :each do
5
+ @e = REXML::Element.new("root")
6
+ @name = REXML::Attribute.new("name", "Joe")
7
+ @ns_uri = REXML::Attribute.new("xmlns:ns", "http://some_uri")
8
+ @e.add_attribute @name
9
+ @e.add_attribute @ns_uri
10
+ end
11
+
12
+ it "iterates over the attributes yielding expanded-name/value" do
13
+ attributes = []
14
+ @e.attributes.each do |attr|
15
+ attr.should be_kind_of(Array)
16
+ attributes << attr
17
+ end
18
+ attributes = attributes.sort_by {|a| a.first }
19
+ attributes.first.should == ["name", "Joe"]
20
+ attributes.last.should == ["xmlns:ns", "http://some_uri"]
21
+ end
22
+ end
23
+
24
+
@@ -0,0 +1,18 @@
1
+ require 'rexml/document'
2
+
3
+ describe "REXML::Attributes#[]" do
4
+ before :each do
5
+ @e = REXML::Element.new("root")
6
+ @lang = REXML::Attribute.new("language", "english")
7
+ @e.attributes << @lang
8
+ end
9
+
10
+ it "returns the value of an attribute" do
11
+ @e.attributes["language"].should == "english"
12
+ end
13
+
14
+ it "returns nil if the attribute does not exist" do
15
+ @e.attributes["chunky bacon"].should == nil
16
+ end
17
+ end
18
+