1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* lib/rss, test/rss: backported from trunk. (2005-11-16 - now)

* test/rss/test_2.0.rb: added RSS 2.0 tests.
* test/rss/rss-assertions.rb: extended XML stylesheet assertion.
* lib/rss/0.9.rb: added initialize method.
* test/rss/test_1.0.rb: cleanup.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@10296 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
kou 2006-06-17 00:53:21 +00:00
parent 88dd1e4c99
commit 7461f297e9
5 changed files with 52 additions and 65 deletions

View file

@ -68,6 +68,11 @@ Sat Jun 17 09:03:47 2006 Kouhei Sutou <kou@cozmixng.org>
* test/rss/test_parser.rb: added an entity handling test.
* test/rss/test_2.0.rb: added RSS 2.0 tests.
* test/rss/rss-assertions.rb: extended XML stylesheet assertion.
* lib/rss/0.9.rb: added initialize method.
* test/rss/test_1.0.rb: cleanup.
Sat Jun 17 02:01:00 2006 Tanaka Akira <akr@m17n.org>
* lib/pp.rb (Kernel#pretty_inspect): defined for pretty printed

View file

@ -339,6 +339,17 @@ module RSS
install_model(name, "?")
end
def initialize(url=nil, title=nil, link=nil, width=nil, height=nil,
description=nil)
super()
@url = url
@title = title
@link = link
@width = width
@height = height
@description = description
end
def to_s(need_convert=true, indent=calc_indent)
rv = tag(indent) do |next_indent|
[
@ -618,6 +629,14 @@ module RSS
install_model(name, nil)
end
def initialize(title=nil, description=nil, name=nil, link=nil)
super()
@title = title
@description = description
@name = name
@link = link
end
def to_s(need_convert=true, indent=calc_indent)
rv = tag(indent) do |next_indent|
[

View file

@ -139,16 +139,16 @@ module RSS
end
end
def assert_xml_stylesheet_pis(attrs_ary)
def assert_xml_stylesheet_pis(attrs_ary, rss=nil)
_wrap_assertion do
rdf = ::RSS::RDF.new()
rss ||= ::RSS::RDF.new()
xss_strs = []
attrs_ary.each do |attrs|
xss = ::RSS::XMLStyleSheet.new(*attrs)
xss_strs.push(xss.to_s)
rdf.xml_stylesheets.push(xss)
rss.xml_stylesheets.push(xss)
end
pi_str = rdf.to_s.gsub(/<\?xml .*\n/, "").gsub(/\s*<rdf:RDF.*\z/m, "")
pi_str = rss.to_s.gsub(/<\?xml .*\n/, "").gsub(/\s*<[^\?].*\z/m, "")
assert_equal(xss_strs.join("\n"), pi_str)
end
end

View file

@ -5,18 +5,15 @@ require "rss-testcase"
require "rss/1.0"
module RSS
class TestCore < TestCase
class TestRSS10Core < TestCase
def setup
@rdf_prefix = "rdf"
@rdf_uri = "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
@uri = "http://purl.org/rss/1.0/"
end
def test_RDF
version = "1.0"
encoding = "UTF-8"
standalone = false
@ -33,7 +30,6 @@ module RSS
assert_equal(standalone, !xmldecl.standalone.nil?)
assert_equal(@rdf_uri, doc.root.namespace)
end
def test_not_displayed_xml_stylesheets
@ -93,11 +89,9 @@ module RSS
end
assert_equal(@uri, c.elements["items"].namespace)
assert_equal("items", c.elements["items"].name)
end
def test_channel_image
resource = "http://hoge.com/hoge.png"
image = RDF::Channel::Image.new(resource)
@ -111,11 +105,9 @@ module RSS
assert_equal(@rdf_uri, res.namespace)
assert_equal(resource, res.value)
end
def test_channel_textinput
resource = "http://hoge.com/hoge.png"
textinput = RDF::Channel::Textinput.new(resource)
@ -129,11 +121,9 @@ module RSS
assert_equal(@rdf_uri, res.namespace)
assert_equal(resource, res.value)
end
def test_items
items = RDF::Channel::Items.new
doc = REXML::Document.new(make_RDF(items.to_s))
@ -145,11 +135,9 @@ module RSS
assert_equal(1, i.elements.size)
assert_equal("Seq", i.elements[1].name)
assert_equal(@rdf_uri, i.elements[1].namespace)
end
def test_seq
seq = RDF::Seq.new
doc = REXML::Document.new(make_RDF(seq.to_s))
@ -157,11 +145,9 @@ module RSS
assert_equal("Seq", s.name)
assert_equal(@rdf_uri, s.namespace)
end
def test_li
resource = "http://hoge.com/"
li = RDF::Li.new(resource)
@ -175,11 +161,9 @@ module RSS
assert_equal('', res.instance_eval("@prefix"))
assert_equal(resource, res.value)
end
def test_image
about = "http://hoge.com"
title = "fugafuga"
url = "http://hoge.com/hoge"
@ -200,11 +184,9 @@ module RSS
assert_equal(@uri, elem.namespace)
assert_equal(instance_eval(x), elem.text)
end
end
def test_item
about = "http://hoge.com"
title = "fugafuga"
link = "http://hoge.com/fuga"
@ -225,11 +207,9 @@ module RSS
assert_equal(@uri, elem.namespace)
assert_equal(instance_eval(x), elem.text)
end
end
def test_textinput
about = "http://hoge.com"
title = "fugafuga"
link = "http://hoge.com/fuga"
@ -251,7 +231,6 @@ module RSS
assert_equal(@uri, elem.namespace)
assert_equal(instance_eval(x), elem.text)
end
end
def test_indent_size
@ -264,6 +243,5 @@ module RSS
assert_equal(1, RDF::Item.indent_size)
assert_equal(1, RDF::Textinput.indent_size)
end
end
end

View file

@ -75,9 +75,9 @@ module RSS
generator = "MightyInHouse Content System v2.3"
docs = "http://blogs.law.harvard.edu/tech/rss"
ttl = "60"
ttl = 60
rating = '(PICS-1.1 "http://www.rsac.org/ratingsv01.html" l gen true comment "RSACi North America Server" for "http://www.rsac.org" on "1996.04.16T08:15-0500" r (n 0 s 0 v 0 l 0))'
rating = 6
channel = Rss::Channel.new
@ -85,9 +85,7 @@ module RSS
managingEditor webMaster pubDate lastBuildDate
generator docs ttl rating)
elems.each do |x|
value = instance_eval(x)
value = value.rfc822 if %w(pubDate lastBuildDate).include?(x)
channel.__send__("#{x}=", value)
channel.__send__("#{x}=", instance_eval(x))
end
categories.each do |cat|
channel.categories << Rss::Channel::Category.new(cat[:domain],
@ -105,8 +103,7 @@ module RSS
case x
when "pubDate", "lastBuildDate"
assert_equal(expected, Time.parse(elem.text))
when "ttl"
expected = channel.__send__(x)
when "ttl", "rating"
assert_equal(expected, elem.text.to_i)
else
assert_equal(expected, elem.text)
@ -127,7 +124,7 @@ module RSS
def test_channel_cloud
cloud_params = {
:domain => "rpc.sys.com",
:port => "80",
:port => 80,
:path => "/RPC2",
:registerProcedure => "myCloud.rssPleaseNotify",
:protocol => "xml-rpc",
@ -137,15 +134,14 @@ module RSS
cloud_params[:path],
cloud_params[:registerProcedure],
cloud_params[:protocol])
cloud_params[:port] = cloud.port
doc = REXML::Document.new(cloud.to_s)
cloud_elem = doc.root
actual = {}
cloud_elem.attributes.each do |name, value|
value = value.to_i if name == "port"
actual[name.intern] = value
actual[name.to_sym] = value
end
assert_equal(cloud_params, actual)
end
@ -155,8 +151,8 @@ module RSS
:url => "http://hoge.com/hoge.png",
:title => "fugafuga",
:link => "http://hoge.com",
:width => "144",
:height => "400",
:width => 144,
:height => 400,
:description => "an image",
}
image = Rss::Channel::Image.new(image_params[:url],
@ -170,7 +166,6 @@ module RSS
image_elem = doc.root
image_params.each do |name, value|
value = image.__send__(name)
actual = image_elem.elements[name.to_s].text
actual = actual.to_i if [:width, :height].include?(name)
assert_equal(value, actual)
@ -218,8 +213,8 @@ module RSS
def test_channel_skip_hours
skipHours_values = [
"0",
"13",
0,
13,
]
skipHours = Rss::Channel::SkipHours.new
skipHours_values.each do |value|
@ -230,8 +225,7 @@ module RSS
hours_elem = doc.root
skipHours_values.each_with_index do |value, i|
expected = skipHours.hours[i].content
assert_equal(expected, hours_elem.elements[i + 1].text.to_i)
assert_equal(value, hours_elem.elements[i + 1].text.to_i)
end
end
@ -258,9 +252,7 @@ module RSS
elems = %w(title link description author comments pubDate)
elems.each do |x|
value = instance_eval(x)
value = value.rfc822 if x == "pubDate"
item.__send__("#{x}=", value)
item.__send__("#{x}=", instance_eval(x))
end
categories.each do |cat|
item.categories << Rss::Channel::Category.new(cat[:domain],
@ -298,22 +290,24 @@ module RSS
def test_item_enclosure
enclosure_params = {
:url => "http://www.scripting.com/mp3s/weatherReportSuite.mp3",
:length => "12216320",
:length => 12216320,
:type => "audio/mpeg",
}
enclosure = Rss::Channel::Item::Enclosure.new(enclosure_params[:url],
enclosure_params[:length],
enclosure_params[:type])
enclosure_params[:length] = enclosure.length
doc = REXML::Document.new(enclosure.to_s)
enclosure_elem = doc.root
actual = {}
enclosure_elem.attributes.each do |name, value|
value = value.to_i if name == "length"
actual[name.intern] = value
if name == "length"
enclosure_params[name.to_sym] = value.to_i
value = value.to_i
end
actual[name.to_sym] = value
end
assert_equal(enclosure_params, actual)
end
@ -332,23 +326,14 @@ module RSS
test_params.each do |guid_params|
guid = Rss::Channel::Item::Guid.new(guid_params[:isPermaLink],
guid_params[:content])
if guid_params.has_key?(:isPermaLink)
guid_params[:isPermaLink] = guid.isPermaLink
end
if guid.isPermaLink.nil?
assert_equal(true, guid.PermaLink?)
else
assert_equal(guid.isPermaLink, guid.PermaLink?)
end
doc = REXML::Document.new(guid.to_s)
guid_elem = doc.root
actual = {}
actual[:content] = guid_elem.text if guid_elem.text
guid_elem.attributes.each do |name, value|
value = value == "true" if name == "isPermaLink"
actual[name.intern] = value
actual[name.to_sym] = value
end
assert_equal(guid_params, actual)
end
@ -369,7 +354,7 @@ module RSS
actual = {}
actual[:content] = source_elem.text
source_elem.attributes.each do |name, value|
actual[name.intern] = value
actual[name.to_sym] = value
end
assert_equal(source_params, actual)
end