rubysl-rexml 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/.travis.yml +8 -0
- data/Gemfile +4 -0
- data/LICENSE +25 -0
- data/README.md +29 -0
- data/Rakefile +1 -0
- data/lib/rexml/attlistdecl.rb +62 -0
- data/lib/rexml/attribute.rb +185 -0
- data/lib/rexml/cdata.rb +67 -0
- data/lib/rexml/child.rb +96 -0
- data/lib/rexml/comment.rb +80 -0
- data/lib/rexml/doctype.rb +271 -0
- data/lib/rexml/document.rb +230 -0
- data/lib/rexml/dtd/attlistdecl.rb +10 -0
- data/lib/rexml/dtd/dtd.rb +51 -0
- data/lib/rexml/dtd/elementdecl.rb +17 -0
- data/lib/rexml/dtd/entitydecl.rb +56 -0
- data/lib/rexml/dtd/notationdecl.rb +39 -0
- data/lib/rexml/element.rb +1227 -0
- data/lib/rexml/encoding.rb +71 -0
- data/lib/rexml/encodings/CP-1252.rb +103 -0
- data/lib/rexml/encodings/EUC-JP.rb +35 -0
- data/lib/rexml/encodings/ICONV.rb +22 -0
- data/lib/rexml/encodings/ISO-8859-1.rb +7 -0
- data/lib/rexml/encodings/ISO-8859-15.rb +72 -0
- data/lib/rexml/encodings/SHIFT-JIS.rb +37 -0
- data/lib/rexml/encodings/SHIFT_JIS.rb +1 -0
- data/lib/rexml/encodings/UNILE.rb +34 -0
- data/lib/rexml/encodings/US-ASCII.rb +30 -0
- data/lib/rexml/encodings/UTF-16.rb +35 -0
- data/lib/rexml/encodings/UTF-8.rb +18 -0
- data/lib/rexml/entity.rb +166 -0
- data/lib/rexml/formatters/default.rb +109 -0
- data/lib/rexml/formatters/pretty.rb +138 -0
- data/lib/rexml/formatters/transitive.rb +56 -0
- data/lib/rexml/functions.rb +382 -0
- data/lib/rexml/instruction.rb +70 -0
- data/lib/rexml/light/node.rb +196 -0
- data/lib/rexml/namespace.rb +47 -0
- data/lib/rexml/node.rb +75 -0
- data/lib/rexml/output.rb +24 -0
- data/lib/rexml/parent.rb +166 -0
- data/lib/rexml/parseexception.rb +51 -0
- data/lib/rexml/parsers/baseparser.rb +503 -0
- data/lib/rexml/parsers/lightparser.rb +60 -0
- data/lib/rexml/parsers/pullparser.rb +196 -0
- data/lib/rexml/parsers/sax2parser.rb +238 -0
- data/lib/rexml/parsers/streamparser.rb +46 -0
- data/lib/rexml/parsers/treeparser.rb +97 -0
- data/lib/rexml/parsers/ultralightparser.rb +56 -0
- data/lib/rexml/parsers/xpathparser.rb +698 -0
- data/lib/rexml/quickpath.rb +266 -0
- data/lib/rexml/rexml.rb +32 -0
- data/lib/rexml/sax2listener.rb +97 -0
- data/lib/rexml/source.rb +251 -0
- data/lib/rexml/streamlistener.rb +92 -0
- data/lib/rexml/syncenumerator.rb +33 -0
- data/lib/rexml/text.rb +344 -0
- data/lib/rexml/undefinednamespaceexception.rb +8 -0
- data/lib/rexml/validation/relaxng.rb +559 -0
- data/lib/rexml/validation/validation.rb +155 -0
- data/lib/rexml/validation/validationexception.rb +9 -0
- data/lib/rexml/xmldecl.rb +119 -0
- data/lib/rexml/xmltokens.rb +18 -0
- data/lib/rexml/xpath.rb +66 -0
- data/lib/rexml/xpath_parser.rb +792 -0
- data/lib/rubysl/rexml.rb +1 -0
- data/lib/rubysl/rexml/version.rb +5 -0
- data/rubysl-rexml.gemspec +23 -0
- data/spec/attribute/clone_spec.rb +10 -0
- data/spec/attribute/element_spec.rb +22 -0
- data/spec/attribute/equal_value_spec.rb +17 -0
- data/spec/attribute/hash_spec.rb +12 -0
- data/spec/attribute/initialize_spec.rb +28 -0
- data/spec/attribute/inspect_spec.rb +19 -0
- data/spec/attribute/namespace_spec.rb +23 -0
- data/spec/attribute/node_type_spec.rb +9 -0
- data/spec/attribute/prefix_spec.rb +17 -0
- data/spec/attribute/remove_spec.rb +19 -0
- data/spec/attribute/to_s_spec.rb +13 -0
- data/spec/attribute/to_string_spec.rb +14 -0
- data/spec/attribute/value_spec.rb +14 -0
- data/spec/attribute/write_spec.rb +22 -0
- data/spec/attribute/xpath_spec.rb +19 -0
- data/spec/attributes/add_spec.rb +6 -0
- data/spec/attributes/append_spec.rb +6 -0
- data/spec/attributes/delete_all_spec.rb +30 -0
- data/spec/attributes/delete_spec.rb +26 -0
- data/spec/attributes/each_attribute_spec.rb +24 -0
- data/spec/attributes/each_spec.rb +24 -0
- data/spec/attributes/element_reference_spec.rb +18 -0
- data/spec/attributes/element_set_spec.rb +25 -0
- data/spec/attributes/get_attribute_ns_spec.rb +13 -0
- data/spec/attributes/get_attribute_spec.rb +28 -0
- data/spec/attributes/initialize_spec.rb +18 -0
- data/spec/attributes/length_spec.rb +6 -0
- data/spec/attributes/namespaces_spec.rb +5 -0
- data/spec/attributes/prefixes_spec.rb +23 -0
- data/spec/attributes/shared/add.rb +17 -0
- data/spec/attributes/shared/length.rb +12 -0
- data/spec/attributes/size_spec.rb +6 -0
- data/spec/attributes/to_a_spec.rb +20 -0
- data/spec/cdata/clone_spec.rb +9 -0
- data/spec/cdata/initialize_spec.rb +24 -0
- data/spec/cdata/shared/to_s.rb +11 -0
- data/spec/cdata/to_s_spec.rb +6 -0
- data/spec/cdata/value_spec.rb +6 -0
- data/spec/document/add_element_spec.rb +30 -0
- data/spec/document/add_spec.rb +60 -0
- data/spec/document/clone_spec.rb +19 -0
- data/spec/document/doctype_spec.rb +14 -0
- data/spec/document/encoding_spec.rb +21 -0
- data/spec/document/expanded_name_spec.rb +15 -0
- data/spec/document/new_spec.rb +37 -0
- data/spec/document/node_type_spec.rb +7 -0
- data/spec/document/root_spec.rb +11 -0
- data/spec/document/stand_alone_spec.rb +18 -0
- data/spec/document/version_spec.rb +13 -0
- data/spec/document/write_spec.rb +38 -0
- data/spec/document/xml_decl_spec.rb +14 -0
- data/spec/element/add_attribute_spec.rb +40 -0
- data/spec/element/add_attributes_spec.rb +21 -0
- data/spec/element/add_element_spec.rb +38 -0
- data/spec/element/add_namespace_spec.rb +23 -0
- data/spec/element/add_text_spec.rb +23 -0
- data/spec/element/attribute_spec.rb +16 -0
- data/spec/element/attributes_spec.rb +18 -0
- data/spec/element/cdatas_spec.rb +23 -0
- data/spec/element/clone_spec.rb +28 -0
- data/spec/element/comments_spec.rb +20 -0
- data/spec/element/delete_attribute_spec.rb +38 -0
- data/spec/element/delete_element_spec.rb +50 -0
- data/spec/element/delete_namespace_spec.rb +24 -0
- data/spec/element/document_spec.rb +17 -0
- data/spec/element/each_element_with_attribute_spec.rb +34 -0
- data/spec/element/each_element_with_text_spec.rb +30 -0
- data/spec/element/get_text_spec.rb +17 -0
- data/spec/element/has_attributes_spec.rb +16 -0
- data/spec/element/has_elements_spec.rb +17 -0
- data/spec/element/has_text_spec.rb +15 -0
- data/spec/element/inspect_spec.rb +26 -0
- data/spec/element/instructions_spec.rb +20 -0
- data/spec/element/namespace_spec.rb +26 -0
- data/spec/element/namespaces_spec.rb +31 -0
- data/spec/element/new_spec.rb +34 -0
- data/spec/element/next_element_spec.rb +18 -0
- data/spec/element/node_type_spec.rb +7 -0
- data/spec/element/prefixes_spec.rb +22 -0
- data/spec/element/previous_element_spec.rb +19 -0
- data/spec/element/raw_spec.rb +23 -0
- data/spec/element/root_spec.rb +27 -0
- data/spec/element/text_spec.rb +45 -0
- data/spec/element/texts_spec.rb +15 -0
- data/spec/element/whitespace_spec.rb +22 -0
- data/spec/node/each_recursive_spec.rb +20 -0
- data/spec/node/find_first_recursive_spec.rb +24 -0
- data/spec/node/index_in_parent_spec.rb +14 -0
- data/spec/node/next_sibling_node_spec.rb +20 -0
- data/spec/node/parent_spec.rb +20 -0
- data/spec/node/previous_sibling_node_spec.rb +20 -0
- data/spec/shared/each_element.rb +35 -0
- data/spec/shared/elements_to_a.rb +35 -0
- data/spec/text/append_spec.rb +9 -0
- data/spec/text/clone_spec.rb +9 -0
- data/spec/text/comparison_spec.rb +24 -0
- data/spec/text/empty_spec.rb +11 -0
- data/spec/text/indent_text_spec.rb +23 -0
- data/spec/text/inspect_spec.rb +7 -0
- data/spec/text/new_spec.rb +48 -0
- data/spec/text/node_type_spec.rb +7 -0
- data/spec/text/normalize_spec.rb +7 -0
- data/spec/text/read_with_substitution_spec.rb +12 -0
- data/spec/text/to_s_spec.rb +17 -0
- data/spec/text/unnormalize_spec.rb +7 -0
- data/spec/text/value_spec.rb +36 -0
- data/spec/text/wrap_spec.rb +20 -0
- data/spec/text/write_with_substitution_spec.rb +32 -0
- 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,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,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,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,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
|