From e289fcf81a22f1dc6ebcb87861877b463af04b7c Mon Sep 17 00:00:00 2001 From: kou Date: Tue, 6 Jul 2004 17:43:05 +0000 Subject: * lib/rss/{rss,parser,0.9,1.0,2.0}.rb: supported RSS 0.9x/2.0 validation and validation which disregard order of elements. * test/rss/test_parser.rb: added tests for RSS 0.9x/2.0 validation. * test/rss/{test_trackback,rss-testcase}.rb: fixed no good method name. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6590 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/rss/test_parser.rb | 171 ++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 157 insertions(+), 14 deletions(-) (limited to 'test/rss/test_parser.rb') diff --git a/test/rss/test_parser.rb b/test/rss/test_parser.rb index 05ff9748ad..5b15ccb908 100644 --- a/test/rss/test_parser.rb +++ b/test/rss/test_parser.rb @@ -3,6 +3,8 @@ require "rss-testcase" require "rss/1.0" +require "rss/2.0" +require "rss/dublincore" module RSS class TestParser < TestCase @@ -76,14 +78,19 @@ EOR EOR end - assert_not_excepted_tag("image", "RDF") do - Parser.parse(make_RDF(<<-EOR)) + assert_parse(make_RDF(<<-EOR), :nothing_raised) #{make_channel} #{make_item} #{make_image} #{make_textinput} EOR - end + + assert_parse(make_RDF(<<-EOR), :nothing_raised) +#{make_channel} +#{make_item} +#{make_textinput} +#{make_image} +EOR assert_parse(make_RDF(<<-EOR), :nothing_raised) #{make_channel} @@ -279,16 +286,25 @@ EOR EOR - rss = make_RDF(<<-EOR) + assert_parse(make_RDF(<<-EOR), :missing_tag, "item", "RDF") #{make_channel} hoge + http://example.com/hoge.png + http://example.com/ + +EOR + + rss = make_RDF(<<-EOR) +#{make_channel} + http://example.com/ http://example.com/hoge.png + hoge EOR - assert_missing_tag("url", "image") do + assert_missing_tag("item", "RDF") do Parser.parse(rss) end @@ -296,15 +312,6 @@ EOR Parser.parse(rss, false).validate end - assert_parse(make_RDF(<<-EOR), :missing_tag, "item", "RDF") -#{make_channel} - - hoge - http://example.com/hoge.png - http://example.com/ - -EOR - end def test_item @@ -439,6 +446,142 @@ EOR end + def test_rss20 + + assert_parse(make_rss20(<<-EOR), :missing_tag, "channel", "rss") +EOR + + assert_parse(make_rss20(<<-EOR), :nothing_raised) +#{make_channel20("")} +EOR + + end + + def test_cloud20 + + attrs = [ + ["domain", CLOUD_DOMAIN], + ["port", CLOUD_PORT], + ["path", CLOUD_PATH], + ["registerProcedure", CLOUD_REGISTER_PROCEDURE], + ["protocol", CLOUD_PROTOCOL], + ] + + (attrs.size + 1).times do |i| + missing_attr = attrs[i] + if missing_attr + meth = :missing_attribute + args = ["cloud", missing_attr[0]] + else + meth = :nothing_raised + args = [] + end + + cloud_attrs = [] + attrs.each_with_index do |attr, j| + unless i == j + cloud_attrs << %Q[#{attr[0]}="#{attr[1]}"] + end + end + + assert_parse(make_rss20(<<-EOR), meth, *args) +#{make_channel20(%Q[])} +EOR + + end + + end + + def test_source20 + + assert_parse(make_rss20(<<-EOR), :missing_attribute, "source", "url") +#{make_channel20(make_item20(%Q[Example]))} +EOR + + assert_parse(make_rss20(<<-EOR), :nothing_raised) +#{make_channel20(make_item20(%Q[]))} +EOR + + assert_parse(make_rss20(<<-EOR), :nothing_raised) +#{make_channel20(make_item20(%Q[Example]))} +EOR + end + + def test_enclosure20 + + attrs = [ + ["url", ENCLOSURE_URL], + ["length", ENCLOSURE_LENGTH], + ["type", ENCLOSURE_TYPE], + ] + + (attrs.size + 1).times do |i| + missing_attr = attrs[i] + if missing_attr + meth = :missing_attribute + args = ["enclosure", missing_attr[0]] + else + meth = :nothing_raised + args = [] + end + + enclosure_attrs = [] + attrs.each_with_index do |attr, j| + unless i == j + enclosure_attrs << %Q[#{attr[0]}="#{attr[1]}"] + end + end + + assert_parse(make_rss20(<<-EOR), meth, *args) +#{make_channel20(%Q[ +#{make_item20(%Q[ + + ])} + ])} +EOR + + end + + end + + def test_category20 + + attrs = [ + ["domain", CATEGORY_DOMAIN], + ] + + (attrs.size + 1).times do |i| + missing_attr = attrs[i] + if missing_attr + meth = :missing_attribute + args = ["category", missing_attr[0]] + else + meth = :nothing_raised + args = [] + end + + category_attrs = [] + attrs.each_with_index do |attr, j| + unless i == j + category_attrs << %Q[#{attr[0]}="#{attr[1]}"] + end + end + + ["", "Example Text"].each do |text| + assert_parse(make_rss20(<<-EOR), meth, *args) +#{make_channel20(%Q[ +#{make_item20(%Q[ +#{text} + ])} + ])} +EOR + end + end + + end + def test_ignore rss = make_RDF(<<-EOR) -- cgit v1.2.3