From a3736e97a6ca517c2cd7d3d93a8f2ef86e39e5b5 Mon Sep 17 00:00:00 2001 From: eregon Date: Sun, 7 May 2017 12:04:49 +0000 Subject: Add in-tree mspec and ruby/spec * For easier modifications of ruby/spec by MRI developers. * .gitignore: track changes under spec. * spec/mspec, spec/rubyspec: add in-tree mspec and ruby/spec. These files can therefore be updated like any other file in MRI. Instructions are provided in spec/README. [Feature #13156] [ruby-core:79246] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58595 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- .../rubyspec/library/rexml/attribute/clone_spec.rb | 11 ++++++++ .../library/rexml/attribute/element_spec.rb | 23 +++++++++++++++++ .../library/rexml/attribute/equal_value_spec.rb | 18 ++++++++++++++ spec/rubyspec/library/rexml/attribute/hash_spec.rb | 13 ++++++++++ .../library/rexml/attribute/initialize_spec.rb | 29 ++++++++++++++++++++++ .../library/rexml/attribute/inspect_spec.rb | 20 +++++++++++++++ .../library/rexml/attribute/namespace_spec.rb | 24 ++++++++++++++++++ .../library/rexml/attribute/node_type_spec.rb | 10 ++++++++ .../library/rexml/attribute/prefix_spec.rb | 18 ++++++++++++++ .../library/rexml/attribute/remove_spec.rb | 20 +++++++++++++++ spec/rubyspec/library/rexml/attribute/to_s_spec.rb | 14 +++++++++++ .../library/rexml/attribute/to_string_spec.rb | 15 +++++++++++ .../rubyspec/library/rexml/attribute/value_spec.rb | 15 +++++++++++ .../rubyspec/library/rexml/attribute/write_spec.rb | 23 +++++++++++++++++ .../rubyspec/library/rexml/attribute/xpath_spec.rb | 20 +++++++++++++++ 15 files changed, 273 insertions(+) create mode 100644 spec/rubyspec/library/rexml/attribute/clone_spec.rb create mode 100644 spec/rubyspec/library/rexml/attribute/element_spec.rb create mode 100644 spec/rubyspec/library/rexml/attribute/equal_value_spec.rb create mode 100644 spec/rubyspec/library/rexml/attribute/hash_spec.rb create mode 100644 spec/rubyspec/library/rexml/attribute/initialize_spec.rb create mode 100644 spec/rubyspec/library/rexml/attribute/inspect_spec.rb create mode 100644 spec/rubyspec/library/rexml/attribute/namespace_spec.rb create mode 100644 spec/rubyspec/library/rexml/attribute/node_type_spec.rb create mode 100644 spec/rubyspec/library/rexml/attribute/prefix_spec.rb create mode 100644 spec/rubyspec/library/rexml/attribute/remove_spec.rb create mode 100644 spec/rubyspec/library/rexml/attribute/to_s_spec.rb create mode 100644 spec/rubyspec/library/rexml/attribute/to_string_spec.rb create mode 100644 spec/rubyspec/library/rexml/attribute/value_spec.rb create mode 100644 spec/rubyspec/library/rexml/attribute/write_spec.rb create mode 100644 spec/rubyspec/library/rexml/attribute/xpath_spec.rb (limited to 'spec/rubyspec/library/rexml/attribute') diff --git a/spec/rubyspec/library/rexml/attribute/clone_spec.rb b/spec/rubyspec/library/rexml/attribute/clone_spec.rb new file mode 100644 index 0000000000..df0d9ca466 --- /dev/null +++ b/spec/rubyspec/library/rexml/attribute/clone_spec.rb @@ -0,0 +1,11 @@ +require File.expand_path('../../../../spec_helper', __FILE__) +require 'rexml/document' + +describe "REXML::Attribute#clone" do + it "returns a copy of this Attribute" do + orig = REXML::Attribute.new("name", "value&&") + orig.should == orig.clone + orig.clone.to_s.should == orig.to_s + orig.clone.to_string.should == orig.to_string + end +end diff --git a/spec/rubyspec/library/rexml/attribute/element_spec.rb b/spec/rubyspec/library/rexml/attribute/element_spec.rb new file mode 100644 index 0000000000..c518bb7b55 --- /dev/null +++ b/spec/rubyspec/library/rexml/attribute/element_spec.rb @@ -0,0 +1,23 @@ +require File.expand_path('../../../../spec_helper', __FILE__) +require 'rexml/document' + +describe "REXML::Attribute#element" do + it "returns the parent element" do + e = REXML::Element.new "root" + + REXML::Attribute.new("name", "value", e).element.should == e + REXML::Attribute.new("name", "default_constructor").element.should == nil + end +end + +describe "REXML::Attribute#element=" do + it "sets the parent element" do + e = REXML::Element.new "root" + f = REXML::Element.new "temp" + a = REXML::Attribute.new("name", "value", e) + a.element.should == e + + a.element = f + a.element.should == f + end +end diff --git a/spec/rubyspec/library/rexml/attribute/equal_value_spec.rb b/spec/rubyspec/library/rexml/attribute/equal_value_spec.rb new file mode 100644 index 0000000000..2a7aa9e87e --- /dev/null +++ b/spec/rubyspec/library/rexml/attribute/equal_value_spec.rb @@ -0,0 +1,18 @@ +require File.expand_path('../../../../spec_helper', __FILE__) +require 'rexml/document' + +describe "REXML::Attribute#==" do + it "returns true if other has equal name and value" do + a1 = REXML::Attribute.new("foo", "bar") + a1.should == a1.clone + + a2 = REXML::Attribute.new("foo", "bar") + a1.should == a2 + + a3 = REXML::Attribute.new("foo", "bla") + a1.should_not == a3 + + a4 = REXML::Attribute.new("baz", "bar") + a1.should_not == a4 + end +end diff --git a/spec/rubyspec/library/rexml/attribute/hash_spec.rb b/spec/rubyspec/library/rexml/attribute/hash_spec.rb new file mode 100644 index 0000000000..a77c23aada --- /dev/null +++ b/spec/rubyspec/library/rexml/attribute/hash_spec.rb @@ -0,0 +1,13 @@ +require File.expand_path('../../../../spec_helper', __FILE__) +require 'rexml/document' + +describe "REXML::Attribute#hash" do + # These are not really complete, any idea on how to make them more + # "testable" will be appreciated. + it "returns a hashcode made of the name and value of self" do + a = REXML::Attribute.new("name", "value") + a.hash.should be_kind_of(Numeric) + b = REXML::Attribute.new(a) + a.hash.should == b.hash + end +end diff --git a/spec/rubyspec/library/rexml/attribute/initialize_spec.rb b/spec/rubyspec/library/rexml/attribute/initialize_spec.rb new file mode 100644 index 0000000000..637bd1b012 --- /dev/null +++ b/spec/rubyspec/library/rexml/attribute/initialize_spec.rb @@ -0,0 +1,29 @@ +require File.expand_path('../../../../spec_helper', __FILE__) +require 'rexml/document' + +describe "REXML::Attribute#initialize" do + before :each do + @e = REXML::Element.new "root" + @name = REXML::Attribute.new("name", "Nicko") + @e.add_attribute @name + end + + it "receives two strings for name and value" do + @e.attributes["name"].should == "Nicko" + @e.add_attribute REXML::Attribute.new("last_name", nil) + @e.attributes["last_name"].should == "" + end + + it "receives an Attribute and clones it" do + copy = REXML::Attribute.new(@name) + copy.should == @name + end + + it "recives a parent node" do + last_name = REXML::Attribute.new("last_name", "McBrain", @e) + last_name.element.should == @e + + last_name = REXML::Attribute.new(@name, @e) + last_name.element.should == @e + end +end diff --git a/spec/rubyspec/library/rexml/attribute/inspect_spec.rb b/spec/rubyspec/library/rexml/attribute/inspect_spec.rb new file mode 100644 index 0000000000..bfc764f663 --- /dev/null +++ b/spec/rubyspec/library/rexml/attribute/inspect_spec.rb @@ -0,0 +1,20 @@ +require File.expand_path('../../../../spec_helper', __FILE__) +require 'rexml/document' + +describe "REXML::Attribute#inspect" do + it "returns the name and value as a string" do + a = REXML::Attribute.new("my_name", "my_value") + a.inspect.should == "my_name='my_value'" + end + + it "accepts attributes with no value" do + a = REXML::Attribute.new("my_name") + a.inspect.should == "my_name=''" + end + + it "does not escape text" do + a = REXML::Attribute.new("&&", "<>") + a.inspect.should == "&&='<>'" + end +end + diff --git a/spec/rubyspec/library/rexml/attribute/namespace_spec.rb b/spec/rubyspec/library/rexml/attribute/namespace_spec.rb new file mode 100644 index 0000000000..5df9742cd3 --- /dev/null +++ b/spec/rubyspec/library/rexml/attribute/namespace_spec.rb @@ -0,0 +1,24 @@ +require File.expand_path('../../../../spec_helper', __FILE__) +require 'rexml/document' + +describe "REXML::Attribute#namespace" do + it "returns the namespace url" do + e = REXML::Element.new("root") + e.add_attribute REXML::Attribute.new("xmlns:ns", "http://some_uri") + e.namespace("ns").should == "http://some_uri" + end + + it "returns nil if namespace is not defined" do + e = REXML::Element.new("root") + e.add_attribute REXML::Attribute.new("test", "value") + e.namespace("test").should == nil + e.namespace("ns").should == nil + end + + it "defaults arg to nil" do + e = REXML::Element.new("root") + e.add_attribute REXML::Attribute.new("xmlns:ns", "http://some_uri") + e.namespace.should == "" + e.namespace("ns").should == "http://some_uri" + end +end diff --git a/spec/rubyspec/library/rexml/attribute/node_type_spec.rb b/spec/rubyspec/library/rexml/attribute/node_type_spec.rb new file mode 100644 index 0000000000..d44695deff --- /dev/null +++ b/spec/rubyspec/library/rexml/attribute/node_type_spec.rb @@ -0,0 +1,10 @@ +require File.expand_path('../../../../spec_helper', __FILE__) +require 'rexml/document' + +describe "REXML::Attribute#node_type" do + it "always returns :attribute" do + attr = REXML::Attribute.new("foo", "bar") + attr.node_type.should == :attribute + REXML::Attribute.new(attr).node_type.should == :attribute + end +end diff --git a/spec/rubyspec/library/rexml/attribute/prefix_spec.rb b/spec/rubyspec/library/rexml/attribute/prefix_spec.rb new file mode 100644 index 0000000000..698c8d5d7b --- /dev/null +++ b/spec/rubyspec/library/rexml/attribute/prefix_spec.rb @@ -0,0 +1,18 @@ +require File.expand_path('../../../../spec_helper', __FILE__) +require 'rexml/document' + +describe "REXML::Attribute#prefix" do + it "returns the namespace of the Attribute" do + ans = REXML::Attribute.new("ns:someattr", "some_value") + out = REXML::Attribute.new("out:something", "some_other_value") + + ans.prefix.should == "ns" + out.prefix.should == "out" + end + + it "returns an empty string for Attributes with no prefixes" do + attr = REXML::Attribute.new("foo", "bar") + + attr.prefix.should == "" + end +end diff --git a/spec/rubyspec/library/rexml/attribute/remove_spec.rb b/spec/rubyspec/library/rexml/attribute/remove_spec.rb new file mode 100644 index 0000000000..5a08ef3a3c --- /dev/null +++ b/spec/rubyspec/library/rexml/attribute/remove_spec.rb @@ -0,0 +1,20 @@ +require File.expand_path('../../../../spec_helper', __FILE__) +require 'rexml/document' + +describe "REXML::Attribute#remove" do + before :each do + @e = REXML::Element.new "Root" + @attr = REXML::Attribute.new("foo", "bar") + end + + it "deletes this Attribute from parent" do + @e.add_attribute(@attr) + @e.attributes["foo"].should_not == nil + @attr.remove + @e.attributes["foo"].should == nil + end + + it "does not anything if element has no parent" do + lambda {@attr.remove}.should_not raise_error(Exception) + end +end diff --git a/spec/rubyspec/library/rexml/attribute/to_s_spec.rb b/spec/rubyspec/library/rexml/attribute/to_s_spec.rb new file mode 100644 index 0000000000..96831625b6 --- /dev/null +++ b/spec/rubyspec/library/rexml/attribute/to_s_spec.rb @@ -0,0 +1,14 @@ +require File.expand_path('../../../../spec_helper', __FILE__) +require 'rexml/document' + +describe "REXML::Attribute#to_s" do + it "returns the value of the Attribute" do + REXML::Attribute.new("name", "some_value").to_s.should == "some_value" + end + + it "returns the escaped value if it was created from Attribute" do + orig = REXML::Attribute.new("name", "<&>") + copy = REXML::Attribute.new(orig) + copy.to_s.should == "<&>" + end +end diff --git a/spec/rubyspec/library/rexml/attribute/to_string_spec.rb b/spec/rubyspec/library/rexml/attribute/to_string_spec.rb new file mode 100644 index 0000000000..f8cc639a9d --- /dev/null +++ b/spec/rubyspec/library/rexml/attribute/to_string_spec.rb @@ -0,0 +1,15 @@ +require File.expand_path('../../../../spec_helper', __FILE__) +require 'rexml/document' + +describe "REXML::Attribute#to_string" do + it "returns the attribute as XML" do + attr = REXML::Attribute.new("name", "value") + attr_empty = REXML::Attribute.new("name") + attr_ns = REXML::Attribute.new("xmlns:ns", "http://uri") + + attr.to_string.should == "name='value'" + attr_empty.to_string.should == "name=''" + attr_ns.to_string.should == "xmlns:ns='http://uri'" + end +end + diff --git a/spec/rubyspec/library/rexml/attribute/value_spec.rb b/spec/rubyspec/library/rexml/attribute/value_spec.rb new file mode 100644 index 0000000000..912509cd75 --- /dev/null +++ b/spec/rubyspec/library/rexml/attribute/value_spec.rb @@ -0,0 +1,15 @@ +require File.expand_path('../../../../spec_helper', __FILE__) +require 'rexml/document' + +describe "REXML::Attribute#value" do + it "returns the value of the Attribute unnormalized" do + attr = REXML::Attribute.new("name", "value") + attr_ents = REXML::Attribute.new("name", "<&>") + attr_empty = REXML::Attribute.new("name") + + attr.value.should == "value" + attr_ents.value.should == "<&>" + attr_empty.value.should == "" + end +end + diff --git a/spec/rubyspec/library/rexml/attribute/write_spec.rb b/spec/rubyspec/library/rexml/attribute/write_spec.rb new file mode 100644 index 0000000000..b6b59930e3 --- /dev/null +++ b/spec/rubyspec/library/rexml/attribute/write_spec.rb @@ -0,0 +1,23 @@ +require File.expand_path('../../../../spec_helper', __FILE__) +require 'rexml/document' + +describe "REXML::Attribute#write" do + before :each do + @attr = REXML::Attribute.new("name", "Charlotte") + @s = "" + end + + it "writes the name and value to output" do + @attr.write(@s) + @s.should == "name='Charlotte'" + end + + it "currently ignores the second argument" do + @attr.write(@s, 3) + @s.should == "name='Charlotte'" + + @s = "" + @attr.write(@s, "foo") + @s.should == "name='Charlotte'" + end +end diff --git a/spec/rubyspec/library/rexml/attribute/xpath_spec.rb b/spec/rubyspec/library/rexml/attribute/xpath_spec.rb new file mode 100644 index 0000000000..6fb80ead37 --- /dev/null +++ b/spec/rubyspec/library/rexml/attribute/xpath_spec.rb @@ -0,0 +1,20 @@ +require File.expand_path('../../../../spec_helper', __FILE__) +require 'rexml/document' + +describe "REXML::Attribute#xpath" do + + before :each do + @e = REXML::Element.new "root" + @attr = REXML::Attribute.new("year", "1989") + end + + it "returns the path for Attribute" do + @e.add_attribute @attr + @attr.xpath.should == "root/@year" + end + + it "raises an error if attribute has no parent" do + lambda { @attr.xpath }.should raise_error(Exception) + end +end + -- cgit v1.2.3