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,45 @@
1
+ require 'rexml/document'
2
+
3
+ describe "REXML::Element#text" do
4
+ before :each do
5
+ @e = REXML::Element.new "name"
6
+ @e.text = "John"
7
+ end
8
+
9
+ it "returns the text node of element" do
10
+ @e.text.should == "John"
11
+ end
12
+
13
+ it "returns the text node value" do
14
+ t = REXML::Text.new "Joe"
15
+ @e.text = t
16
+ @e.text.should == "Joe"
17
+ @e.text.should_not == t
18
+ end
19
+
20
+ it "returns nil if no text is attached" do
21
+ elem = REXML::Element.new "name"
22
+ elem.text.should == nil
23
+ end
24
+ end
25
+
26
+ describe "REXML::Element#text=" do
27
+ before :each do
28
+ @e = REXML::Element.new "name"
29
+ @e.text = "John"
30
+ end
31
+
32
+ it "sets the text node" do
33
+ @e.to_s.should == "<name>John</name>"
34
+ end
35
+
36
+ it "replaces existing text" do
37
+ @e.text = "Joe"
38
+ @e.to_s.should == "<name>Joe</name>"
39
+ end
40
+
41
+ it "receives nil as an argument" do
42
+ @e.text = nil
43
+ @e.to_s.should == "<name/>"
44
+ end
45
+ end
@@ -0,0 +1,15 @@
1
+ require 'rexml/document'
2
+
3
+ describe "REXML::Element#texts" do
4
+
5
+ it "returns an array of the Text children" do
6
+ e = REXML::Element.new("root")
7
+ e.add_text "First"
8
+ e.add_text "Second"
9
+ e.texts.should == ["FirstSecond"]
10
+ end
11
+
12
+ it "returns an empty array if it has no Text children" do
13
+ REXML::Element.new("root").texts.should == []
14
+ end
15
+ end
@@ -0,0 +1,22 @@
1
+ require 'rexml/document'
2
+
3
+ describe "REXML::Element#whitespace" do
4
+ it "returns true if whitespace is respected in the element" do
5
+ e = REXML::Element.new("root")
6
+ e.whitespace.should be_true
7
+
8
+ e = REXML::Element.new("root", nil, :respect_whitespace => :all)
9
+ e.whitespace.should be_true
10
+
11
+ e = REXML::Element.new("root", nil, :respect_whitespace => ["root"])
12
+ e.whitespace.should be_true
13
+ end
14
+
15
+ it "returns false if whitespace is ignored inside element" do
16
+ e = REXML::Element.new("root", nil, :compress_whitespace => :all)
17
+ e.whitespace.should be_false
18
+
19
+ e = REXML::Element.new("root", nil, :compress_whitespace => ["root"])
20
+ e.whitespace.should be_false
21
+ end
22
+ end
@@ -0,0 +1,20 @@
1
+ require 'rexml/document'
2
+
3
+ describe "REXML::Node#each_recursive" do
4
+ before :each do
5
+ @doc = REXML::Document.new
6
+ @doc << REXML::XMLDecl.new
7
+ @root = REXML::Element.new "root"
8
+ @child1 = REXML::Element.new "child1"
9
+ @child2 = REXML::Element.new "child2"
10
+ @root << @child1
11
+ @root << @child2
12
+ @doc << @root
13
+ end
14
+
15
+ it "visits all subnodes of self" do
16
+ nodes = []
17
+ @doc.each_recursive { |node| nodes << node}
18
+ nodes.should == [@root, @child1, @child2]
19
+ end
20
+ end
@@ -0,0 +1,24 @@
1
+ require 'rexml/document'
2
+
3
+ describe "REXML::Node#find_first_recursive" do
4
+ before :each do
5
+ @e = REXML::Element.new("root")
6
+ @node1 = REXML::Element.new("node")
7
+ @node2 = REXML::Element.new("another node")
8
+ @subnode = REXML::Element.new("another node")
9
+ @node1 << @subnode
10
+ @e << @node1
11
+ @e << @node2
12
+ end
13
+
14
+ it "finds the first element that matches block" do
15
+ found = @e.find_first_recursive { |n| n.to_s == "<node><another node/></node>"}
16
+ found.should == @node1
17
+ end
18
+
19
+ it "visits the nodes in preorder" do
20
+ found = @e.find_first_recursive { |n| n.to_s == "<another node/>"}
21
+ found.should == @subnode
22
+ found.should_not == @node2
23
+ end
24
+ end
@@ -0,0 +1,14 @@
1
+ require 'rexml/document'
2
+
3
+ describe "REXML::Node#index_in_parent" do
4
+ it "returns the index (starting from 1) of self in parent" do
5
+ e = REXML::Element.new("root")
6
+ node1 = REXML::Element.new("node")
7
+ node2 = REXML::Element.new("another node")
8
+ e << node1
9
+ e << node2
10
+
11
+ node1.index_in_parent.should == 1
12
+ node2.index_in_parent.should == 2
13
+ end
14
+ end
@@ -0,0 +1,20 @@
1
+ require 'rexml/document'
2
+
3
+ describe "REXML::Node#next_sibling_node" do
4
+ before :each do
5
+ @e = REXML::Element.new("root")
6
+ @node1 = REXML::Element.new("node")
7
+ @node2 = REXML::Element.new("another node")
8
+ @e << @node1
9
+ @e << @node2
10
+ end
11
+
12
+ it "returns the next child node in parent" do
13
+ @node1.next_sibling_node.should == @node2
14
+ end
15
+
16
+ it "returns nil if there are no more child nodes next" do
17
+ @node2.next_sibling_node.should == nil
18
+ @e.next_sibling_node.should == nil
19
+ end
20
+ end
@@ -0,0 +1,20 @@
1
+ require 'rexml/document'
2
+
3
+ describe "REXML::Node#parent?" do
4
+ it "returns true for Elements" do
5
+ e = REXML::Element.new("foo")
6
+ e.parent?.should == true
7
+ end
8
+
9
+ it "returns true for Documents" do
10
+ e = REXML::Document.new
11
+ e.parent?.should == true
12
+ end
13
+
14
+ # This includes attributes, CDatas and declarations.
15
+ it "returns false for Texts" do
16
+ e = REXML::Text.new("foo")
17
+ e.parent?.should == false
18
+ end
19
+ end
20
+
@@ -0,0 +1,20 @@
1
+ require 'rexml/document'
2
+
3
+ describe "REXML::Node#previous_sibling_node" do
4
+ before :each do
5
+ @e = REXML::Element.new("root")
6
+ @node1 = REXML::Element.new("node")
7
+ @node2 = REXML::Element.new("another node")
8
+ @e << @node1
9
+ @e << @node2
10
+ end
11
+
12
+ it "returns the previous child node in parent" do
13
+ @node2.previous_sibling_node.should == @node1
14
+ end
15
+
16
+ it "returns nil if there are no more child nodes before" do
17
+ @node1.previous_sibling_node.should == nil
18
+ @e.previous_sibling_node.should == nil
19
+ end
20
+ end
@@ -0,0 +1,35 @@
1
+ require 'rexml/document'
2
+
3
+ describe :rexml_each_element, :shared => true do
4
+ before :each do
5
+ @e = REXML::Element.new "root"
6
+ s1 = REXML::Element.new "node1"
7
+ s2 = REXML::Element.new "node2"
8
+ s3 = REXML::Element.new "node3"
9
+ s4 = REXML::Element.new "sub_node"
10
+ @e << s1
11
+ @e << s2
12
+ @e << s3
13
+ @e << s4
14
+ end
15
+
16
+ it "iterates through element" do
17
+ str = ""
18
+ @e.send(@method) { |elem| str << elem.name << " " }
19
+ str.should == "node1 node2 node3 sub_node "
20
+ end
21
+
22
+ it "iterates through element filtering with XPath" do
23
+ str = ""
24
+ @e.send(@method, "/*"){ |e| str << e.name << " "}
25
+ str.should == "node1 node2 node3 sub_node "
26
+ end
27
+ end
28
+
29
+ describe "REXML::Element#each_element" do
30
+ it_behaves_like :rexml_each_element, :each_element
31
+ end
32
+
33
+ describe "REXML::Elements#each" do
34
+ it_behaves_like :rexml_each_element, :each
35
+ end
@@ -0,0 +1,35 @@
1
+ require 'rexml/document'
2
+
3
+ describe :rexml_elements_to_a, :shared => true do
4
+ before :each do
5
+ @e = REXML::Element.new "root"
6
+ @first = REXML::Element.new("FirstChild")
7
+ @second = REXML::Element.new("SecondChild")
8
+ @e << @first
9
+ @e << @second
10
+ end
11
+
12
+ it "returns elements that match xpath" do
13
+ @e.elements.send(@method, "FirstChild").first.should == @first
14
+ end
15
+
16
+ # According to the docs REXML::Element#get_elements is an alias for
17
+ # REXML::Elements.to_a. Implementation wise there's a difference, get_elements
18
+ # always needs the first param (even if it's nil).
19
+ # A patch was submitted:
20
+ # http://rubyforge.org/tracker/index.php?func=detail&aid=19354&group_id=426&atid=1698
21
+ ruby_bug "#", "1.8.6.114" do
22
+ it "returns all childs if xpath is nil" do
23
+ @e.elements.send(@method).should == [@first, @second]
24
+ end
25
+ end
26
+
27
+ end
28
+
29
+ describe "REXML::REXML::Elements#to_a" do
30
+ it_behaves_like :rexml_elements_to_a, :to_a
31
+ end
32
+
33
+ describe "REXML::REXML::Element#get_elements" do
34
+ it_behaves_like :rexml_elements_to_a, :get_elements
35
+ end
@@ -0,0 +1,9 @@
1
+ require 'rexml/document'
2
+
3
+ describe "REXML::Text#<<" do
4
+ it "appends a string to this text node" do
5
+ text = REXML::Text.new("foo")
6
+ text << "bar"
7
+ text.should == "foobar"
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ require 'rexml/document'
2
+
3
+ describe "REXML::Text#clone" do
4
+ it "creates a copy of this node" do
5
+ text = REXML::Text.new("foo")
6
+ text.clone.should == "foo"
7
+ text.clone.should == text
8
+ end
9
+ end
@@ -0,0 +1,24 @@
1
+ require 'rexml/document'
2
+
3
+ describe "REXML::Text#<=>" do
4
+ before :each do
5
+ @first = REXML::Text.new("abc")
6
+ @last = REXML::Text.new("def")
7
+ end
8
+
9
+ it "returns -1 if lvalue is less than rvalue" do
10
+ val = @first <=> @last
11
+ val.should == -1
12
+ end
13
+
14
+ it "returns -1 if lvalue is greater than rvalue" do
15
+ val = @last <=> @first
16
+ val.should == 1
17
+ end
18
+
19
+ it "returns 0 if both values are equal" do
20
+ tmp = REXML::Text.new("tmp")
21
+ val = tmp <=> tmp
22
+ val.should == 0
23
+ end
24
+ end
@@ -0,0 +1,11 @@
1
+ require 'rexml/document'
2
+
3
+ describe "REXML::Text#empty?" do
4
+ it "returns true if the text is empty" do
5
+ REXML::Text.new("").empty?.should == true
6
+ end
7
+
8
+ it "returns false if the text is not empty" do
9
+ REXML::Text.new("some_text").empty?.should == false
10
+ end
11
+ end
@@ -0,0 +1,23 @@
1
+ require 'rexml/document'
2
+
3
+ describe "REXML::Text#indent_text" do
4
+ before :each do
5
+ @t = REXML::Text.new("")
6
+ end
7
+ it "indents a string with default parameters" do
8
+ @t.indent_text("foo").should == "\tfoo"
9
+ end
10
+
11
+ it "accepts a custom indentation level as second argument" do
12
+ @t.indent_text("foo", 2, "\t", true).should == "\t\tfoo"
13
+ end
14
+
15
+ it "accepts a custom separator as third argument" do
16
+ @t.indent_text("foo", 1, "\n", true).should == "\nfoo"
17
+ end
18
+
19
+ it "accepts a fourth parameter to skip the first line" do
20
+ @t.indent_text("foo", 1, "\t", false).should == "foo"
21
+ end
22
+ end
23
+
@@ -0,0 +1,7 @@
1
+ require 'rexml/document'
2
+
3
+ describe "REXML::Text#inspect" do
4
+ it "inspects the string attribute as a string" do
5
+ REXML::Text.new("a text").inspect.should == "a text".inspect
6
+ end
7
+ end
@@ -0,0 +1,48 @@
1
+ require 'rexml/document'
2
+
3
+ describe "REXML::Text.new" do
4
+
5
+ it "creates a Text child node with no parent" do
6
+ t = REXML::Text.new("test")
7
+ t.should be_kind_of(REXML::Child)
8
+ t.should == "test"
9
+ t.parent.should == nil
10
+ end
11
+
12
+ it "respects whitespace if second argument is true" do
13
+ t = REXML::Text.new("testing whitespace", true)
14
+ t.should == "testing whitespace"
15
+ t = REXML::Text.new(" ", true)
16
+ t.should == " "
17
+ end
18
+
19
+ it "receives a parent as third argument" do
20
+ e = REXML::Element.new("root")
21
+ t = REXML::Text.new("test", false, e)
22
+ t.parent.should == e
23
+ e.to_s.should == "<root>test</root>"
24
+ end
25
+
26
+ it "expects escaped text if raw is true" do
27
+ t = REXML::Text.new("&lt;&amp;&gt;", false, nil, true)
28
+ t.should == "&lt;&amp;&gt;"
29
+
30
+ lambda{ REXML::Text.new("<&>", false, nil, true)}.should raise_error(Exception)
31
+ end
32
+
33
+ it "uses raw value of the parent if raw is nil" do
34
+ e1 = REXML::Element.new("root", nil, { :raw => :all})
35
+ lambda {REXML::Text.new("<&>", false, e1)}.should raise_error(Exception)
36
+
37
+ e2 = REXML::Element.new("root", nil, { :raw => []})
38
+ e2.raw.should be_false
39
+ t1 = REXML::Text.new("<&>", false, e2)
40
+ t1.should == "&lt;&amp;&gt;"
41
+ end
42
+
43
+ it "escapes the values if raw is false" do
44
+ t = REXML::Text.new("<&>", false, nil, false)
45
+ t.should == "&lt;&amp;&gt;"
46
+ end
47
+ end
48
+
@@ -0,0 +1,7 @@
1
+ require 'rexml/document'
2
+
3
+ describe "REXML::Text#node_type" do
4
+ it "returns :text" do
5
+ REXML::Text.new("test").node_type.should == :text
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ require 'rexml/document'
2
+
3
+ describe "REXML::Text.normalize" do
4
+ it "escapes a string with <, >, &, ' and \" " do
5
+ REXML::Text.normalize("< > & \" '").should == "&lt; &gt; &amp; &quot; &apos;"
6
+ end
7
+ end