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,7 @@
1
+ require 'rexml/document'
2
+
3
+ describe "REXML::Document#node_type" do
4
+ it "returns :document" do
5
+ REXML::Document.new.node_type.should == :document
6
+ end
7
+ end
@@ -0,0 +1,11 @@
1
+ require 'rexml/document'
2
+
3
+ describe "REXML::Document#root" do
4
+ it "returns document root tag name" do
5
+ REXML::Document.new("<foo/>").root.name.should == "foo"
6
+ end
7
+
8
+ it "returns nil if there is not root" do
9
+ REXML::Document.new.root.should == nil
10
+ end
11
+ end
@@ -0,0 +1,18 @@
1
+ require 'rexml/document'
2
+
3
+ describe "REXML::Document#stand_alone?" do
4
+ it "returns the XMLDecl standalone value" do
5
+ d = REXML::Document.new
6
+ decl = REXML::XMLDecl.new("1.0", "UTF-8", "yes")
7
+ d.add decl
8
+ d.stand_alone?.should == "yes"
9
+ end
10
+
11
+ # According to the docs this should return the default XMLDecl but that
12
+ # will carry some more problems when printing the document. Currently, it
13
+ # returns nil. See http://www.ruby-forum.com/topic/146812#650061
14
+ it "returns the default value when no XML declaration present" do
15
+ REXML::Document.new.stand_alone?.should == nil
16
+ end
17
+
18
+ end
@@ -0,0 +1,13 @@
1
+ require 'rexml/document'
2
+
3
+ describe "REXML::Document#version" do
4
+ it "returns XML version from declaration" do
5
+ d = REXML::Document.new
6
+ d.add REXML::XMLDecl.new("1.1")
7
+ d.version.should == "1.1"
8
+ end
9
+
10
+ it "returns the default version when declaration is not present" do
11
+ REXML::Document.new.version.should == REXML::XMLDecl::DEFAULT_VERSION
12
+ end
13
+ end
@@ -0,0 +1,38 @@
1
+ require 'rexml/document'
2
+ require 'rexml/formatters/transitive'
3
+
4
+ # Maybe this can be cleaned
5
+ describe "REXML::Document#write" do
6
+ before :each do
7
+ @d = REXML::Document.new
8
+ city = REXML::Element.new "Springfield"
9
+ street = REXML::Element.new "EvergreenTerrace"
10
+ address = REXML::Element.new "House742"
11
+ @d << city << street << address
12
+ @str = ""
13
+ end
14
+
15
+ it "returns document source as string" do
16
+ @d.write(@str)
17
+ @str.should == "<Springfield><EvergreenTerrace><House742/></EvergreenTerrace></Springfield>"
18
+ end
19
+
20
+ it "returns document indented" do
21
+ @d.write(@str, 2)
22
+ @str.should =~ /\s*<Springfield>\s*<EvergreenTerrace>\s*<House742\/>\s*<\/EvergreenTerrace>\s*<\/Springfield>/
23
+ end
24
+
25
+ # REXML in 1.8 is screwed up:
26
+ # Document#write uses wrong arity for Formatters::Transitive#initialize
27
+ ruby_bug "REXMLTracker#162", "1.8" do
28
+ it "returns document with transitive support" do
29
+ @d.write(@str, 2, true)
30
+ @str.should =~ /\s*<Springfield\s*><EvergreenTerrace\s*><House742\s*\/><\/EvergreenTerrace\s*><\/Springfield\s*>/
31
+ end
32
+ end
33
+
34
+ it "returns document with support for IE" do
35
+ @d.write(@str, -1, false, true)
36
+ @str.should == "<Springfield><EvergreenTerrace><House742 /></EvergreenTerrace></Springfield>"
37
+ end
38
+ end
@@ -0,0 +1,14 @@
1
+ require 'rexml/document'
2
+
3
+ describe "REXML::Document#xml_decl" do
4
+ it "returns XML declaration of the document" do
5
+ d = REXML::Document.new
6
+ decl = REXML::XMLDecl.new("1.0", "UTF-16", "yes")
7
+ d.add decl
8
+ d.xml_decl.should == decl
9
+ end
10
+
11
+ it "returns default XML declaration unless present" do
12
+ REXML::Document.new.xml_decl.should == REXML::XMLDecl.new
13
+ end
14
+ end
@@ -0,0 +1,40 @@
1
+ require 'rexml/document'
2
+
3
+ describe "REXML::Element#add_attribute" do
4
+ before :each do
5
+ @person = REXML::Element.new "person"
6
+ @person.attributes["name"] = "Bill"
7
+ end
8
+
9
+ it "adds a new attribute" do
10
+ @person.add_attribute("age", "17")
11
+ @person.attributes["age"].should == "17"
12
+ end
13
+
14
+ it "overwrites an existing attribute" do
15
+ @person.add_attribute("name", "Bill")
16
+ @person.attributes["name"].should == "Bill"
17
+ end
18
+
19
+ it "accepts a pair of strings" do
20
+ @person.add_attribute("male", "true")
21
+ @person.attributes["male"].should == "true"
22
+ end
23
+
24
+ it "accepts an Attribute for key" do
25
+ attr = REXML::Attribute.new("male", "true")
26
+ @person.add_attribute attr
27
+ @person.attributes["male"].should == "true"
28
+ end
29
+
30
+ it "ignores value if key is an Attribute" do
31
+ attr = REXML::Attribute.new("male", "true")
32
+ @person.add_attribute(attr, "false")
33
+ @person.attributes["male"].should == "true"
34
+ end
35
+
36
+ it "returns the attribute added" do
37
+ attr = REXML::Attribute.new("name", "Tony")
38
+ @person.add_attribute(attr).should == attr
39
+ end
40
+ end
@@ -0,0 +1,21 @@
1
+ require 'rexml/document'
2
+
3
+ describe "REXML::Element#add_attribute" do
4
+ before :each do
5
+ @person = REXML::Element.new "person"
6
+ @person.attributes["name"] = "Bill"
7
+ end
8
+
9
+ it "adds multiple attributes from a hash" do
10
+ @person.add_attributes({"name" => "Joe", "age" => "27"})
11
+ @person.attributes["name"].should == "Joe"
12
+ @person.attributes["age"].should == "27"
13
+ end
14
+
15
+ it "adds multiple attributes from an array" do
16
+ attrs = { "name" => "Joe", "age" => "27"}
17
+ @person.add_attributes attrs.to_a
18
+ @person.attributes["name"].should == "Joe"
19
+ @person.attributes["age"].should == "27"
20
+ end
21
+ end
@@ -0,0 +1,38 @@
1
+ require 'rexml/document'
2
+
3
+
4
+ describe "REXML::Element#add_element" do
5
+ before :each do
6
+ @root = REXML::Element.new("root")
7
+ end
8
+
9
+ it "adds a child without attributes" do
10
+ name = REXML::Element.new("name")
11
+ @root.add_element name
12
+ @root.elements["name"].name.should == name.name
13
+ @root.elements["name"].attributes.should == name.attributes
14
+ @root.elements["name"].context.should == name.context
15
+ end
16
+
17
+ it "adds a child with attributes" do
18
+ person = REXML::Element.new("person")
19
+ @root.add_element(person, {"name" => "Madonna"})
20
+ @root.elements["person"].name.should == person.name
21
+ @root.elements["person"].attributes.should == person.attributes
22
+ @root.elements["person"].context.should == person.context
23
+ end
24
+
25
+ it "adds a child with name" do
26
+ @root.add_element "name"
27
+ @root.elements["name"].name.should == "name"
28
+ @root.elements["name"].attributes.should == {}
29
+ @root.elements["name"].context.should == nil
30
+ end
31
+
32
+ it "returns the added child" do
33
+ name = @root.add_element "name"
34
+ @root.elements["name"].name.should == name.name
35
+ @root.elements["name"].attributes.should == name.attributes
36
+ @root.elements["name"].context.should == name.context
37
+ end
38
+ end
@@ -0,0 +1,23 @@
1
+ require 'rexml/document'
2
+
3
+ describe "REXML::Element#add_namespace" do
4
+ before :each do
5
+ @elem = REXML::Element.new("person")
6
+ end
7
+
8
+ it "adds a namespace to element" do
9
+ @elem.add_namespace("foo", "bar")
10
+ @elem.namespace("foo").should == "bar"
11
+ end
12
+
13
+ it "accepts a prefix string as prefix" do
14
+ @elem.add_namespace("xmlns:foo", "bar")
15
+ @elem.namespace("foo").should == "bar"
16
+ end
17
+
18
+ it "uses prefix as URI if uri is nil" do
19
+ @elem.add_namespace("some_uri", nil)
20
+ @elem.namespace.should == "some_uri"
21
+ end
22
+ end
23
+
@@ -0,0 +1,23 @@
1
+ require 'rexml/document'
2
+
3
+ describe "REXML::Element#add_namespace" do
4
+ before :each do
5
+ @name = REXML::Element.new "Name"
6
+ end
7
+
8
+ it "adds text to an element" do
9
+ @name.add_text "Ringo"
10
+ @name.to_s.should == "<Name>Ringo</Name>"
11
+ end
12
+
13
+ it "accepts a Text" do
14
+ @name.add_text(REXML::Text.new("Ringo"))
15
+ @name.to_s.should == "<Name>Ringo</Name>"
16
+ end
17
+
18
+ it "joins the new text with the old one" do
19
+ @name.add_text "Ringo"
20
+ @name.add_text " Starr"
21
+ @name.to_s.should == "<Name>Ringo Starr</Name>"
22
+ end
23
+ end
@@ -0,0 +1,16 @@
1
+ require 'rexml/document'
2
+
3
+ describe "REXML::Element#attribute" do
4
+ it "returns an attribute by name" do
5
+ person = REXML::Element.new "Person"
6
+ attribute = REXML::Attribute.new("drink", "coffee")
7
+ person.add_attribute(attribute)
8
+ person.attribute("drink").should == attribute
9
+ end
10
+
11
+ it "supports attributes inside namespaces" do
12
+ e = REXML::Element.new("element")
13
+ e.add_attributes({"xmlns:ns" => "http://some_uri"})
14
+ e.attribute("ns", "ns").to_s.should == "http://some_uri"
15
+ end
16
+ end
@@ -0,0 +1,18 @@
1
+ require 'rexml/document'
2
+
3
+ describe "REXML::Element#attributes" do
4
+ it "returns element's Attributes" do
5
+ p = REXML::Element.new "Person"
6
+
7
+ name = REXML::Attribute.new("name", "John")
8
+ attrs = REXML::Attributes.new(p)
9
+ attrs.add name
10
+
11
+ p.add_attribute name
12
+ p.attributes.should == attrs
13
+ end
14
+
15
+ it "returns an empty hash if element has no attributes" do
16
+ REXML::Element.new("Person").attributes.should == {}
17
+ end
18
+ end
@@ -0,0 +1,23 @@
1
+ require 'rexml/document'
2
+
3
+ describe "REXML::Element#cdatas" do
4
+ before :each do
5
+ @e = REXML::Element.new("Root")
6
+ end
7
+
8
+ it "returns the array of children cdatas" do
9
+ c = REXML::CData.new("Primary")
10
+ d = REXML::CData.new("Secondary")
11
+ @e << c
12
+ @e << d
13
+ @e.cdatas.should == [c, d]
14
+ end
15
+
16
+ it "freezes the returned array" do
17
+ @e.cdatas.frozen?.should == true
18
+ end
19
+
20
+ it "returns an empty array if element has no cdata" do
21
+ @e.cdatas.should == []
22
+ end
23
+ end
@@ -0,0 +1,28 @@
1
+ require 'rexml/document'
2
+
3
+ describe "REXML::Element#clone" do
4
+ before :each do
5
+ @e = REXML::Element.new "a"
6
+ end
7
+ it "creates a copy of element" do
8
+ @e.clone.to_s.should == @e.to_s
9
+ end
10
+
11
+ it "copies the attributes" do
12
+ @e.add_attribute("foo", "bar")
13
+ @e.clone.to_s.should == @e.to_s
14
+ end
15
+
16
+ it "does not copy the text" do
17
+ @e.add_text "some text..."
18
+ @e.clone.to_s.should_not == @e
19
+ @e.clone.to_s.should == "<a/>"
20
+ end
21
+
22
+ it "does not copy the child elements" do
23
+ b = REXML::Element.new "b"
24
+ @e << b
25
+ @e.clone.should_not == @e
26
+ @e.clone.to_s.should == "<a/>"
27
+ end
28
+ end
@@ -0,0 +1,20 @@
1
+ require 'rexml/document'
2
+
3
+ describe "REXML::Element#comments" do
4
+ before :each do
5
+ @e = REXML::Element.new "root"
6
+ @c1 = REXML::Comment.new "this is a comment"
7
+ @c2 = REXML::Comment.new "this is another comment"
8
+ @e << @c1
9
+ @e << @c2
10
+ end
11
+
12
+ it "returns the array of comments" do
13
+ @e.comments.should == [@c1, @c2]
14
+ end
15
+
16
+ it "returns a frozen object" do
17
+ comment = REXML::Comment.new "The insertion should fail"
18
+ @e.comments.frozen?.should == true
19
+ end
20
+ end
@@ -0,0 +1,38 @@
1
+ require 'rexml/document'
2
+
3
+ describe "REXML::Element#delete_attribute" do
4
+ before :each do
5
+ @e = REXML::Element.new("Person")
6
+ @attr = REXML::Attribute.new("name", "Sean")
7
+ @e.add_attribute(@attr)
8
+ end
9
+
10
+ it "deletes an attribute from the element" do
11
+ @e.delete_attribute("name")
12
+ @e.attributes["name"].should be_nil
13
+ end
14
+
15
+ # Bug was filled with a patch in Ruby's tracker #20298
16
+ quarantine! do
17
+ it "receives an Attribute" do
18
+ @e.add_attribute(@attr)
19
+ @e.delete_attribute(@attr)
20
+ @e.attributes["name"].should be_nil
21
+ end
22
+ end
23
+
24
+ # Docs say that it returns the removed attribute but then examples
25
+ # show it returns the element with the attribute removed.
26
+ # Also fixed in #20298
27
+ it "returns the element with the attribute removed" do
28
+ elem = @e.delete_attribute("name")
29
+ elem.attributes.should be_empty
30
+ elem.to_s.should eql("<Person/>")
31
+ end
32
+
33
+ it "returns nil if the attribute does not exist" do
34
+ @e.delete_attribute("name")
35
+ at = @e.delete_attribute("name")
36
+ at.should be_nil
37
+ end
38
+ end
@@ -0,0 +1,50 @@
1
+ require 'rexml/document'
2
+
3
+ describe "REXML::Element#delete_element" do
4
+ before :each do
5
+ @root = REXML::Element.new("root")
6
+ end
7
+
8
+ it "deletes the child element" do
9
+ node = REXML::Element.new("some_node")
10
+ @root.add_element node
11
+ @root.delete_element node
12
+ @root.elements.size.should == 0
13
+ end
14
+
15
+ it "deletes a child via XPath" do
16
+ @root.add_element "some_node"
17
+ @root.delete_element "some_node"
18
+ @root.elements.size.should == 0
19
+ end
20
+
21
+ it "deletes the child at index" do
22
+ @root.add_element "some_node"
23
+ @root.delete_element 1
24
+ @root.elements.size.should == 0
25
+ end
26
+
27
+ # According to the docs this should return the deleted element
28
+ # but it won't if it's an Element.
29
+ ruby_bug "REXMLTracker#161", "1.8" do
30
+ it "deletes Element and returns it" do
31
+ node = REXML::Element.new("some_node")
32
+ @root.add_element node
33
+ del_node = @root.delete_element node
34
+ del_node.should == node
35
+ end
36
+ end
37
+
38
+ # Note how passing the string will return the removed element
39
+ # but passing the Element as above won't.
40
+ it "deletes an element and returns it" do
41
+ node = REXML::Element.new("some_node")
42
+ @root.add_element node
43
+ del_node = @root.delete_element "some_node"
44
+ del_node.should == node
45
+ end
46
+
47
+ it "returns nil unless element exists" do
48
+ @root.delete_element("something").should == nil
49
+ end
50
+ end