2005-11-24 22:54:29 -05:00
|
|
|
begin
|
|
|
|
require "fileutils"
|
|
|
|
rescue LoadError
|
|
|
|
module FileUtils
|
|
|
|
module_function
|
|
|
|
def rm_f(target)
|
|
|
|
File.unlink(target)
|
|
|
|
rescue Errno::ENOENT
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2005-07-22 01:41:33 -04:00
|
|
|
|
2004-03-21 05:03:17 -05:00
|
|
|
require "rss-testcase"
|
|
|
|
|
2004-01-27 22:46:13 -05:00
|
|
|
require "rss/1.0"
|
2004-07-06 13:43:05 -04:00
|
|
|
require "rss/2.0"
|
|
|
|
require "rss/dublincore"
|
2004-03-21 05:03:17 -05:00
|
|
|
|
|
|
|
module RSS
|
2004-10-16 00:51:15 -04:00
|
|
|
class TestParser < TestCase
|
|
|
|
|
|
|
|
def setup
|
|
|
|
@_default_parser = Parser.default_parser
|
2005-07-22 01:41:33 -04:00
|
|
|
@rss10 = make_RDF(<<-EOR)
|
|
|
|
#{make_channel}
|
|
|
|
#{make_item}
|
|
|
|
#{make_textinput}
|
|
|
|
#{make_image}
|
|
|
|
EOR
|
|
|
|
@rss_file = "rss10.rdf"
|
|
|
|
File.open(@rss_file, "w") {|f| f.print(@rss10)}
|
2004-10-16 00:51:15 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def teardown
|
|
|
|
Parser.default_parser = @_default_parser
|
2005-07-22 01:41:33 -04:00
|
|
|
FileUtils.rm_f(@rss_file)
|
2004-10-16 00:51:15 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_RDF
|
|
|
|
assert_ns("", RDF::URI) do
|
|
|
|
Parser.parse(<<-EOR)
|
2004-01-27 22:46:13 -05:00
|
|
|
#{make_xmldecl}
|
|
|
|
<RDF/>
|
|
|
|
EOR
|
2004-10-16 00:51:15 -04:00
|
|
|
end
|
2004-01-27 22:46:13 -05:00
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
assert_ns("", RDF::URI) do
|
|
|
|
Parser.parse(<<-EOR)
|
2004-01-27 22:46:13 -05:00
|
|
|
#{make_xmldecl}
|
|
|
|
<RDF xmlns="hoge"/>
|
|
|
|
EOR
|
2004-10-16 00:51:15 -04:00
|
|
|
end
|
2004-01-27 22:46:13 -05:00
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
assert_ns("rdf", RDF::URI) do
|
|
|
|
Parser.parse(<<-EOR)
|
2004-01-27 22:46:13 -05:00
|
|
|
#{make_xmldecl}
|
|
|
|
<rdf:RDF xmlns:rdf="hoge"/>
|
|
|
|
EOR
|
2004-10-16 00:51:15 -04:00
|
|
|
end
|
2004-01-27 22:46:13 -05:00
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
assert_parse(<<-EOR, :missing_tag, "channel", "RDF")
|
2004-01-27 22:46:13 -05:00
|
|
|
#{make_xmldecl}
|
|
|
|
<rdf:RDF xmlns:rdf="#{RSS::RDF::URI}"/>
|
|
|
|
EOR
|
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
assert_parse(<<-EOR, :missing_tag, "channel", "RDF")
|
2004-01-27 22:46:13 -05:00
|
|
|
#{make_xmldecl}
|
|
|
|
<RDF xmlns="#{RSS::RDF::URI}"/>
|
|
|
|
EOR
|
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
assert_parse(<<-EOR, :missing_tag, "channel", "RDF")
|
2004-01-27 22:46:13 -05:00
|
|
|
#{make_xmldecl}
|
|
|
|
<RDF xmlns="#{RSS::RDF::URI}"/>
|
|
|
|
EOR
|
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
assert_parse(make_RDF(<<-EOR), :missing_tag, "item", "RDF")
|
2004-01-27 22:46:13 -05:00
|
|
|
#{make_channel}
|
|
|
|
EOR
|
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
assert_parse(make_RDF(<<-EOR), :missing_tag, "item", "RDF")
|
2004-01-27 22:46:13 -05:00
|
|
|
#{make_channel}
|
|
|
|
#{make_image}
|
|
|
|
EOR
|
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
assert_parse(make_RDF(<<-EOR), :missing_tag, "item", "RDF")
|
2004-01-27 22:46:13 -05:00
|
|
|
#{make_channel}
|
|
|
|
#{make_textinput}
|
|
|
|
EOR
|
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
assert_too_much_tag("image", "RDF") do
|
|
|
|
Parser.parse(make_RDF(<<-EOR))
|
2004-01-27 22:46:13 -05:00
|
|
|
#{make_channel}
|
|
|
|
#{make_image}
|
|
|
|
#{make_image}
|
|
|
|
#{make_item}
|
|
|
|
#{make_textinput}
|
|
|
|
EOR
|
2004-10-16 00:51:15 -04:00
|
|
|
end
|
2004-01-27 22:46:13 -05:00
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
assert_parse(make_RDF(<<-EOR), :nothing_raised)
|
2004-01-27 22:46:13 -05:00
|
|
|
#{make_channel}
|
|
|
|
#{make_item}
|
|
|
|
#{make_image}
|
|
|
|
#{make_textinput}
|
|
|
|
EOR
|
2004-07-06 13:43:05 -04:00
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
assert_parse(make_RDF(<<-EOR), :nothing_raised)
|
2004-07-06 13:43:05 -04:00
|
|
|
#{make_channel}
|
|
|
|
#{make_item}
|
|
|
|
#{make_textinput}
|
|
|
|
#{make_image}
|
|
|
|
EOR
|
2004-01-27 22:46:13 -05:00
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
assert_parse(make_RDF(<<-EOR), :nothing_raised)
|
2004-01-27 22:46:13 -05:00
|
|
|
#{make_channel}
|
|
|
|
#{make_image}
|
|
|
|
#{make_item}
|
|
|
|
EOR
|
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
assert_parse(make_RDF(<<-EOR), :nothing_raised)
|
2004-01-27 22:46:13 -05:00
|
|
|
#{make_channel}
|
|
|
|
#{make_image}
|
|
|
|
#{make_item}
|
|
|
|
#{make_textinput}
|
|
|
|
EOR
|
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
1.step(15, 3) do |i|
|
|
|
|
rss = make_RDF() do
|
|
|
|
res = make_channel
|
|
|
|
i.times { res << make_item }
|
|
|
|
res
|
|
|
|
end
|
|
|
|
assert_parse(rss, :nothing_raised)
|
|
|
|
end
|
2005-11-23 08:35:11 -05:00
|
|
|
end
|
2004-01-27 22:46:13 -05:00
|
|
|
|
2005-11-23 08:35:11 -05:00
|
|
|
def test_undefined_entity
|
|
|
|
return unless RSS::Parser.default_parser.raise_for_undefined_entity?
|
|
|
|
assert_parse(make_RDF(<<-EOR), :raises, RSS::NotWellFormedError)
|
|
|
|
#{make_channel}
|
|
|
|
#{make_image}
|
|
|
|
<item rdf:about="#{RDF_ABOUT}">
|
|
|
|
<title>#{TITLE_VALUE} &UNKNOWN_ENTITY;</title>
|
|
|
|
<link>#{LINK_VALUE}</link>
|
|
|
|
<description>#{DESCRIPTION_VALUE}</description>
|
|
|
|
</item>
|
|
|
|
#{make_textinput}
|
|
|
|
EOR
|
2004-10-16 00:51:15 -04:00
|
|
|
end
|
2004-01-27 22:46:13 -05:00
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
def test_channel
|
2004-01-27 22:46:13 -05:00
|
|
|
|
2004-11-19 03:25:25 -05:00
|
|
|
assert_parse(make_RDF(<<-EOR), :missing_attribute, "channel", "rdf:about")
|
2004-01-27 22:46:13 -05:00
|
|
|
<channel />
|
|
|
|
EOR
|
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
assert_parse(make_RDF(<<-EOR), :missing_tag, "title", "channel")
|
2004-01-27 22:46:13 -05:00
|
|
|
<channel rdf:about="http://example.com/"/>
|
|
|
|
EOR
|
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
assert_parse(make_RDF(<<-EOR), :missing_tag, "link", "channel")
|
2004-01-27 22:46:13 -05:00
|
|
|
<channel rdf:about="http://example.com/">
|
|
|
|
<title>hoge</title>
|
|
|
|
</channel>
|
|
|
|
EOR
|
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
assert_parse(make_RDF(<<EOR), :missing_tag, "description", "channel")
|
2004-01-27 22:46:13 -05:00
|
|
|
<channel rdf:about="http://example.com/">
|
|
|
|
<title>hoge</title>
|
|
|
|
<link>http://example.com/</link>
|
|
|
|
</channel>
|
|
|
|
EOR
|
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
assert_parse(make_RDF(<<-EOR), :missing_tag, "items", "channel")
|
2004-01-27 22:46:13 -05:00
|
|
|
<channel rdf:about="http://example.com/">
|
|
|
|
<title>hoge</title>
|
|
|
|
<link>http://example.com/</link>
|
|
|
|
<description>hogehoge</description>
|
|
|
|
</channel>
|
|
|
|
EOR
|
|
|
|
|
2004-11-19 03:25:25 -05:00
|
|
|
assert_parse(make_RDF(<<-EOR), :missing_attribute, "image", "rdf:resource")
|
2004-01-27 22:46:13 -05:00
|
|
|
<channel rdf:about="http://example.com/">
|
|
|
|
<title>hoge</title>
|
|
|
|
<link>http://example.com/</link>
|
|
|
|
<description>hogehoge</description>
|
|
|
|
<image/>
|
|
|
|
</channel>
|
|
|
|
EOR
|
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
assert_parse(make_RDF(<<-EOR), :missing_tag, "items", "channel")
|
2004-01-27 22:46:13 -05:00
|
|
|
<channel rdf:about="http://example.com/">
|
|
|
|
<title>hoge</title>
|
|
|
|
<link>http://example.com/</link>
|
|
|
|
<description>hogehoge</description>
|
|
|
|
<image rdf:resource="http://example.com/hoge.png" />
|
|
|
|
</channel>
|
|
|
|
EOR
|
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
rss = make_RDF(<<-EOR)
|
2004-01-27 22:46:13 -05:00
|
|
|
<channel rdf:about="http://example.com/">
|
|
|
|
<title>hoge</title>
|
|
|
|
<link>http://example.com/</link>
|
|
|
|
<description>hogehoge</description>
|
|
|
|
<image rdf:resource="http://example.com/hoge.png" />
|
|
|
|
<items/>
|
|
|
|
</channel>
|
|
|
|
EOR
|
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
assert_missing_tag("Seq", "items") do
|
|
|
|
Parser.parse(rss)
|
|
|
|
end
|
2004-01-27 22:46:13 -05:00
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
assert_missing_tag("item", "RDF") do
|
|
|
|
Parser.parse(rss, false).validate
|
|
|
|
end
|
2004-01-27 22:46:13 -05:00
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
assert_parse(make_RDF(<<-EOR), :missing_tag, "item", "RDF")
|
2004-01-27 22:46:13 -05:00
|
|
|
<channel rdf:about="http://example.com/">
|
|
|
|
<title>hoge</title>
|
|
|
|
<link>http://example.com/</link>
|
|
|
|
<description>hogehoge</description>
|
|
|
|
<image rdf:resource="http://example.com/hoge.png" />
|
|
|
|
<items>
|
|
|
|
<rdf:Seq>
|
|
|
|
</rdf:Seq>
|
|
|
|
</items>
|
|
|
|
</channel>
|
|
|
|
EOR
|
|
|
|
|
2004-11-19 03:25:25 -05:00
|
|
|
assert_parse(make_RDF(<<-EOR), :missing_attribute, "textinput", "rdf:resource")
|
2004-01-27 22:46:13 -05:00
|
|
|
<channel rdf:about="http://example.com/">
|
|
|
|
<title>hoge</title>
|
|
|
|
<link>http://example.com/</link>
|
|
|
|
<description>hogehoge</description>
|
|
|
|
<image rdf:resource="http://example.com/hoge.png" />
|
|
|
|
<items>
|
|
|
|
<rdf:Seq>
|
|
|
|
</rdf:Seq>
|
|
|
|
</items>
|
|
|
|
<textinput/>
|
|
|
|
</channel>
|
|
|
|
EOR
|
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
assert_parse(make_RDF(<<-EOR), :missing_tag, "item", "RDF")
|
2004-01-27 22:46:13 -05:00
|
|
|
<channel rdf:about="http://example.com/">
|
|
|
|
<title>hoge</title>
|
|
|
|
<link>http://example.com/</link>
|
|
|
|
<description>hogehoge</description>
|
|
|
|
<image rdf:resource="http://example.com/hoge.png" />
|
|
|
|
<items>
|
|
|
|
<rdf:Seq>
|
|
|
|
</rdf:Seq>
|
|
|
|
</items>
|
|
|
|
<textinput rdf:resource="http://example.com/search" />
|
|
|
|
</channel>
|
|
|
|
EOR
|
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
end
|
2004-01-27 22:46:13 -05:00
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
def test_rdf_li
|
2004-04-06 23:36:38 -04:00
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
rss = make_RDF(<<-EOR)
|
2004-04-06 23:36:38 -04:00
|
|
|
<channel rdf:about="http://example.com/">
|
|
|
|
<title>hoge</title>
|
|
|
|
<link>http://example.com/</link>
|
|
|
|
<description>hogehoge</description>
|
|
|
|
<image rdf:resource="http://example.com/hoge.png" />
|
|
|
|
<items>
|
|
|
|
<rdf:Seq>
|
|
|
|
<rdf:li \#{rdf_li_attr}/>
|
|
|
|
</rdf:Seq>
|
|
|
|
</items>
|
|
|
|
<textinput rdf:resource="http://example.com/search" />
|
|
|
|
</channel>
|
|
|
|
#{make_item}
|
|
|
|
EOR
|
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
source = Proc.new do |rdf_li_attr|
|
|
|
|
eval(%Q[%Q[#{rss}]], binding)
|
|
|
|
end
|
2004-04-06 23:36:38 -04:00
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
attr = %q[resource="http://example.com/hoge"]
|
|
|
|
assert_parse(source.call(attr), :nothing_raised)
|
2004-04-06 23:36:38 -04:00
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
attr = %q[rdf:resource="http://example.com/hoge"]
|
|
|
|
assert_parse(source.call(attr), :nothing_raised)
|
2004-04-06 23:36:38 -04:00
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
assert_parse(source.call(""), :missing_attribute, "li", "resource")
|
|
|
|
end
|
2004-04-06 23:36:38 -04:00
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
def test_image
|
2004-01-27 22:46:13 -05:00
|
|
|
|
2004-11-19 03:25:25 -05:00
|
|
|
assert_parse(make_RDF(<<-EOR), :missing_attribute, "image", "rdf:about")
|
2004-01-27 22:46:13 -05:00
|
|
|
#{make_channel}
|
|
|
|
<image>
|
|
|
|
</image>
|
|
|
|
EOR
|
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
assert_parse(make_RDF(<<-EOR), :missing_tag, "title", "image")
|
2004-01-27 22:46:13 -05:00
|
|
|
#{make_channel}
|
|
|
|
<image rdf:about="http://example.com/hoge.png">
|
|
|
|
</image>
|
|
|
|
EOR
|
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
assert_parse(make_RDF(<<-EOR), :missing_tag, "url", "image")
|
2004-01-27 22:46:13 -05:00
|
|
|
#{make_channel}
|
|
|
|
<image rdf:about="http://example.com/hoge.png">
|
|
|
|
<title>hoge</title>
|
|
|
|
</image>
|
|
|
|
EOR
|
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
assert_parse(make_RDF(<<-EOR), :missing_tag, "link", "image")
|
2004-01-27 22:46:13 -05:00
|
|
|
#{make_channel}
|
|
|
|
<image rdf:about="http://example.com/hoge.png">
|
|
|
|
<title>hoge</title>
|
|
|
|
<url>http://example.com/hoge.png</url>
|
|
|
|
</image>
|
|
|
|
EOR
|
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
assert_parse(make_RDF(<<-EOR), :missing_tag, "item", "RDF")
|
2004-01-27 22:46:13 -05:00
|
|
|
#{make_channel}
|
|
|
|
<image rdf:about="http://example.com/hoge.png">
|
|
|
|
<title>hoge</title>
|
2004-07-06 13:43:05 -04:00
|
|
|
<url>http://example.com/hoge.png</url>
|
|
|
|
<link>http://example.com/</link>
|
|
|
|
</image>
|
|
|
|
EOR
|
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
rss = make_RDF(<<-EOR)
|
2004-07-06 13:43:05 -04:00
|
|
|
#{make_channel}
|
|
|
|
<image rdf:about="http://example.com/hoge.png">
|
2004-01-27 22:46:13 -05:00
|
|
|
<link>http://example.com/</link>
|
|
|
|
<url>http://example.com/hoge.png</url>
|
2004-07-06 13:43:05 -04:00
|
|
|
<title>hoge</title>
|
2004-01-27 22:46:13 -05:00
|
|
|
</image>
|
|
|
|
EOR
|
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
assert_missing_tag("item", "RDF") do
|
|
|
|
Parser.parse(rss)
|
|
|
|
end
|
2004-01-27 22:46:13 -05:00
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
assert_missing_tag("item", "RDF") do
|
|
|
|
Parser.parse(rss, false).validate
|
|
|
|
end
|
2004-01-27 22:46:13 -05:00
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
end
|
2004-01-27 22:46:13 -05:00
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
def test_item
|
2004-01-27 22:46:13 -05:00
|
|
|
|
2004-11-19 03:25:25 -05:00
|
|
|
assert_parse(make_RDF(<<-EOR), :missing_attribute, "item", "rdf:about")
|
2004-01-27 22:46:13 -05:00
|
|
|
#{make_channel}
|
|
|
|
#{make_image}
|
|
|
|
<item>
|
|
|
|
</item>
|
|
|
|
EOR
|
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
assert_parse(make_RDF(<<-EOR), :missing_tag, "title", "item")
|
2004-01-27 22:46:13 -05:00
|
|
|
#{make_channel}
|
|
|
|
#{make_image}
|
|
|
|
<item rdf:about="http://example.com/hoge.html">
|
|
|
|
</item>
|
|
|
|
EOR
|
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
assert_parse(make_RDF(<<-EOR), :missing_tag, "link", "item")
|
2004-01-27 22:46:13 -05:00
|
|
|
#{make_channel}
|
|
|
|
#{make_image}
|
|
|
|
<item rdf:about="http://example.com/hoge.html">
|
|
|
|
<title>hoge</title>
|
|
|
|
</item>
|
|
|
|
EOR
|
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
assert_too_much_tag("title", "item") do
|
|
|
|
Parser.parse(make_RDF(<<-EOR))
|
2004-01-27 22:46:13 -05:00
|
|
|
#{make_channel}
|
|
|
|
#{make_image}
|
|
|
|
<item rdf:about="http://example.com/hoge.html">
|
|
|
|
<title>hoge</title>
|
|
|
|
<title>hoge</title>
|
|
|
|
<link>http://example.com/hoge.html</link>
|
|
|
|
</item>
|
|
|
|
EOR
|
2004-10-16 00:51:15 -04:00
|
|
|
end
|
2004-01-27 22:46:13 -05:00
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
assert_parse(make_RDF(<<-EOR), :nothing_raised)
|
2004-01-27 22:46:13 -05:00
|
|
|
#{make_channel}
|
|
|
|
#{make_image}
|
|
|
|
<item rdf:about="http://example.com/hoge.html">
|
|
|
|
<title>hoge</title>
|
|
|
|
<link>http://example.com/hoge.html</link>
|
|
|
|
</item>
|
|
|
|
EOR
|
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
assert_parse(make_RDF(<<-EOR), :nothing_raised)
|
2004-01-27 22:46:13 -05:00
|
|
|
#{make_channel}
|
|
|
|
#{make_image}
|
|
|
|
<item rdf:about="http://example.com/hoge.html">
|
|
|
|
<title>hoge</title>
|
|
|
|
<link>http://example.com/hoge.html</link>
|
|
|
|
<description>hogehoge</description>
|
|
|
|
</item>
|
|
|
|
EOR
|
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
end
|
2004-01-27 22:46:13 -05:00
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
def test_textinput
|
2004-01-27 22:46:13 -05:00
|
|
|
|
2004-11-19 03:25:25 -05:00
|
|
|
assert_parse(make_RDF(<<-EOR), :missing_attribute, "textinput", "rdf:about")
|
2004-01-27 22:46:13 -05:00
|
|
|
#{make_channel}
|
|
|
|
#{make_image}
|
|
|
|
#{make_item}
|
|
|
|
<textinput>
|
|
|
|
</textinput>
|
|
|
|
EOR
|
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
assert_parse(make_RDF(<<-EOR), :missing_tag, "title", "textinput")
|
2004-01-27 22:46:13 -05:00
|
|
|
#{make_channel}
|
|
|
|
#{make_image}
|
|
|
|
#{make_item}
|
|
|
|
<textinput rdf:about="http://example.com/search.html">
|
|
|
|
</textinput>
|
|
|
|
EOR
|
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
assert_parse(make_RDF(<<-EOR), :missing_tag, "description", "textinput")
|
2004-01-27 22:46:13 -05:00
|
|
|
#{make_channel}
|
|
|
|
#{make_image}
|
|
|
|
#{make_item}
|
|
|
|
<textinput rdf:about="http://example.com/search.html">
|
|
|
|
<title>hoge</title>
|
|
|
|
</textinput>
|
|
|
|
EOR
|
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
assert_too_much_tag("title", "textinput") do
|
|
|
|
Parser.parse(make_RDF(<<-EOR))
|
2004-01-27 22:46:13 -05:00
|
|
|
#{make_channel}
|
|
|
|
#{make_image}
|
|
|
|
#{make_item}
|
|
|
|
<textinput rdf:about="http://example.com/search.html">
|
|
|
|
<title>hoge</title>
|
|
|
|
<title>hoge</title>
|
|
|
|
<description>hogehoge</description>
|
|
|
|
</textinput>
|
|
|
|
EOR
|
2004-10-16 00:51:15 -04:00
|
|
|
end
|
2004-01-27 22:46:13 -05:00
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
assert_parse(make_RDF(<<-EOR), :missing_tag, "name", "textinput")
|
2004-01-27 22:46:13 -05:00
|
|
|
#{make_channel}
|
|
|
|
#{make_image}
|
|
|
|
#{make_item}
|
|
|
|
<textinput rdf:about="http://example.com/search.html">
|
|
|
|
<title>hoge</title>
|
|
|
|
<description>hogehoge</description>
|
|
|
|
</textinput>
|
|
|
|
EOR
|
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
assert_parse(make_RDF(<<-EOR), :missing_tag, "link", "textinput")
|
2004-01-27 22:46:13 -05:00
|
|
|
#{make_channel}
|
|
|
|
#{make_image}
|
|
|
|
#{make_item}
|
|
|
|
<textinput rdf:about="http://example.com/search.html">
|
|
|
|
<title>hoge</title>
|
|
|
|
<description>hogehoge</description>
|
|
|
|
<name>key</name>
|
|
|
|
</textinput>
|
|
|
|
EOR
|
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
assert_parse(make_RDF(<<-EOR), :nothing_raised)
|
2004-01-27 22:46:13 -05:00
|
|
|
#{make_channel}
|
|
|
|
#{make_image}
|
|
|
|
#{make_item}
|
|
|
|
<textinput rdf:about="http://example.com/search.html">
|
|
|
|
<title>hoge</title>
|
|
|
|
<description>hogehoge</description>
|
|
|
|
<name>key</name>
|
|
|
|
<link>http://example.com/search.html</link>
|
|
|
|
</textinput>
|
|
|
|
EOR
|
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
end
|
2004-01-27 22:46:13 -05:00
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
def test_rss20
|
|
|
|
|
|
|
|
assert_parse(make_rss20(<<-EOR), :missing_tag, "channel", "rss")
|
2004-07-06 13:43:05 -04:00
|
|
|
EOR
|
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
assert_parse(make_rss20(<<-EOR), :nothing_raised)
|
2004-07-06 13:43:05 -04:00
|
|
|
#{make_channel20("")}
|
|
|
|
EOR
|
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
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)
|
2004-07-06 13:43:05 -04:00
|
|
|
#{make_channel20(%Q[<cloud #{cloud_attrs.join("\n")}/>])}
|
|
|
|
EOR
|
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
end
|
2004-07-06 13:43:05 -04:00
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
end
|
2004-07-06 13:43:05 -04:00
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
def test_source20
|
2004-07-06 13:43:05 -04:00
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
assert_parse(make_rss20(<<-EOR), :missing_attribute, "source", "url")
|
2004-07-06 13:43:05 -04:00
|
|
|
#{make_channel20(make_item20(%Q[<source>Example</source>]))}
|
|
|
|
EOR
|
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
assert_parse(make_rss20(<<-EOR), :nothing_raised)
|
2004-07-06 13:43:05 -04:00
|
|
|
#{make_channel20(make_item20(%Q[<source url="http://example.com/" />]))}
|
|
|
|
EOR
|
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
assert_parse(make_rss20(<<-EOR), :nothing_raised)
|
2004-07-06 13:43:05 -04:00
|
|
|
#{make_channel20(make_item20(%Q[<source url="http://example.com/">Example</source>]))}
|
|
|
|
EOR
|
2004-10-16 00:51:15 -04:00
|
|
|
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)
|
2004-07-06 13:43:05 -04:00
|
|
|
#{make_channel20(%Q[
|
|
|
|
#{make_item20(%Q[
|
|
|
|
<enclosure
|
|
|
|
#{enclosure_attrs.join("\n")} />
|
2004-10-16 00:51:15 -04:00
|
|
|
])}
|
|
|
|
])}
|
|
|
|
EOR
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_category20
|
2005-07-08 02:51:21 -04:00
|
|
|
values = [nil, CATEGORY_DOMAIN]
|
2004-10-16 00:51:15 -04:00
|
|
|
|
2005-07-08 02:51:21 -04:00
|
|
|
values.each do |value|
|
|
|
|
domain = ""
|
|
|
|
domain << %Q[domain="#{value}"] if value
|
2004-10-16 00:51:15 -04:00
|
|
|
|
|
|
|
["", "Example Text"].each do |text|
|
2005-07-08 02:51:21 -04:00
|
|
|
rss_src = make_rss20(<<-EOR)
|
2004-07-06 13:43:05 -04:00
|
|
|
#{make_channel20(%Q[
|
|
|
|
#{make_item20(%Q[
|
2005-07-08 02:51:21 -04:00
|
|
|
<category #{domain}>#{text}</category>
|
2004-10-16 00:51:15 -04:00
|
|
|
])}
|
|
|
|
])}
|
2004-07-06 13:43:05 -04:00
|
|
|
EOR
|
2005-07-08 02:51:21 -04:00
|
|
|
assert_parse(rss_src, :nothing_raised)
|
|
|
|
|
|
|
|
rss = RSS::Parser.parse(rss_src)
|
|
|
|
category = rss.items.last.categories.first
|
|
|
|
assert_equal(value, category.domain)
|
|
|
|
assert_equal(text, category.content)
|
2004-10-16 00:51:15 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2004-07-06 13:43:05 -04:00
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
def test_ignore
|
2004-01-27 22:46:13 -05:00
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
rss = make_RDF(<<-EOR)
|
2004-01-27 22:46:13 -05:00
|
|
|
#{make_channel}
|
|
|
|
#{make_item}
|
|
|
|
<a/>
|
|
|
|
EOR
|
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
assert_parse(rss, :nothing_raised)
|
2004-03-21 05:03:17 -05:00
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
assert_not_excepted_tag("a", "RDF") do
|
|
|
|
Parser.parse(rss, true, false)
|
|
|
|
end
|
2004-01-27 22:46:13 -05:00
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
end
|
2004-01-27 22:46:13 -05:00
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
def test_default_parser
|
2005-07-22 01:41:33 -04:00
|
|
|
assert_nothing_raised do
|
2004-10-16 00:51:15 -04:00
|
|
|
Parser.default_parser = RSS::AVAILABLE_PARSERS.first
|
|
|
|
end
|
2004-01-27 22:46:13 -05:00
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
assert_raise(RSS::NotValidXMLParser) do
|
|
|
|
Parser.default_parser = RSS::Parser
|
|
|
|
end
|
|
|
|
end
|
2004-01-31 11:10:53 -05:00
|
|
|
|
2005-07-22 01:41:33 -04:00
|
|
|
def test_parse
|
|
|
|
assert_not_nil(RSS::Parser.parse(@rss_file))
|
|
|
|
|
|
|
|
garbage_rss_file = @rss_file + "-garbage"
|
|
|
|
if RSS::Parser.default_parser.name == "RSS::XMLParserParser"
|
|
|
|
assert_raise(RSS::NotWellFormedError) do
|
|
|
|
RSS::Parser.parse(garbage_rss_file)
|
|
|
|
end
|
|
|
|
else
|
|
|
|
assert_nil(RSS::Parser.parse(garbage_rss_file))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
end
|
2004-01-27 22:46:13 -05:00
|
|
|
end
|
2004-03-21 05:03:17 -05:00
|
|
|
|