2015-12-16 00:07:31 -05:00
|
|
|
# frozen_string_literal: false
|
2013-01-19 20:19:44 -05:00
|
|
|
require "tempfile"
|
2005-07-22 01:41:33 -04:00
|
|
|
|
2013-02-24 08:10:46 -05:00
|
|
|
require_relative "rss-testcase"
|
2004-03-21 05:03:17 -05:00
|
|
|
|
2004-01-27 22:46:13 -05:00
|
|
|
require "rss/1.0"
|
2004-07-06 13:43:05 -04:00
|
|
|
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
|
2013-01-19 20:19:44 -05:00
|
|
|
@rss_tmp = Tempfile.new(%w"rss10- .rdf")
|
|
|
|
@rss_tmp.print(@rss10)
|
|
|
|
@rss_tmp.close
|
2013-06-13 01:41:44 -04:00
|
|
|
@rss_file = @rss_tmp.path.untaint
|
2004-10-16 00:51:15 -04:00
|
|
|
end
|
2007-08-04 23:03:05 -04:00
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
def teardown
|
|
|
|
Parser.default_parser = @_default_parser
|
2013-01-19 20:19:44 -05:00
|
|
|
@rss_tmp.close(true)
|
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
|
2007-12-27 23:20:47 -05:00
|
|
|
|
|
|
|
def test_parse_tag_includes_hyphen
|
|
|
|
assert_nothing_raised do
|
|
|
|
RSS::Parser.parse(make_RDF(<<-EOR))
|
|
|
|
<xCal:x-calconnect-venue xmlns:xCal="urn:ietf:params:xml:ns:xcal" />
|
|
|
|
#{make_channel}
|
|
|
|
#{make_item}
|
|
|
|
#{make_textinput}
|
|
|
|
#{make_image}
|
|
|
|
EOR
|
|
|
|
end
|
|
|
|
end
|
2004-10-16 00:51:15 -04:00
|
|
|
end
|
2004-01-27 22:46:13 -05:00
|
|
|
end
|