summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorkou <kou@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2005-04-09 03:09:52 +0000
committerkou <kou@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2005-04-09 03:09:52 +0000
commit80861909e66342872332c47e57d8d42e68b0759c (patch)
tree47a070c926cf4cad42a7ec2d1cb6b2bc885b206d /test
parent16cb9d65eda9e2a692b9f0f5299a477793a8ba11 (diff)
* lib/rss: backoported from HEAD.
* lib/rss: refactored. - gave a name to 'x'. - undef_method -> remove_method for avoiding a warning in ruby 1.6. * lib/rss/parser.rb: @@setter -> @@setters. * lib/rss/parser.rb (RSS::BaseListener.register_uri) (RSS::BaseListener.uri_registered?) (RSS::BaseListener.install_get_text_element): swapped the first argument and the second argument. * lib/rss/taxonomy.rb: swapped the first argument and the second argument for RSS::BaseListener.install_get_text_element. * lib/rss/image.rb: ditto. * lib/rss/syndication.rb: ditto. * lib/rss/dublincore.rb: ditto. * lib/rss/parser.rb: ditto. * lib/rss/1.0.rb: ditto. * lib/rss/2.0.rb: ditto. * lib/rss/0.9.rb: ditto. * lib/rss/content.rb: ditto. * lib/rss/parser.rb (RSS::BaseListener.install_setter) (RSS::BaseListener.register_uri): changed fallback way. * lib/rss/parser.rb: added class name registry for complex model elements. (ex. have childlen elements, have some attributes and a child element and so on.) * lib/rss/dublincore.rb: supported multiple Dublin Core items. * lib/rss/maker/dublincore.rb: ditto. * lib/rss/maker/image.rb: supproted new Dublin Core API. * lib/rss/maker/base.rb: added default current_element implementation. * lib/rss/trackback.rb (RSS::TrackBackUtils.new_with_value_if_need): moved to RSS::Utils. * lib/rss/utils.rb (RSS::Utils.new_with_value_if_need): moved from RSS::TrackBackUtils. * lib/rss/maker/image.rb: fixed invalid argument of add_need_initialize_variable bug. * lib/rss/maker/trackback.rb: ditto. * lib/rss/rss.rb (Hash#merge): added for ruby 1.6. * lib/rss/rss.rb (RSS::BaseModel.date_writer): changed to accept nil for date value. * test/test_dublincore.rb: added tests for plural accessor and multiple Dublin Core items. * test/test_setup_maker_1.0.rb: fixed swapped actual and expected values. * test/rss/rss-assertions.rb (assert_multiple_dublin_core): added an assertion for testing multiple Dublin Core items. * test/rss/test_maker_dc.rb (test_rss10_multiple): added a test for making multiple Dublin Core items. * test/rss/test_maker_dc.rb (test_date): added a test for #date= and #dc_date=. * sample/rss/tdiary_plugin/rss-recent.rb: new option: @options['rss-recent.use-image-link']: use image as link instread of text if available. * sample/rss/tdiary_plugin/rss-recent.rb (RSS_RECENT_VERSION): 0.0.5 -> 0.0.6. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@8284 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r--test/rss/rss-assertions.rb10
-rw-r--r--test/rss/test_dublincore.rb72
-rw-r--r--test/rss/test_maker_dc.rb74
-rw-r--r--test/rss/test_setup_maker_1.0.rb4
4 files changed, 146 insertions, 14 deletions
diff --git a/test/rss/rss-assertions.rb b/test/rss/rss-assertions.rb
index 569e962..2636062 100644
--- a/test/rss/rss-assertions.rb
+++ b/test/rss/rss-assertions.rb
@@ -394,6 +394,16 @@ module RSS
end
end
+ def assert_multiple_dublin_core(elems, target)
+ _wrap_assertion do
+ elems.each do |name, values, plural|
+ plural ||= "#{name}s"
+ actual = target.__send__("dc_#{plural}").collect{|x| x.value}
+ assert_equal(values, actual)
+ end
+ end
+ end
+
def assert_syndication(elems, target)
_wrap_assertion do
elems.each do |name, value|
diff --git a/test/rss/test_dublincore.rb b/test/rss/test_dublincore.rb
index e1ee929..5ad9311 100644
--- a/test/rss/test_dublincore.rb
+++ b/test/rss/test_dublincore.rb
@@ -54,26 +54,35 @@ EOR
end
def test_parser
-
assert_nothing_raised do
Parser.parse(@rss_source)
end
@elems.each do |tag, value|
- assert_too_much_tag(tag.to_s, "channel") do
- Parser.parse(make_RDF(<<-EOR, {@prefix => @uri}))
+ rss = nil
+ assert_nothing_raised do
+ rss = Parser.parse(make_RDF(<<-EOR, {@prefix => @uri}))
#{make_channel(("<" + @prefix + ":" + tag.to_s + ">" +
value.to_s +
"</" + @prefix + ":" + tag.to_s + ">") * 2)}
#{make_item}
EOR
end
+ plural_reader = "dc_#{tag}" + (tag == :rights ? "es" : "s")
+ values = rss.channel.__send__(plural_reader).collect do |x|
+ val = x.value
+ if val.kind_of?(String)
+ CGI.escapeHTML(val)
+ else
+ val
+ end
+ end
+ assert_equal([value, value], values)
end
end
-
- def test_accessor
-
+
+ def test_singular_accessor
new_value = "hoge"
@elems.each do |name, value|
@@ -101,15 +110,58 @@ EOR
end
end
end
+ end
+ def test_plural_accessor
+ new_value = "hoge"
+
+ @elems.each do |name, value|
+ @parents.each do |parent|
+ parsed_value = @rss.send(parent).send("dc_#{name}")
+ if parsed_value.kind_of?(String)
+ parsed_value = CGI.escapeHTML(parsed_value)
+ end
+ assert_equal(value, parsed_value)
+
+ plural_reader = "dc_#{name}" + (name == :rights ? "es" : "s")
+ klass_name = "DublinCore#{Utils.to_class_name(name.to_s)}"
+ klass = DublinCoreModel.const_get(klass_name)
+ if name == :date
+ t = Time.iso8601("2003-01-01T02:30:23+09:00")
+ class << t
+ alias_method(:to_s, :iso8601)
+ end
+ elems = @rss.send(parent).send(plural_reader)
+ elems << klass.new(t.iso8601)
+ values = @rss.send(parent).send(plural_reader).collect{|x| x.value}
+ assert_equal([@rss.send(parent).send("dc_#{name}"), t],
+ values)
+ else
+ elems = @rss.send(parent).send(plural_reader)
+ elems << klass.new(new_value)
+ values = @rss.send(parent).send(plural_reader).collect{|x| x.value}
+ assert_equal([@rss.send(parent).send("dc_#{name}"), new_value],
+ values)
+ end
+ end
+ end
end
def test_to_s
-
@elems.each do |name, value|
excepted = "<#{@prefix}:#{name}>#{value}</#{@prefix}:#{name}>"
@parents.each do |parent|
- assert_equal(excepted, @rss.send(parent).send("dc_#{name}_element"))
+ assert_equal(excepted, @rss.send(parent).send("dc_#{name}_elements"))
+ end
+
+ excepted = Array.new(2, excepted).join("\n")
+ @parents.each do |parent|
+ reader = "dc_#{name}" + (name == :rights ? "es" : "s")
+ elems = @rss.send(parent).send(reader)
+ klass_name = "DublinCore#{Utils.to_class_name(name.to_s)}"
+ klass = DublinCoreModel.const_get(klass_name)
+ elems << klass.new(@rss.send(parent).send("dc_#{name}"))
+ assert_equal(excepted, @rss.send(parent).send("dc_#{name}_elements"))
end
end
@@ -117,12 +169,12 @@ EOR
if @parents.include?(parent.name)
parent.each_element do |elem|
if elem.namespace == @uri
- assert_equal(CGI.escapeHTML(elem.text), @elems[elem.name.intern].to_s)
+ assert_equal(CGI.escapeHTML(elem.text),
+ @elems[elem.name.intern].to_s)
end
end
end
end
-
end
end
diff --git a/test/rss/test_maker_dc.rb b/test/rss/test_maker_dc.rb
index 0a4a4d4..9f568ed 100644
--- a/test/rss/test_maker_dc.rb
+++ b/test/rss/test_maker_dc.rb
@@ -56,16 +56,86 @@ module RSS
assert_dublin_core(@elements, rss.textinput)
end
+ def test_rss10_multiple
+ elems = []
+ @elements.each do |name, value|
+ plural = name.to_s + (name == :rights ? "es" : "s")
+ values = [value]
+ if name == :date
+ values << value + 60
+ else
+ values << value * 2
+ end
+ elems << [name, values, plural]
+ end
+
+ rss = RSS::Maker.make("1.0") do |maker|
+ setup_dummy_channel(maker)
+ set_multiple_elements(maker.channel, elems)
+
+ setup_dummy_image(maker)
+ set_multiple_elements(maker.image, elems)
+
+ setup_dummy_item(maker)
+ item = maker.items.last
+ elems.each do |name, values, plural|
+ dc_elems = item.__send__("dc_#{plural}")
+ values.each do |value|
+ elem = dc_elems.__send__("new_#{name}")
+ elem.value = value
+ end
+ end
+
+ setup_dummy_textinput(maker)
+ set_multiple_elements(maker.textinput, elems)
+ end
+ assert_multiple_dublin_core(elems, rss.channel)
+ assert_multiple_dublin_core(elems, rss.image)
+ assert_multiple_dublin_core(elems, rss.items.last)
+ assert_multiple_dublin_core(elems, rss.textinput)
+ end
+
+ def test_date
+ t1 = Time.iso8601("2000-01-01T12:00:05+00:00")
+ t2 = Time.iso8601("2005-01-01T12:00:05+00:00")
+
+ rss = RSS::Maker.make("1.0") do |maker|
+ setup_dummy_channel(maker)
+ maker.channel.date = t1
+ date = maker.channel.dc_dates.new_date
+ date.value = t2
+
+ setup_dummy_item(maker)
+ item = maker.items.last
+ item.date = t2
+ date = item.dc_dates.new_date
+ date.value = t1
+ end
+ assert_equal([t1, t2], rss.channel.dc_dates.collect{|x| x.value})
+ assert_equal([t2, t1], rss.items.last.dc_dates.collect{|x| x.value})
+ end
+
private
def accessor_name(name)
"dc_#{name}"
end
- def set_elements(target)
- @elements.each do |name, value|
+ def set_elements(target, elems=@elements)
+ elems.each do |name, value|
target.__send__("#{accessor_name(name)}=", value)
end
end
+ def set_multiple_elements(target, elems)
+ elems.each do |name, values, plural|
+ plural ||= "#{name}s"
+ dc_elems = target.__send__("dc_#{plural}")
+ values.each do |value|
+ new_dc_elem = dc_elems.__send__("new_#{name}")
+ new_dc_elem.value = value
+ end
+ end
+ end
+
end
end
diff --git a/test/rss/test_setup_maker_1.0.rb b/test/rss/test_setup_maker_1.0.rb
index 5255748..395e9b1 100644
--- a/test/rss/test_setup_maker_1.0.rb
+++ b/test/rss/test_setup_maker_1.0.rb
@@ -84,11 +84,11 @@ module RSS
assert_nil(channel.textinput)
@dc_elems.each do |var, value|
- assert_equal(channel.__send__("dc_#{var}"), value)
+ assert_equal(value, channel.__send__("dc_#{var}"))
end
@sy_elems.each do |var, value|
- assert_equal(channel.__send__("sy_#{var}"), value)
+ assert_equal(value, channel.__send__("sy_#{var}"))
end
end