diff options
author | kou <kou@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2006-06-17 01:37:08 +0000 |
---|---|---|
committer | kou <kou@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2006-06-17 01:37:08 +0000 |
commit | faeff623e09cb77c23a93b56001b51b043b5aa6a (patch) | |
tree | e9fb92ee7006fa7d105d055510238effea9a63ec /test | |
parent | 02cce7ed8273bab55081357c57f24a8265a6f32a (diff) |
* lib/rss/rss.rb (Hash#merge, Enumerable#sort_by): removed.
* lib/rss/rss.rb (RSS::RootElementMixin#to_xml): added.
[ruby-talk:197284]
We can convert RSS version easily like the following:
rss10 = RSS::Parser.parse(File.read("1.0.rdf"))
File.open("2.0.rss", "w") {|f| f.print(rss10.to_xml("2.0"))}
* test/rss/test_1.0.rb: added #to_xml test.
* test/rss/test_2.0.rb: ditto.
* test/rss/rss-testcase.rb: added some helper methods that
generates sample RSS 2.0.
* sample/rss/convert.rb: added a sample script to convert RSS format.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@10301 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r-- | test/rss/rss-testcase.rb | 17 | ||||
-rw-r--r-- | test/rss/test_1.0.rb | 13 | ||||
-rw-r--r-- | test/rss/test_2.0.rb | 15 |
3 files changed, 43 insertions, 2 deletions
diff --git a/test/rss/rss-testcase.rb b/test/rss/rss-testcase.rb index 0612abcccd..21670bc05c 100644 --- a/test/rss/rss-testcase.rb +++ b/test/rss/rss-testcase.rb @@ -140,6 +140,15 @@ EOR EORSS end + def make_sample_items20 + RESOURCES.collect do |res| + elems = ["<link>#{res}</link>"] + elems << "<title>title of #{res}</title>" + elems = elems.join("\n") + item = "<item>\n#{elems}\n</item>" + end.join("\n") + end + def make_channel20(content=nil) <<-EOC <channel> @@ -154,7 +163,7 @@ EORSS <link>#{LINK_VALUE}</link> </image> -#{RESOURCES.collect do |res| '<item><link>' + res + '</link></item>' end.join("\n")} +#{make_sample_items20} <textInput> <title>#{TITLE_VALUE}</title> @@ -190,6 +199,12 @@ EOI EOC end + def make_sample_rss20 + make_rss20(<<-EOR) +#{make_channel20} +EOR + end + def make_element(elem_name, attrs, contents) attrs_str = attrs.collect do |name, value| "#{h name}='#{h value}'" diff --git a/test/rss/test_1.0.rb b/test/rss/test_1.0.rb index b905ba6e94..3266e00393 100644 --- a/test/rss/test_1.0.rb +++ b/test/rss/test_1.0.rb @@ -233,6 +233,19 @@ module RSS end end + def test_to_xml + rss = RSS::Parser.parse(make_sample_RDF) + assert_equal(rss.to_s, rss.to_xml) + assert_equal(rss.to_s, rss.to_xml("1.0")) + rss09 = rss.to_xml("0.91") do |maker| + maker.channel.language = "en-us" + end + rss09 = RSS::Parser.parse(rss09) + assert_equal("0.91", rss09.rss_version) + rss20 = RSS::Parser.parse(rss.to_xml("2.0")) + assert_equal("2.0", rss20.rss_version) + end + def test_indent_size assert_equal(0, RDF.indent_size) assert_equal(1, RDF::Channel.indent_size) diff --git a/test/rss/test_2.0.rb b/test/rss/test_2.0.rb index 2027e5344a..b0e6b17165 100644 --- a/test/rss/test_2.0.rb +++ b/test/rss/test_2.0.rb @@ -373,7 +373,20 @@ module RSS end assert_equal(source_params, actual) end - + + def test_to_xml + rss = RSS::Parser.parse(make_sample_rss20) + assert_equal(rss.to_s, rss.to_xml) + assert_equal(rss.to_s, rss.to_xml("2.0")) + rss09 = RSS::Parser.parse(rss.to_xml("0.91")) + assert_equal("0.91", rss09.rss_version) + rss10 = rss.to_xml("1.0") do |maker| + maker.channel.about = "http://www.example.com/index.rdf" + end + rss10 = RSS::Parser.parse(rss10) + assert_equal("1.0", rss10.rss_version) + end + def test_indent_size assert_equal(0, Rss.indent_size) assert_equal(1, Rss::Channel.indent_size) |