mirror of
				https://github.com/ruby/ruby.git
				synced 2022-11-09 12:17:21 -05:00 
			
		
		
		
	* test/rss/*: Test::Unit::TestCase -> RSS::TestCase and
Test::Unit::Assertions -> RSS::Assertions. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@5991 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
		
							parent
							
								
									cfbe158fae
								
							
						
					
					
						commit
						abe876ed4e
					
				
					 12 changed files with 1036 additions and 1009 deletions
				
			
		|  | @ -1,130 +1,138 @@ | |||
| # -*- tab-width: 2 -*- vim: ts=2 | ||||
| 
 | ||||
| require "test/unit" | ||||
| require "rss/1.0" | ||||
| require "common" | ||||
| require "rss-testcase" | ||||
| 
 | ||||
| class TestParser < Test::Unit::TestCase | ||||
| 	include TestRSSMixin | ||||
| 	 | ||||
| 	def test_RDF | ||||
| 		assert_ns("", RDF::URI) do | ||||
| 			Parser.parse(<<-EOR) | ||||
| require "rss/1.0" | ||||
| 
 | ||||
| module RSS | ||||
| 	class TestParser < TestCase | ||||
| 		 | ||||
| 		def setup | ||||
| 			@_default_parser = Parser.default_parser | ||||
| 		end | ||||
| 		 | ||||
| 		def teardown | ||||
| 			Parser.default_parser = @_default_parser | ||||
| 		end | ||||
| 		 | ||||
| 		def test_RDF | ||||
| 			assert_ns("", RDF::URI) do | ||||
| 				Parser.parse(<<-EOR) | ||||
| #{make_xmldecl} | ||||
| <RDF/> | ||||
| EOR | ||||
| 		end  | ||||
| 			end  | ||||
| 
 | ||||
| 		assert_ns("", RDF::URI) do | ||||
| 			Parser.parse(<<-EOR) | ||||
| 			assert_ns("", RDF::URI) do | ||||
| 				Parser.parse(<<-EOR) | ||||
| #{make_xmldecl} | ||||
| <RDF xmlns="hoge"/> | ||||
| EOR | ||||
| 		end  | ||||
| 			end  | ||||
| 
 | ||||
| 		assert_ns("rdf", RDF::URI) do | ||||
| 			Parser.parse(<<-EOR) | ||||
| 			assert_ns("rdf", RDF::URI) do | ||||
| 				Parser.parse(<<-EOR) | ||||
| #{make_xmldecl} | ||||
| <rdf:RDF xmlns:rdf="hoge"/> | ||||
| EOR | ||||
| 		end | ||||
| 			end | ||||
| 
 | ||||
| 		assert_parse(<<-EOR, :missing_tag, "channel", "RDF") | ||||
| 			assert_parse(<<-EOR, :missing_tag, "channel", "RDF") | ||||
| #{make_xmldecl} | ||||
| <rdf:RDF xmlns:rdf="#{RSS::RDF::URI}"/> | ||||
| EOR | ||||
| 
 | ||||
| 		assert_parse(<<-EOR, :missing_tag, "channel", "RDF") | ||||
| 			assert_parse(<<-EOR, :missing_tag, "channel", "RDF") | ||||
| #{make_xmldecl} | ||||
| <RDF xmlns="#{RSS::RDF::URI}"/> | ||||
| EOR | ||||
| 
 | ||||
| 		assert_parse(<<-EOR, :missing_tag, "channel", "RDF") | ||||
| 			assert_parse(<<-EOR, :missing_tag, "channel", "RDF") | ||||
| #{make_xmldecl} | ||||
| <RDF xmlns="#{RSS::RDF::URI}"/> | ||||
| EOR | ||||
| 
 | ||||
| 		assert_parse(make_RDF(<<-EOR), :missing_tag, "item", "RDF") | ||||
| 			assert_parse(make_RDF(<<-EOR), :missing_tag, "item", "RDF") | ||||
| #{make_channel} | ||||
| EOR | ||||
| 
 | ||||
| 		assert_parse(make_RDF(<<-EOR), :missing_tag, "item", "RDF") | ||||
| 			assert_parse(make_RDF(<<-EOR), :missing_tag, "item", "RDF") | ||||
| #{make_channel} | ||||
| #{make_image} | ||||
| EOR | ||||
| 
 | ||||
| 		assert_parse(make_RDF(<<-EOR), :missing_tag, "item", "RDF") | ||||
| 			assert_parse(make_RDF(<<-EOR), :missing_tag, "item", "RDF") | ||||
| #{make_channel} | ||||
| #{make_textinput} | ||||
| EOR | ||||
| 
 | ||||
| 		assert_too_much_tag("image", "RDF") do | ||||
| 			Parser.parse(make_RDF(<<-EOR)) | ||||
| 			assert_too_much_tag("image", "RDF") do | ||||
| 				Parser.parse(make_RDF(<<-EOR)) | ||||
| #{make_channel} | ||||
| #{make_image} | ||||
| #{make_image} | ||||
| #{make_item} | ||||
| #{make_textinput} | ||||
| EOR | ||||
| 		end | ||||
| 
 | ||||
| 		assert_not_excepted_tag("image", "RDF") do | ||||
| 			Parser.parse(make_RDF(<<-EOR)) | ||||
| #{make_channel} | ||||
| #{make_item} | ||||
| #{make_image} | ||||
| #{make_textinput} | ||||
| EOR | ||||
| 		end | ||||
| 
 | ||||
| 		assert_parse(make_RDF(<<-EOR), :nothing_raised) | ||||
| #{make_channel} | ||||
| #{make_image} | ||||
| #{make_item} | ||||
| EOR | ||||
| 
 | ||||
| 		assert_parse(make_RDF(<<-EOR), :nothing_raised) | ||||
| #{make_channel} | ||||
| #{make_image} | ||||
| #{make_item} | ||||
| #{make_textinput} | ||||
| EOR | ||||
| 
 | ||||
| 		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) | ||||
| 
 | ||||
| 			assert_not_excepted_tag("image", "RDF") do | ||||
| 				Parser.parse(make_RDF(<<-EOR)) | ||||
| #{make_channel} | ||||
| #{make_item} | ||||
| #{make_image} | ||||
| #{make_textinput} | ||||
| EOR | ||||
| 			end | ||||
| 
 | ||||
| 			assert_parse(make_RDF(<<-EOR), :nothing_raised) | ||||
| #{make_channel} | ||||
| #{make_image} | ||||
| #{make_item} | ||||
| EOR | ||||
| 
 | ||||
| 			assert_parse(make_RDF(<<-EOR), :nothing_raised) | ||||
| #{make_channel} | ||||
| #{make_image} | ||||
| #{make_item} | ||||
| #{make_textinput} | ||||
| EOR | ||||
| 
 | ||||
| 			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 | ||||
| 
 | ||||
| 		end | ||||
| 
 | ||||
| 	end | ||||
| 		def test_channel | ||||
| 
 | ||||
| 	def test_channel | ||||
| 
 | ||||
| 		assert_parse(make_RDF(<<-EOR), :missing_attribute, "channel", "about") | ||||
| 			assert_parse(make_RDF(<<-EOR), :missing_attribute, "channel", "about") | ||||
| <channel /> | ||||
| EOR | ||||
| 
 | ||||
| 		assert_parse(make_RDF(<<-EOR), :missing_tag, "title", "channel") | ||||
| 			assert_parse(make_RDF(<<-EOR), :missing_tag, "title", "channel") | ||||
| <channel rdf:about="http://example.com/"/> | ||||
| EOR | ||||
| 
 | ||||
| 		assert_parse(make_RDF(<<-EOR), :missing_tag, "link", "channel") | ||||
| 			assert_parse(make_RDF(<<-EOR), :missing_tag, "link", "channel") | ||||
| <channel rdf:about="http://example.com/"> | ||||
|   <title>hoge</title> | ||||
| </channel> | ||||
| EOR | ||||
| 
 | ||||
| 		assert_parse(make_RDF(<<EOR), :missing_tag, "description", "channel") | ||||
| 			assert_parse(make_RDF(<<EOR), :missing_tag, "description", "channel") | ||||
| <channel rdf:about="http://example.com/"> | ||||
|   <title>hoge</title> | ||||
|   <link>http://example.com/</link> | ||||
| </channel> | ||||
| EOR | ||||
| 
 | ||||
| 		assert_parse(make_RDF(<<-EOR), :missing_tag, "items", "channel") | ||||
| 			assert_parse(make_RDF(<<-EOR), :missing_tag, "items", "channel") | ||||
| <channel rdf:about="http://example.com/"> | ||||
|   <title>hoge</title> | ||||
|   <link>http://example.com/</link> | ||||
|  | @ -132,7 +140,7 @@ EOR | |||
| </channel> | ||||
| EOR | ||||
| 
 | ||||
| 		assert_parse(make_RDF(<<-EOR), :missing_attribute, "image", "resource") | ||||
| 			assert_parse(make_RDF(<<-EOR), :missing_attribute, "image", "resource") | ||||
| <channel rdf:about="http://example.com/"> | ||||
|   <title>hoge</title> | ||||
|   <link>http://example.com/</link> | ||||
|  | @ -141,7 +149,7 @@ EOR | |||
| </channel> | ||||
| EOR | ||||
| 
 | ||||
| 		assert_parse(make_RDF(<<-EOR), :missing_tag, "items", "channel") | ||||
| 			assert_parse(make_RDF(<<-EOR), :missing_tag, "items", "channel") | ||||
| <channel rdf:about="http://example.com/"> | ||||
|   <title>hoge</title> | ||||
|   <link>http://example.com/</link> | ||||
|  | @ -150,7 +158,7 @@ EOR | |||
| </channel> | ||||
| EOR | ||||
| 
 | ||||
| 		rss = make_RDF(<<-EOR) | ||||
| 			rss = make_RDF(<<-EOR) | ||||
| <channel rdf:about="http://example.com/"> | ||||
|   <title>hoge</title> | ||||
|   <link>http://example.com/</link> | ||||
|  | @ -160,15 +168,15 @@ EOR | |||
| </channel> | ||||
| EOR | ||||
| 
 | ||||
| 		assert_missing_tag("Seq", "items") do | ||||
| 			Parser.parse(rss) | ||||
| 		end | ||||
| 			assert_missing_tag("Seq", "items") do | ||||
| 				Parser.parse(rss) | ||||
| 			end | ||||
| 
 | ||||
| 		assert_missing_tag("item", "RDF") do | ||||
| 			Parser.parse(rss, false).validate | ||||
| 		end | ||||
| 			assert_missing_tag("item", "RDF") do | ||||
| 				Parser.parse(rss, false).validate | ||||
| 			end | ||||
| 
 | ||||
| 		assert_parse(make_RDF(<<-EOR), :missing_tag, "item", "RDF") | ||||
| 			assert_parse(make_RDF(<<-EOR), :missing_tag, "item", "RDF") | ||||
| <channel rdf:about="http://example.com/"> | ||||
|   <title>hoge</title> | ||||
|   <link>http://example.com/</link> | ||||
|  | @ -181,7 +189,7 @@ EOR | |||
| </channel> | ||||
| EOR | ||||
| 
 | ||||
| 		assert_parse(make_RDF(<<-EOR), :missing_attribute, "textinput", "resource") | ||||
| 			assert_parse(make_RDF(<<-EOR), :missing_attribute, "textinput", "resource") | ||||
| <channel rdf:about="http://example.com/"> | ||||
|   <title>hoge</title> | ||||
|   <link>http://example.com/</link> | ||||
|  | @ -195,7 +203,7 @@ EOR | |||
| </channel> | ||||
| EOR | ||||
| 
 | ||||
| 		assert_parse(make_RDF(<<-EOR), :missing_tag, "item", "RDF") | ||||
| 			assert_parse(make_RDF(<<-EOR), :missing_tag, "item", "RDF") | ||||
| <channel rdf:about="http://example.com/"> | ||||
|   <title>hoge</title> | ||||
|   <link>http://example.com/</link> | ||||
|  | @ -209,30 +217,30 @@ EOR | |||
| </channel> | ||||
| EOR | ||||
| 
 | ||||
| 	end | ||||
| 		end | ||||
| 
 | ||||
|   def test_image | ||||
| 	  def test_image | ||||
| 
 | ||||
| 		assert_parse(make_RDF(<<-EOR), :missing_attribute, "image", "about") | ||||
| 			assert_parse(make_RDF(<<-EOR), :missing_attribute, "image", "about") | ||||
| #{make_channel} | ||||
| <image> | ||||
| </image> | ||||
| EOR | ||||
| 
 | ||||
| 		assert_parse(make_RDF(<<-EOR), :missing_tag, "title", "image") | ||||
| 			assert_parse(make_RDF(<<-EOR), :missing_tag, "title", "image") | ||||
| #{make_channel} | ||||
| <image rdf:about="http://example.com/hoge.png"> | ||||
| </image> | ||||
| EOR | ||||
| 
 | ||||
| 		assert_parse(make_RDF(<<-EOR), :missing_tag, "url", "image") | ||||
| 			assert_parse(make_RDF(<<-EOR), :missing_tag, "url", "image") | ||||
| #{make_channel} | ||||
| <image rdf:about="http://example.com/hoge.png"> | ||||
|   <title>hoge</title> | ||||
| </image> | ||||
| EOR | ||||
| 
 | ||||
| 		assert_parse(make_RDF(<<-EOR), :missing_tag, "link", "image") | ||||
| 			assert_parse(make_RDF(<<-EOR), :missing_tag, "link", "image") | ||||
| #{make_channel} | ||||
| <image rdf:about="http://example.com/hoge.png"> | ||||
|   <title>hoge</title> | ||||
|  | @ -240,7 +248,7 @@ EOR | |||
| </image> | ||||
| EOR | ||||
| 
 | ||||
| 		rss = make_RDF(<<-EOR) | ||||
| 			rss = make_RDF(<<-EOR) | ||||
| #{make_channel} | ||||
| <image rdf:about="http://example.com/hoge.png"> | ||||
|   <title>hoge</title> | ||||
|  | @ -249,15 +257,15 @@ EOR | |||
| </image> | ||||
| EOR | ||||
| 
 | ||||
| 		assert_missing_tag("url", "image") do | ||||
| 			Parser.parse(rss) | ||||
| 		end | ||||
| 			assert_missing_tag("url", "image") do | ||||
| 				Parser.parse(rss) | ||||
| 			end | ||||
| 
 | ||||
| 		assert_missing_tag("item", "RDF") do | ||||
| 			Parser.parse(rss, false).validate | ||||
| 		end | ||||
| 			assert_missing_tag("item", "RDF") do | ||||
| 				Parser.parse(rss, false).validate | ||||
| 			end | ||||
| 
 | ||||
| 		assert_parse(make_RDF(<<-EOR), :missing_tag, "item", "RDF") | ||||
| 			assert_parse(make_RDF(<<-EOR), :missing_tag, "item", "RDF") | ||||
| #{make_channel} | ||||
| <image rdf:about="http://example.com/hoge.png"> | ||||
|   <title>hoge</title> | ||||
|  | @ -266,25 +274,25 @@ EOR | |||
| </image> | ||||
| EOR | ||||
| 
 | ||||
|   end | ||||
| 	  end | ||||
| 
 | ||||
| 	def test_item | ||||
| 		def test_item | ||||
| 
 | ||||
| 		assert_parse(make_RDF(<<-EOR), :missing_attribute, "item", "about") | ||||
| 			assert_parse(make_RDF(<<-EOR), :missing_attribute, "item", "about") | ||||
| #{make_channel} | ||||
| #{make_image} | ||||
| <item> | ||||
| </item> | ||||
| EOR | ||||
| 
 | ||||
| 		assert_parse(make_RDF(<<-EOR), :missing_tag, "title", "item") | ||||
| 			assert_parse(make_RDF(<<-EOR), :missing_tag, "title", "item") | ||||
| #{make_channel} | ||||
| #{make_image} | ||||
| <item rdf:about="http://example.com/hoge.html"> | ||||
| </item> | ||||
| EOR | ||||
| 
 | ||||
| 		assert_parse(make_RDF(<<-EOR), :missing_tag, "link", "item") | ||||
| 			assert_parse(make_RDF(<<-EOR), :missing_tag, "link", "item") | ||||
| #{make_channel} | ||||
| #{make_image} | ||||
| <item rdf:about="http://example.com/hoge.html"> | ||||
|  | @ -292,8 +300,8 @@ EOR | |||
| </item> | ||||
| EOR | ||||
| 
 | ||||
| 		assert_too_much_tag("title", "item") do | ||||
| 			Parser.parse(make_RDF(<<-EOR)) | ||||
| 			assert_too_much_tag("title", "item") do | ||||
| 				Parser.parse(make_RDF(<<-EOR)) | ||||
| #{make_channel} | ||||
| #{make_image} | ||||
| <item rdf:about="http://example.com/hoge.html"> | ||||
|  | @ -302,9 +310,9 @@ EOR | |||
|   <link>http://example.com/hoge.html</link> | ||||
| </item> | ||||
| EOR | ||||
| 		end | ||||
| 			end | ||||
| 
 | ||||
| 		assert_parse(make_RDF(<<-EOR), :nothing_raised) | ||||
| 			assert_parse(make_RDF(<<-EOR), :nothing_raised) | ||||
| #{make_channel} | ||||
| #{make_image} | ||||
| <item rdf:about="http://example.com/hoge.html"> | ||||
|  | @ -313,7 +321,7 @@ EOR | |||
| </item> | ||||
| EOR | ||||
| 
 | ||||
| 		assert_parse(make_RDF(<<-EOR), :nothing_raised) | ||||
| 			assert_parse(make_RDF(<<-EOR), :nothing_raised) | ||||
| #{make_channel} | ||||
| #{make_image} | ||||
| <item rdf:about="http://example.com/hoge.html"> | ||||
|  | @ -323,11 +331,11 @@ EOR | |||
| </item> | ||||
| EOR | ||||
| 
 | ||||
| 	end | ||||
| 		end | ||||
| 
 | ||||
| 	def test_textinput | ||||
| 		def test_textinput | ||||
| 
 | ||||
| 		assert_parse(make_RDF(<<-EOR), :missing_attribute, "textinput", "about") | ||||
| 			assert_parse(make_RDF(<<-EOR), :missing_attribute, "textinput", "about") | ||||
| #{make_channel} | ||||
| #{make_image} | ||||
| #{make_item} | ||||
|  | @ -335,7 +343,7 @@ EOR | |||
| </textinput> | ||||
| EOR | ||||
| 
 | ||||
| 		assert_parse(make_RDF(<<-EOR), :missing_tag, "title", "textinput") | ||||
| 			assert_parse(make_RDF(<<-EOR), :missing_tag, "title", "textinput") | ||||
| #{make_channel} | ||||
| #{make_image} | ||||
| #{make_item} | ||||
|  | @ -343,7 +351,7 @@ EOR | |||
| </textinput> | ||||
| EOR | ||||
| 
 | ||||
| 		assert_parse(make_RDF(<<-EOR), :missing_tag, "description", "textinput") | ||||
| 			assert_parse(make_RDF(<<-EOR), :missing_tag, "description", "textinput") | ||||
| #{make_channel} | ||||
| #{make_image} | ||||
| #{make_item} | ||||
|  | @ -352,8 +360,8 @@ EOR | |||
| </textinput> | ||||
| EOR | ||||
| 
 | ||||
| 		assert_too_much_tag("title", "textinput") do | ||||
| 			Parser.parse(make_RDF(<<-EOR)) | ||||
| 			assert_too_much_tag("title", "textinput") do | ||||
| 				Parser.parse(make_RDF(<<-EOR)) | ||||
| #{make_channel} | ||||
| #{make_image} | ||||
| #{make_item} | ||||
|  | @ -363,9 +371,9 @@ EOR | |||
|   <description>hogehoge</description> | ||||
| </textinput> | ||||
| EOR | ||||
| 		end | ||||
| 			end | ||||
| 
 | ||||
| 		assert_parse(make_RDF(<<-EOR), :missing_tag, "name", "textinput") | ||||
| 			assert_parse(make_RDF(<<-EOR), :missing_tag, "name", "textinput") | ||||
| #{make_channel} | ||||
| #{make_image} | ||||
| #{make_item} | ||||
|  | @ -375,7 +383,7 @@ EOR | |||
| </textinput> | ||||
| EOR | ||||
| 
 | ||||
| 		assert_parse(make_RDF(<<-EOR), :missing_tag, "link", "textinput") | ||||
| 			assert_parse(make_RDF(<<-EOR), :missing_tag, "link", "textinput") | ||||
| #{make_channel} | ||||
| #{make_image} | ||||
| #{make_item} | ||||
|  | @ -386,7 +394,7 @@ EOR | |||
| </textinput> | ||||
| EOR | ||||
| 
 | ||||
| 		assert_parse(make_RDF(<<-EOR), :nothing_raised) | ||||
| 			assert_parse(make_RDF(<<-EOR), :nothing_raised) | ||||
| #{make_channel} | ||||
| #{make_image} | ||||
| #{make_item} | ||||
|  | @ -398,32 +406,34 @@ EOR | |||
| </textinput> | ||||
| EOR | ||||
| 
 | ||||
| 	end | ||||
| 		end | ||||
| 
 | ||||
| 	def test_ignore | ||||
| 		def test_ignore | ||||
| 
 | ||||
| 		rss = make_RDF(<<-EOR) | ||||
| 			rss = make_RDF(<<-EOR) | ||||
| #{make_channel} | ||||
| #{make_item} | ||||
| <a/> | ||||
| EOR | ||||
| 
 | ||||
| 		assert_parse(rss, :nothing_raised) | ||||
| 			assert_parse(rss, :nothing_raised) | ||||
| 
 | ||||
| 		assert_not_excepted_tag("a", "RDF") do | ||||
| 			Parser.parse(rss, true, false) | ||||
| 			assert_not_excepted_tag("a", "RDF") do | ||||
| 				Parser.parse(rss, true, false) | ||||
| 			end | ||||
| 
 | ||||
| 		end | ||||
| 
 | ||||
| 		def test_default_parser | ||||
| 			assert_nothing_raised() do | ||||
| 				Parser.default_parser = RSS::AVAILABLE_PARSERS.first | ||||
| 			end | ||||
| 
 | ||||
| 			assert_raise(RSS::NotValidXMLParser) do | ||||
| 				Parser.default_parser = RSS::Parser | ||||
| 			end | ||||
| 		end | ||||
| 
 | ||||
| 	end | ||||
| 
 | ||||
| 	def test_default_parser | ||||
| 		assert_nothing_raised() do | ||||
| 			Parser.default_parser = RSS::AVAILABLE_PARSERS.first | ||||
| 		end | ||||
| 
 | ||||
| 		assert_raise(RSS::NotValidXMLParser) do | ||||
| 			Parser.default_parser = RSS::Parser | ||||
| 		end | ||||
| 	end | ||||
| 
 | ||||
| end | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 kou
						kou