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,25 @@
1
+ require 'rexml/document'
2
+
3
+ describe "REXML::Attributes#[]=" do
4
+ before :each do
5
+ @e = REXML::Element.new("song")
6
+ @name = REXML::Attribute.new("name", "Holy Smoke!")
7
+ @e.attributes << @name
8
+ end
9
+
10
+ it "sets an attribute" do
11
+ @e.attributes["author"] = "_why's foxes"
12
+ @e.attributes["author"].should == "_why's foxes"
13
+ end
14
+
15
+ it "overwrites an existing attribute" do
16
+ @e.attributes["name"] = "Chunky Bacon"
17
+ @e.attributes["name"].should == "Chunky Bacon"
18
+ end
19
+
20
+ it "deletes an attribute is value is nil" do
21
+ @e.attributes["name"] = nil
22
+ @e.attributes.length.should == 0
23
+ end
24
+ end
25
+
@@ -0,0 +1,13 @@
1
+ require 'rexml/document'
2
+
3
+ describe "REXML::Attributes#get_attribute_ns" do
4
+ it "returns an attribute by name and namespace" do
5
+ e = REXML::Element.new("root")
6
+ attr = REXML::Attribute.new("xmlns:ns", "http://some_url")
7
+ e.attributes << attr
8
+ attr.prefix.should == "xmlns"
9
+ # This might be a bug in Attribute, commenting until those specs
10
+ # are ready
11
+ # e.attributes.get_attribute_ns(attr.prefix, "name").should == "http://some_url"
12
+ end
13
+ end
@@ -0,0 +1,28 @@
1
+ require 'rexml/document'
2
+
3
+ describe "REXML::Attributes#get_attribute" do
4
+ before :each do
5
+ @e = REXML::Element.new("root")
6
+ @name = REXML::Attribute.new("name", "Dave")
7
+ @e.attributes << @name
8
+ end
9
+
10
+ it "fetches an attributes" do
11
+ @e.attributes.get_attribute("name").should == @name
12
+ end
13
+
14
+ it "fetches an namespaced attribute" do
15
+ ns_name = REXML::Attribute.new("im:name", "Murray")
16
+ @e.attributes << ns_name
17
+ @e.attributes.get_attribute("name").should == @name
18
+ @e.attributes.get_attribute("im:name").should == ns_name
19
+ end
20
+
21
+ it "returns an Attribute" do
22
+ @e.attributes.get_attribute("name").should be_kind_of(REXML::Attribute)
23
+ end
24
+
25
+ it "returns nil if it attribute does not exist" do
26
+ @e.attributes.get_attribute("fake").should be_nil
27
+ end
28
+ end
@@ -0,0 +1,18 @@
1
+ require 'rexml/document'
2
+
3
+ describe "REXML::Attributes#initialize" do
4
+ it "is auto initialized by Element" do
5
+ e = REXML::Element.new "root"
6
+ e.attributes.should be_kind_of(REXML::Attributes)
7
+
8
+ e.attributes << REXML::Attribute.new("name", "Paul")
9
+ e.attributes["name"].should == "Paul"
10
+ end
11
+
12
+ it "receives a parent node" do
13
+ e = REXML::Element.new "root"
14
+ a = REXML::Attributes.new(e)
15
+ e.attributes << REXML::Attribute.new("name", "Vic")
16
+ e.attributes["name"].should == "Vic"
17
+ end
18
+ end
@@ -0,0 +1,6 @@
1
+ require File.expand_path('../shared/length', __FILE__)
2
+ require 'rexml/document'
3
+
4
+ describe "REXML::Attributes#length" do
5
+ it_behaves_like :rexml_attribute_length, :length
6
+ end
@@ -0,0 +1,5 @@
1
+ require 'rexml/document'
2
+
3
+ describe "REXML::Attributes#namespaces" do
4
+ it "needs to be reviewed for spec completeness"
5
+ end
@@ -0,0 +1,23 @@
1
+ require 'rexml/document'
2
+
3
+ describe "REXML::Attributes#prefixes" do
4
+ before :each do
5
+ @e = REXML::Element.new("root")
6
+ a1 = REXML::Attribute.new("xmlns:a", "bar")
7
+ a2 = REXML::Attribute.new("xmlns:b", "bla")
8
+ a3 = REXML::Attribute.new("xmlns:c", "baz")
9
+ @e.attributes << a1
10
+ @e.attributes << a2
11
+ @e.attributes << a3
12
+
13
+ @e.attributes << REXML::Attribute.new("xmlns", "foo")
14
+ end
15
+
16
+ it "returns an array with the prefixes of each attribute" do
17
+ @e.attributes.prefixes.sort.should == ["a", "b", "c"]
18
+ end
19
+
20
+ it "does not include the default namespace" do
21
+ @e.attributes.prefixes.include?("xmlns").should == false
22
+ end
23
+ end
@@ -0,0 +1,17 @@
1
+ describe :rexml_attribute_add, :shared => true do
2
+ before :each do
3
+ @e = REXML::Element.new("root")
4
+ @attr = REXML::Attributes.new(@e)
5
+ @name = REXML::Attribute.new("name", "Joe")
6
+ end
7
+
8
+ it "adds an attribute" do
9
+ @attr.send(@method, @name)
10
+ @attr["name"].should == "Joe"
11
+ end
12
+
13
+ it "replaces an existing attribute" do
14
+ @attr.send(@method, REXML::Attribute.new("name", "Bruce"))
15
+ @attr["name"].should == "Bruce"
16
+ end
17
+ end
@@ -0,0 +1,12 @@
1
+ require 'rexml/document'
2
+
3
+ describe :rexml_attribute_length, :shared => true do
4
+ it "returns the number of attributes" do
5
+ e = REXML::Element.new("root")
6
+ e.attributes.send(@method).should == 0
7
+
8
+ e.attributes << REXML::Attribute.new("name", "John")
9
+ e.attributes << REXML::Attribute.new("another_name", "Leo")
10
+ e.attributes.send(@method).should == 2
11
+ end
12
+ end
@@ -0,0 +1,6 @@
1
+ require File.expand_path('../shared/length', __FILE__)
2
+ require 'rexml/document'
3
+
4
+ describe "REXML::Attributes#size" do
5
+ it_behaves_like :rexml_attribute_length, :size
6
+ end
@@ -0,0 +1,20 @@
1
+ require 'rexml/document'
2
+
3
+ describe "REXML::Attributes#to_a" do
4
+ it "returns an array with the attributes" do
5
+ e = REXML::Element.new("root")
6
+ name = REXML::Attribute.new("name", "Dave")
7
+ last = REXML::Attribute.new("last_name", "Murray")
8
+
9
+ e.attributes << name
10
+ e.attributes << last
11
+
12
+ result = e.attributes.to_a.sort { |a, b| a.to_s <=> b.to_s }
13
+ result.should == [name, last]
14
+ end
15
+
16
+ it "returns an empty array if it has no attributes" do
17
+ REXML::Element.new("root").attributes.to_a.should == []
18
+ end
19
+ end
20
+
@@ -0,0 +1,9 @@
1
+ require 'rexml/document'
2
+
3
+ describe "REXML::CData#clone" do
4
+ it "makes a copy of itself" do
5
+ c = REXML::CData.new("some text")
6
+ c.clone.to_s.should == c.to_s
7
+ c.clone.should == c
8
+ end
9
+ end
@@ -0,0 +1,24 @@
1
+ require 'rexml/document'
2
+
3
+ describe "REXML::CData#initialize" do
4
+ it "creates a new CData object" do
5
+ c = REXML::CData.new("some text")
6
+ c = REXML::CData.new("some text")
7
+ c.should be_kind_of(REXML::CData)
8
+ c.should be_kind_of(REXML::Text)
9
+ end
10
+
11
+ it "respects whitespace if whitespace is true" do
12
+ c = REXML::CData.new("whitespace test", true)
13
+ c1 = REXML::CData.new("whitespace test", false)
14
+
15
+ c.to_s.should == "whitespace test"
16
+ c1.to_s.should == "whitespace test"
17
+ end
18
+
19
+ it "receives parent as third argument" do
20
+ e = REXML::Element.new("root")
21
+ c = REXML::CData.new("test", true, e)
22
+ e.to_s.should == "<root><![CDATA[test]]></root>"
23
+ end
24
+ end
@@ -0,0 +1,11 @@
1
+ describe :rexml_cdata_to_s, :shared => true do
2
+ it "returns the contents of the CData" do
3
+ c = REXML::CData.new("some text")
4
+ c.send(@method).should == "some text"
5
+ end
6
+
7
+ it "does not escape text" do
8
+ c1 = REXML::CData.new("some& text\n")
9
+ c1.send(@method).should == "some& text\n"
10
+ end
11
+ end
@@ -0,0 +1,6 @@
1
+ require File.expand_path('../shared/to_s', __FILE__)
2
+ require 'rexml/document'
3
+
4
+ describe "REXML::CData#to_s" do
5
+ it_behaves_like :rexml_cdata_to_s, :to_s
6
+ end
@@ -0,0 +1,6 @@
1
+ require File.expand_path('../shared/to_s', __FILE__)
2
+ require 'rexml/document'
3
+
4
+ describe "REXML::CData#value" do
5
+ it_behaves_like :rexml_cdata_to_s, :value
6
+ end
@@ -0,0 +1,30 @@
1
+ require 'rexml/document'
2
+
3
+ describe "REXML::Document#add_element" do
4
+ it "adds arg1 with attributes arg2 as root node" do
5
+ d = REXML::Document.new
6
+ e = REXML::Element.new("root")
7
+ d.add_element e
8
+ d.root.should == e
9
+ end
10
+
11
+ it "sets arg2 as arg1's attributes" do
12
+ d = REXML::Document.new
13
+ e = REXML::Element.new("root")
14
+ attr = {"foo" => "bar"}
15
+ d.add_element(e,attr)
16
+ d.root.attributes["foo"].should == attr["foo"]
17
+ end
18
+
19
+ it "accepts a node name as arg1 and adds it as root" do
20
+ d = REXML::Document.new
21
+ d.add_element "foo"
22
+ d.root.name.should == "foo"
23
+ end
24
+
25
+ it "sets arg1's context to the root's context" do
26
+ d = REXML::Document.new("", {"foo" => "bar"})
27
+ d.add_element "foo"
28
+ d.root.context.should == d.context
29
+ end
30
+ end
@@ -0,0 +1,60 @@
1
+ require 'rexml/document'
2
+
3
+ # This spec defines Document#add and Document#<<
4
+
5
+ describe :rexml_document_add, :shared => true do
6
+ before :each do
7
+ @doc = REXML::Document.new("<root/>")
8
+ @decl = REXML::XMLDecl.new("1.0")
9
+ end
10
+
11
+ it "sets document's XML declaration" do
12
+ @doc.send(@method, @decl)
13
+ @doc.xml_decl.should == @decl
14
+ end
15
+
16
+ it "inserts XML declaration as first node" do
17
+ @doc.send(@method, @decl)
18
+ @doc.children[0].version.should == "1.0"
19
+ end
20
+
21
+ it "overwrites existing XML declaration" do
22
+ @doc.send(@method, @decl)
23
+ @doc.send(@method, REXML::XMLDecl.new("2.0"))
24
+ @doc.xml_decl.version.should == "2.0"
25
+ end
26
+
27
+ it "sets document DocType" do
28
+ @doc.send(@method, REXML::DocType.new("transitional"))
29
+ @doc.doctype.name.should == "transitional"
30
+ end
31
+
32
+ ruby_bug "#19058", "1.8" do
33
+ # MRI 1.8.x and 1.9 bug. A patch has been submitted.
34
+ # http://rubyforge.org/tracker/index.php?func=detail&aid=19058&group_id=426&atid=1698
35
+ it "overwrites existing DocType" do
36
+ @doc.send(@method, REXML::DocType.new("transitional"))
37
+ @doc.send(@method, REXML::DocType.new("strict"))
38
+ @doc.doctype.name.should == "strict"
39
+ end
40
+ end
41
+
42
+ it "adds root node unless it exists" do
43
+ d = REXML::Document.new("")
44
+ elem = REXML::Element.new "root"
45
+ d.send(@method, elem)
46
+ d.root.should == elem
47
+ end
48
+
49
+ it "refuses to add second root" do
50
+ lambda { @doc.send(@method, REXML::Element.new("foo")) }.should raise_error(RuntimeError)
51
+ end
52
+ end
53
+
54
+ describe "REXML::Document#add" do
55
+ it_behaves_like(:rexml_document_add, :add)
56
+ end
57
+
58
+ describe "REXML::Document#<<" do
59
+ it_behaves_like(:rexml_document_add, :<<)
60
+ end
@@ -0,0 +1,19 @@
1
+ require 'rexml/document'
2
+
3
+ # According to the MRI documentation (http://www.ruby-doc.org/stdlib/libdoc/rexml/rdoc/index.html),
4
+ # clone's behavior "should be obvious". Apparently "obvious" means cloning
5
+ # only the attributes and the context of the document, not its children.
6
+ describe "REXML::Document#clone" do
7
+ it "clones document attributes" do
8
+ d = REXML::Document.new("foo")
9
+ d.attributes["foo"] = "bar"
10
+ e = d.clone
11
+ e.attributes.should == d.attributes
12
+ end
13
+
14
+ it "clones document context" do
15
+ d = REXML::Document.new("foo", {"foo" => "bar"})
16
+ e = d.clone
17
+ e.context.should == d.context
18
+ end
19
+ end
@@ -0,0 +1,14 @@
1
+ require 'rexml/document'
2
+
3
+ describe "REXML::Document#doctype" do
4
+ it "returns the doctype" do
5
+ d = REXML::Document.new
6
+ dt = REXML::DocType.new("foo")
7
+ d.add dt
8
+ d.doctype.should == dt
9
+ end
10
+
11
+ it "returns nil if there's no doctype" do
12
+ REXML::Document.new.doctype.should == nil
13
+ end
14
+ end
@@ -0,0 +1,21 @@
1
+ require 'rexml/document'
2
+
3
+ describe "REXML::Document#encoding" do
4
+ before :each do
5
+ @doc = REXML::Document.new
6
+ end
7
+
8
+ it "returns encoding from XML declaration" do
9
+ @doc.add REXML::XMLDecl.new(nil, "UTF-16", nil)
10
+ @doc.encoding.should == "UTF-16"
11
+ end
12
+
13
+ it "returns encoding from XML declaration (for UTF-16 as well)" do
14
+ @doc.add REXML::XMLDecl.new("1.0", "UTF-8", nil)
15
+ @doc.encoding.should == "UTF-8"
16
+ end
17
+
18
+ it "uses UTF-8 as default encoding" do
19
+ @doc.encoding.should == "UTF-8"
20
+ end
21
+ end
@@ -0,0 +1,15 @@
1
+ require 'rexml/document'
2
+
3
+ describe :document_expanded_name, :shared => true do
4
+ it "returns an empty string for root" do # root nodes have no expanded name
5
+ REXML::Document.new.send(@method).should == ""
6
+ end
7
+ end
8
+
9
+ describe "REXML::Document#expanded_name" do
10
+ it_behaves_like(:document_expanded_name, :expanded_name)
11
+ end
12
+
13
+ describe "REXML::Document#name" do
14
+ it_behaves_like(:document_expanded_name, :name)
15
+ end
@@ -0,0 +1,37 @@
1
+ require 'rexml/document'
2
+
3
+ describe "REXML::Document#new" do
4
+
5
+ it "initializes context of {} unless specified" do
6
+ d = REXML::Document.new("<foo />")
7
+ d.context.should == {}
8
+ end
9
+
10
+ it "has empty attributes if source is nil" do
11
+ d = REXML::Document.new(nil)
12
+ d.elements.should be_empty
13
+ end
14
+
15
+ it "can use other document context" do
16
+ s = REXML::Document.new("")
17
+ d = REXML::Document.new(s)
18
+ d.context.should == s.context
19
+ end
20
+
21
+ it "clones source attributes" do
22
+ s = REXML::Document.new("<root />")
23
+ s.attributes["some_attr"] = "some_val"
24
+ d = REXML::Document.new(s)
25
+ d.attributes.should == s.attributes
26
+ end
27
+
28
+ ruby_bug "#", "1.8.6.111" do
29
+ it "raises an error if source is not a Document, String or IO" do
30
+ lambda {s = REXML::Document.new(3)}.should raise_error(RuntimeError)
31
+ end
32
+ end
33
+
34
+ it "does not perform XML validation" do
35
+ REXML::Document.new("Invalid document").should be_kind_of(REXML::Document)
36
+ end
37
+ end