From 2fa78a09f7d3c35640f261cc427944a5011401cc Mon Sep 17 00:00:00 2001 From: kou Date: Wed, 8 Dec 2004 12:58:36 +0000 Subject: * lib/rss, test/rss, sample/rss: backported from CVS HEAD. git-svn-id: http://svn.ruby-lang.org/repos/ruby/branches/ruby_1_8@7509 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/rss/rss-assertions.rb | 341 ++++++++++++++++++++++++++++++++++++--- test/rss/test_1.0.rb | 5 +- test/rss/test_maker_0.9.rb | 204 ++++++++++++----------- test/rss/test_maker_1.0.rb | 84 +++++----- test/rss/test_maker_2.0.rb | 135 ++++++++++------ test/rss/test_maker_content.rb | 2 +- test/rss/test_maker_dc.rb | 2 +- test/rss/test_maker_sy.rb | 2 +- test/rss/test_maker_trackback.rb | 13 +- test/rss/test_parser.rb | 12 +- test/rss/test_trackback.rb | 10 +- test/rss/test_xml-stylesheet.rb | 6 +- 12 files changed, 575 insertions(+), 241 deletions(-) (limited to 'test/rss') diff --git a/test/rss/rss-assertions.rb b/test/rss/rss-assertions.rb index 6b83cbe09..569e9621d 100644 --- a/test/rss/rss-assertions.rb +++ b/test/rss/rss-assertions.rb @@ -94,27 +94,44 @@ module RSS end end end - - def assert_xml_stylesheet_attrs(xsl, attrs) + + def assert_not_set_error(name, variables) _wrap_assertion do - normalized_attrs = {} - attrs.each do |name, value| - normalized_attrs[name.to_s] = value + begin + yield + flunk("Not raise NotSetError") + rescue ::RSS::NotSetError => e + assert_equal(name, e.name) + assert_equal(variables.sort, e.variables.sort) end + end + end + + def assert_xml_declaration(version, encoding, standalone, rss) + _wrap_assertion do + assert_equal(version, rss.version) + assert_equal(encoding, rss.encoding) + assert_equal(standalone, rss.standalone) + end + end + + def assert_xml_stylesheet_attrs(attrs, xsl) + _wrap_assertion do + n_attrs = normalized_attrs(attrs) ::RSS::XMLStyleSheet::ATTRIBUTES.each do |name| - assert_equal(normalized_attrs[name], xsl.send(name)) + assert_equal(n_attrs[name], xsl.send(name)) end end end - def assert_xml_stylesheet(target, xsl, attrs) + def assert_xml_stylesheet(target, attrs, xsl) _wrap_assertion do if attrs.has_key?(:href) if !attrs.has_key?(:type) and attrs.has_key?(:guess_type) attrs[:type] = attrs[:guess_type] end assert_equal("xml-stylesheet", target) - assert_xml_stylesheet_attrs(xsl, attrs) + assert_xml_stylesheet_attrs(attrs, xsl) else assert_nil(target) assert_equal("", xsl.to_s) @@ -123,39 +140,313 @@ module RSS end def assert_xml_stylesheet_pis(attrs_ary) - rdf = ::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) + _wrap_assertion do + rdf = ::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) + end + pi_str = rdf.to_s.gsub(/<\?xml .*\n/, "").gsub(/\s* "http://bar.com/tb.cgi?tb_id=rssplustrackback", - :about => "http://foo.com/trackback/tb.cgi?tb_id=20020923", + :abouts => [ + "http://foo.com/trackback/tb.cgi?tb_id=20020923", + "http://bar.com/trackback/tb.cgi?tb_id=20041114", + ], } end def test_rss10 - rss = RSS::Maker.make("1.0", ["trackback"]) do |maker| + rss = RSS::Maker.make("1.0") do |maker| setup_dummy_channel(maker) setup_dummy_item(maker) item = maker.items.last - @elements.each do |name, value| - item.__send__("#{accessor_name(name)}=", value) + item.trackback_ping = @elements[:ping] + @elements[:abouts].each do |about| + new_about = item.trackback_abouts.new_about + new_about.value = about end end assert_trackback(@elements, rss.items.last) diff --git a/test/rss/test_parser.rb b/test/rss/test_parser.rb index de4894997..019030bcc 100644 --- a/test/rss/test_parser.rb +++ b/test/rss/test_parser.rb @@ -116,7 +116,7 @@ EOR def test_channel - assert_parse(make_RDF(<<-EOR), :missing_attribute, "channel", "about") + assert_parse(make_RDF(<<-EOR), :missing_attribute, "channel", "rdf:about") EOR @@ -145,7 +145,7 @@ EOR EOR - assert_parse(make_RDF(<<-EOR), :missing_attribute, "image", "resource") + assert_parse(make_RDF(<<-EOR), :missing_attribute, "image", "rdf:resource") hoge http://example.com/ @@ -194,7 +194,7 @@ EOR EOR - assert_parse(make_RDF(<<-EOR), :missing_attribute, "textinput", "resource") + assert_parse(make_RDF(<<-EOR), :missing_attribute, "textinput", "rdf:resource") hoge http://example.com/ @@ -257,7 +257,7 @@ EOR def test_image - assert_parse(make_RDF(<<-EOR), :missing_attribute, "image", "about") + assert_parse(make_RDF(<<-EOR), :missing_attribute, "image", "rdf:about") #{make_channel} @@ -314,7 +314,7 @@ EOR def test_item - assert_parse(make_RDF(<<-EOR), :missing_attribute, "item", "about") + assert_parse(make_RDF(<<-EOR), :missing_attribute, "item", "rdf:about") #{make_channel} #{make_image} @@ -371,7 +371,7 @@ EOR def test_textinput - assert_parse(make_RDF(<<-EOR), :missing_attribute, "textinput", "about") + assert_parse(make_RDF(<<-EOR), :missing_attribute, "textinput", "rdf:about") #{make_channel} #{make_image} #{make_item} diff --git a/test/rss/test_trackback.rb b/test/rss/test_trackback.rb index bfe39d005..a3f023e88 100644 --- a/test/rss/test_trackback.rb +++ b/test/rss/test_trackback.rb @@ -88,19 +88,19 @@ EOR @elems.each do |name, value| @parents.each do |parent| accessor = "#{RSS::TRACKBACK_PREFIX}_#{name}" - target_accessor = "resource" - target = @rss.send(parent).send(accessor) + target = @rss.send(parent) target20 = @rss20.channel.send(parent, -1) - assert_equal(value, target.send(target_accessor)) + assert_equal(value, target.send(accessor)) assert_equal(value, target20.send(accessor)) - target.send("#{target_accessor}=", new_value[name].to_s) if name == :about # abount is zero or more + target.send("#{accessor}=", 0, new_value[name].to_s) target20.send("#{accessor}=", 0, new_value[name].to_s) else + target.send("#{accessor}=", new_value[name].to_s) target20.send("#{accessor}=", new_value[name].to_s) end - assert_equal(new_value[name], target.send(target_accessor)) + assert_equal(new_value[name], target.send(accessor)) assert_equal(new_value[name], target20.send(accessor)) end end diff --git a/test/rss/test_xml-stylesheet.rb b/test/rss/test_xml-stylesheet.rb index ab16d6e2f..c88a858f5 100644 --- a/test/rss/test_xml-stylesheet.rb +++ b/test/rss/test_xml-stylesheet.rb @@ -14,7 +14,7 @@ module RSS {:media => "print", :title => "FOO"}, {:charset => "UTF-8", :alternate => "yes"}, ].each do |attrs| - assert_xml_stylesheet_attrs(XMLStyleSheet.new(*attrs), attrs) + assert_xml_stylesheet_attrs(attrs, XMLStyleSheet.new(*attrs)) end end @@ -36,7 +36,7 @@ module RSS :alternate => "yes"}, ].each do |attrs| target, contents = parse_pi(XMLStyleSheet.new(*attrs).to_s) - assert_xml_stylesheet(target, XMLStyleSheet.new(*contents), attrs) + assert_xml_stylesheet(target, attrs, XMLStyleSheet.new(*contents)) end end @@ -88,7 +88,7 @@ module RSS assert_equal(have_href_xsss.size, rss.xml_stylesheets.size) rss.xml_stylesheets.each_with_index do |stylesheet, i| target, = parse_pi(stylesheet.to_s) - assert_xml_stylesheet(target, stylesheet, have_href_xsss[i]) + assert_xml_stylesheet(target, have_href_xsss[i], stylesheet) end end end -- cgit