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,3 +1,8 @@
|
|||
Sun Mar 21 18:57:37 2004 Kouhei Sutou <kou@cozmixng.org>
|
||||
|
||||
* test/rss/*: Test::Unit::TestCase -> RSS::TestCase and
|
||||
Test::Unit::Assertions -> RSS::Assertions.
|
||||
|
||||
Sun Mar 21 18:48:20 2004 Kouhei Sutou <kou@cozmixng.org>
|
||||
|
||||
* lib/rss/{rss,dublincore,syndication}.rb: handled W3CDTF correctly.
|
||||
|
|
|
@ -1,130 +0,0 @@
|
|||
# -*- tab-width: 2 -*- vim: ts=2
|
||||
|
||||
module Test
|
||||
module Unit
|
||||
module Assertions
|
||||
|
||||
def assert_parse(rss, assert_method, *args)
|
||||
send("assert_#{assert_method}", *args) do
|
||||
::RSS::Parser.parse(rss)
|
||||
end
|
||||
send("assert_#{assert_method}", *args) do
|
||||
::RSS::Parser.parse(rss, false).validate
|
||||
end
|
||||
end
|
||||
|
||||
def assert_ns(prefix, uri)
|
||||
_wrap_assertion do
|
||||
begin
|
||||
yield
|
||||
flunk("Not raise NSError")
|
||||
rescue ::RSS::NSError => e
|
||||
assert_equal(prefix, e.prefix)
|
||||
assert_equal(uri, e.uri)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def assert_missing_tag(tag, parent)
|
||||
_wrap_assertion do
|
||||
begin
|
||||
yield
|
||||
flunk("Not raise MissingTagError")
|
||||
rescue ::RSS::MissingTagError => e
|
||||
assert_equal(tag, e.tag)
|
||||
assert_equal(parent, e.parent)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def assert_too_much_tag(tag, parent)
|
||||
_wrap_assertion do
|
||||
begin
|
||||
yield
|
||||
flunk("Not raise TooMuchTagError")
|
||||
rescue ::RSS::TooMuchTagError => e
|
||||
assert_equal(tag, e.tag)
|
||||
assert_equal(parent, e.parent)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def assert_missing_attribute(tag, attrname)
|
||||
_wrap_assertion do
|
||||
begin
|
||||
yield
|
||||
flunk("Not raise MissingAttributeError")
|
||||
rescue ::RSS::MissingAttributeError => e
|
||||
assert_equal(tag, e.tag)
|
||||
assert_equal(attrname, e.attribute)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def assert_not_excepted_tag(tag, parent)
|
||||
_wrap_assertion do
|
||||
begin
|
||||
yield
|
||||
flunk("Not raise NotExceptedTagError")
|
||||
rescue ::RSS::NotExceptedTagError => e
|
||||
assert_equal(tag, e.tag)
|
||||
assert_equal(parent, e.parent)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def assert_not_available_value(tag, value)
|
||||
_wrap_assertion do
|
||||
begin
|
||||
yield
|
||||
flunk("Not raise NotAvailableValueError")
|
||||
rescue ::RSS::NotAvailableValueError => e
|
||||
assert_equal(tag, e.tag)
|
||||
assert_equal(value, e.value)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def assert_xml_stylesheet_attrs(xsl, attrs)
|
||||
_wrap_assertion do
|
||||
normalized_attrs = {}
|
||||
attrs.each do |name, value|
|
||||
normalized_attrs[name.to_s] = value
|
||||
end
|
||||
::RSS::XMLStyleSheet::ATTRIBUTES.each do |name|
|
||||
assert_equal(normalized_attrs[name], xsl.send(name))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def assert_xml_stylesheet(target, xsl, attrs)
|
||||
_wrap_assertion do
|
||||
if attrs.has_key?(:href)
|
||||
if !attrs.has_key?(:type) and attrs.has_key?(:guess_type)
|
||||
attrs[:type] = attrs[:guess_type]
|
||||
end
|
||||
assert_equal("xml-stylesheet", target)
|
||||
assert_xml_stylesheet_attrs(xsl, attrs)
|
||||
else
|
||||
assert_nil(target)
|
||||
assert_equal("", xsl.to_s)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def assert_xml_stylesheet_pis(attrs_ary)
|
||||
rdf = ::RSS::RDF.new()
|
||||
xss_strs = []
|
||||
attrs_ary.each do |attrs|
|
||||
xss = ::RSS::XMLStyleSheet.new(*attrs)
|
||||
xss_strs.push(xss.to_s)
|
||||
rdf.xml_stylesheets.push(xss)
|
||||
end
|
||||
pi_str = rdf.to_s.gsub(/<\?xml .*\n/, "").gsub(/\s*<rdf:RDF.*\z/m, "")
|
||||
assert_equal(xss_strs.join("\n"), pi_str)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
127
test/rss/rss-assertions.rb
Normal file
127
test/rss/rss-assertions.rb
Normal file
|
@ -0,0 +1,127 @@
|
|||
# -*- tab-width: 2 -*- vim: ts=2
|
||||
|
||||
module RSS
|
||||
module Assertions
|
||||
|
||||
def assert_parse(rss, assert_method, *args)
|
||||
send("assert_#{assert_method}", *args) do
|
||||
::RSS::Parser.parse(rss)
|
||||
end
|
||||
send("assert_#{assert_method}", *args) do
|
||||
::RSS::Parser.parse(rss, false).validate
|
||||
end
|
||||
end
|
||||
|
||||
def assert_ns(prefix, uri)
|
||||
_wrap_assertion do
|
||||
begin
|
||||
yield
|
||||
flunk("Not raise NSError")
|
||||
rescue ::RSS::NSError => e
|
||||
assert_equal(prefix, e.prefix)
|
||||
assert_equal(uri, e.uri)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def assert_missing_tag(tag, parent)
|
||||
_wrap_assertion do
|
||||
begin
|
||||
yield
|
||||
flunk("Not raise MissingTagError")
|
||||
rescue ::RSS::MissingTagError => e
|
||||
assert_equal(tag, e.tag)
|
||||
assert_equal(parent, e.parent)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def assert_too_much_tag(tag, parent)
|
||||
_wrap_assertion do
|
||||
begin
|
||||
yield
|
||||
flunk("Not raise TooMuchTagError")
|
||||
rescue ::RSS::TooMuchTagError => e
|
||||
assert_equal(tag, e.tag)
|
||||
assert_equal(parent, e.parent)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def assert_missing_attribute(tag, attrname)
|
||||
_wrap_assertion do
|
||||
begin
|
||||
yield
|
||||
flunk("Not raise MissingAttributeError")
|
||||
rescue ::RSS::MissingAttributeError => e
|
||||
assert_equal(tag, e.tag)
|
||||
assert_equal(attrname, e.attribute)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def assert_not_excepted_tag(tag, parent)
|
||||
_wrap_assertion do
|
||||
begin
|
||||
yield
|
||||
flunk("Not raise NotExceptedTagError")
|
||||
rescue ::RSS::NotExceptedTagError => e
|
||||
assert_equal(tag, e.tag)
|
||||
assert_equal(parent, e.parent)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def assert_not_available_value(tag, value)
|
||||
_wrap_assertion do
|
||||
begin
|
||||
yield
|
||||
flunk("Not raise NotAvailableValueError")
|
||||
rescue ::RSS::NotAvailableValueError => e
|
||||
assert_equal(tag, e.tag)
|
||||
assert_equal(value, e.value)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def assert_xml_stylesheet_attrs(xsl, attrs)
|
||||
_wrap_assertion do
|
||||
normalized_attrs = {}
|
||||
attrs.each do |name, value|
|
||||
normalized_attrs[name.to_s] = value
|
||||
end
|
||||
::RSS::XMLStyleSheet::ATTRIBUTES.each do |name|
|
||||
assert_equal(normalized_attrs[name], xsl.send(name))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def assert_xml_stylesheet(target, xsl, attrs)
|
||||
_wrap_assertion do
|
||||
if attrs.has_key?(:href)
|
||||
if !attrs.has_key?(:type) and attrs.has_key?(:guess_type)
|
||||
attrs[:type] = attrs[:guess_type]
|
||||
end
|
||||
assert_equal("xml-stylesheet", target)
|
||||
assert_xml_stylesheet_attrs(xsl, attrs)
|
||||
else
|
||||
assert_nil(target)
|
||||
assert_equal("", xsl.to_s)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def assert_xml_stylesheet_pis(attrs_ary)
|
||||
rdf = ::RSS::RDF.new()
|
||||
xss_strs = []
|
||||
attrs_ary.each do |attrs|
|
||||
xss = ::RSS::XMLStyleSheet.new(*attrs)
|
||||
xss_strs.push(xss.to_s)
|
||||
rdf.xml_stylesheets.push(xss)
|
||||
end
|
||||
pi_str = rdf.to_s.gsub(/<\?xml .*\n/, "").gsub(/\s*<rdf:RDF.*\z/m, "")
|
||||
assert_equal(xss_strs.join("\n"), pi_str)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
|
@ -1,10 +1,13 @@
|
|||
# -*- tab-width: 2 -*- vim: ts=2
|
||||
|
||||
require 'my-assertions'
|
||||
require "test/unit"
|
||||
require 'rss-assertions'
|
||||
|
||||
module TestRSSMixin
|
||||
module RSS
|
||||
class TestCase < Test::Unit::TestCase
|
||||
|
||||
include RSS
|
||||
include Assertions
|
||||
|
||||
XMLDECL_VERSION = "1.0"
|
||||
XMLDECL_ENCODING = "UTF-8"
|
||||
|
@ -25,6 +28,10 @@ module TestRSSMixin
|
|||
"http://xml.com/pub/2000/08/09/rdfdb/index.html",
|
||||
]
|
||||
|
||||
def default_test
|
||||
# This class isn't tested
|
||||
end
|
||||
|
||||
private
|
||||
def make_xmldecl(v=XMLDECL_VERSION, e=XMLDECL_ENCODING, s=XMLDECL_STANDALONE)
|
||||
rv = "<?xml version='#{v}'"
|
||||
|
@ -154,3 +161,4 @@ EOC
|
|||
EOI
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,14 +1,13 @@
|
|||
# -*- tab-width: 2 -*- vim: ts=2
|
||||
|
||||
require "test/unit"
|
||||
require "rexml/document"
|
||||
|
||||
require "rss-testcase"
|
||||
|
||||
require "rss/1.0"
|
||||
require "common"
|
||||
|
||||
class TestCore < Test::Unit::TestCase
|
||||
|
||||
include TestRSSMixin
|
||||
module RSS
|
||||
class TestCore < TestCase
|
||||
|
||||
def setup
|
||||
|
||||
|
@ -257,3 +256,4 @@ class TestCore < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
# -*- tab-width: 2 -*- vim: ts=2
|
||||
|
||||
require "test/unit"
|
||||
require "rss-testcase"
|
||||
|
||||
require "rss/1.0"
|
||||
require "rss/2.0"
|
||||
require "common"
|
||||
|
||||
class TestAccessor < Test::Unit::TestCase
|
||||
include TestRSSMixin
|
||||
module RSS
|
||||
class TestAccessor < TestCase
|
||||
|
||||
def test_date
|
||||
channel = Rss::Channel.new
|
||||
|
@ -23,3 +23,4 @@ class TestAccessor < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
# -*- tab-width: 2 -*- vim: ts=2
|
||||
|
||||
require "test/unit"
|
||||
require "cgi"
|
||||
require "rexml/document"
|
||||
|
||||
require "rss-testcase"
|
||||
|
||||
require "rss/1.0"
|
||||
require "rss/content"
|
||||
require "common"
|
||||
|
||||
class TestContent < Test::Unit::TestCase
|
||||
include TestRSSMixin
|
||||
module RSS
|
||||
class TestContent < TestCase
|
||||
|
||||
def setup
|
||||
@prefix = "content"
|
||||
|
@ -94,3 +94,4 @@ EOR
|
|||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
# -*- tab-width: 2 -*- vim: ts=2
|
||||
|
||||
require "test/unit"
|
||||
require "cgi"
|
||||
require "rexml/document"
|
||||
|
||||
require "rss-testcase"
|
||||
|
||||
require "rss/1.0"
|
||||
require "rss/dublincore"
|
||||
require "common"
|
||||
|
||||
class TestDublinCore < Test::Unit::TestCase
|
||||
include TestRSSMixin
|
||||
module RSS
|
||||
class TestDublinCore < TestCase
|
||||
|
||||
def setup
|
||||
@prefix = "dc"
|
||||
|
@ -25,8 +25,8 @@ class TestDublinCore < Test::Unit::TestCase
|
|||
@elems = {
|
||||
:title => "hoge",
|
||||
:description =>
|
||||
" XML is placing increasingly heavy loads on the existing technical
|
||||
infrastructure of the Internet.",
|
||||
" XML is placing increasingly heavy loads on
|
||||
the existing technical infrastructure of the Internet.",
|
||||
:creator => "Rael Dornfest (mailto:rael@oreilly.com)",
|
||||
:subject => "XML",
|
||||
:publisher => "The O'Reilly Network",
|
||||
|
@ -123,3 +123,4 @@ EOR
|
|||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,11 +1,19 @@
|
|||
# -*- 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
|
||||
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
|
||||
|
@ -427,3 +435,5 @@ EOR
|
|||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
# -*- tab-width: 2 -*- vim: ts=2
|
||||
|
||||
require "test/unit"
|
||||
require "cgi"
|
||||
require "rexml/document"
|
||||
|
||||
require "rss-testcase"
|
||||
|
||||
require "rss/1.0"
|
||||
require "rss/syndication"
|
||||
require "common"
|
||||
|
||||
class TestSyndication < Test::Unit::TestCase
|
||||
include TestRSSMixin
|
||||
module RSS
|
||||
class TestSyndication < TestCase
|
||||
|
||||
def setup
|
||||
@prefix = "sy"
|
||||
|
@ -122,3 +122,4 @@ EOR
|
|||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,16 +1,16 @@
|
|||
# -*- tab-width: 2 -*- vim: ts=2
|
||||
|
||||
require "test/unit"
|
||||
require "cgi"
|
||||
require "rexml/document"
|
||||
|
||||
require "rss-testcase"
|
||||
|
||||
require "rss/1.0"
|
||||
require "rss/2.0"
|
||||
require "rss/trackback"
|
||||
require "common"
|
||||
|
||||
class TestTrackBack < Test::Unit::TestCase
|
||||
include TestRSSMixin
|
||||
module RSS
|
||||
class TestTrackBack < TestCase
|
||||
|
||||
def setup
|
||||
@prefix = "trackback"
|
||||
|
@ -133,3 +133,5 @@ EOR
|
|||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
# -*- tab-width: 2 -*- vim: ts=2
|
||||
|
||||
require "test/unit"
|
||||
require "rexml/document"
|
||||
|
||||
require "rss-testcase"
|
||||
|
||||
require "rss/1.0"
|
||||
require "rss/xml-stylesheet"
|
||||
require "common"
|
||||
|
||||
class TestXMLStyleSheet < Test::Unit::TestCase
|
||||
include TestRSSMixin
|
||||
module RSS
|
||||
class TestXMLStyleSheet < TestCase
|
||||
|
||||
def test_accessor
|
||||
[
|
||||
|
@ -107,3 +107,4 @@ class TestXMLStyleSheet < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue