* 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:
kou 2004-03-21 10:03:17 +00:00
Родитель cfbe158fae
Коммит abe876ed4e
12 изменённых файлов: 1036 добавлений и 1009 удалений

Просмотреть файл

@ -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> Sun Mar 21 18:48:20 2004 Kouhei Sutou <kou@cozmixng.org>
* lib/rss/{rss,dublincore,syndication}.rb: handled W3CDTF correctly. * 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
Просмотреть файл

@ -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 # -*- 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 RSS
include Assertions
XMLDECL_VERSION = "1.0" XMLDECL_VERSION = "1.0"
XMLDECL_ENCODING = "UTF-8" XMLDECL_ENCODING = "UTF-8"
@ -25,6 +28,10 @@ module TestRSSMixin
"http://xml.com/pub/2000/08/09/rdfdb/index.html", "http://xml.com/pub/2000/08/09/rdfdb/index.html",
] ]
def default_test
# This class isn't tested
end
private private
def make_xmldecl(v=XMLDECL_VERSION, e=XMLDECL_ENCODING, s=XMLDECL_STANDALONE) def make_xmldecl(v=XMLDECL_VERSION, e=XMLDECL_ENCODING, s=XMLDECL_STANDALONE)
rv = "<?xml version='#{v}'" rv = "<?xml version='#{v}'"
@ -154,3 +161,4 @@ EOC
EOI EOI
end end
end end
end

Просмотреть файл

@ -1,14 +1,13 @@
# -*- tab-width: 2 -*- vim: ts=2 # -*- tab-width: 2 -*- vim: ts=2
require "test/unit"
require "rexml/document" require "rexml/document"
require "rss-testcase"
require "rss/1.0" require "rss/1.0"
require "common"
class TestCore < Test::Unit::TestCase module RSS
class TestCore < TestCase
include TestRSSMixin
def setup def setup
@ -257,3 +256,4 @@ class TestCore < Test::Unit::TestCase
end end
end end
end

Просмотреть файл

@ -1,12 +1,12 @@
# -*- tab-width: 2 -*- vim: ts=2 # -*- tab-width: 2 -*- vim: ts=2
require "test/unit" require "rss-testcase"
require "rss/1.0" require "rss/1.0"
require "rss/2.0" require "rss/2.0"
require "common"
class TestAccessor < Test::Unit::TestCase module RSS
include TestRSSMixin class TestAccessor < TestCase
def test_date def test_date
channel = Rss::Channel.new channel = Rss::Channel.new
@ -23,3 +23,4 @@ class TestAccessor < Test::Unit::TestCase
end end
end end
end

Просмотреть файл

@ -1,15 +1,15 @@
# -*- tab-width: 2 -*- vim: ts=2 # -*- tab-width: 2 -*- vim: ts=2
require "test/unit"
require "cgi" require "cgi"
require "rexml/document" require "rexml/document"
require "rss-testcase"
require "rss/1.0" require "rss/1.0"
require "rss/content" require "rss/content"
require "common"
class TestContent < Test::Unit::TestCase module RSS
include TestRSSMixin class TestContent < TestCase
def setup def setup
@prefix = "content" @prefix = "content"
@ -94,3 +94,4 @@ EOR
end end
end end
end

Просмотреть файл

@ -1,15 +1,15 @@
# -*- tab-width: 2 -*- vim: ts=2 # -*- tab-width: 2 -*- vim: ts=2
require "test/unit"
require "cgi" require "cgi"
require "rexml/document" require "rexml/document"
require "rss-testcase"
require "rss/1.0" require "rss/1.0"
require "rss/dublincore" require "rss/dublincore"
require "common"
class TestDublinCore < Test::Unit::TestCase module RSS
include TestRSSMixin class TestDublinCore < TestCase
def setup def setup
@prefix = "dc" @prefix = "dc"
@ -25,8 +25,8 @@ class TestDublinCore < Test::Unit::TestCase
@elems = { @elems = {
:title => "hoge", :title => "hoge",
:description => :description =>
" XML is placing increasingly heavy loads on the existing technical " XML is placing increasingly heavy loads on
infrastructure of the Internet.", the existing technical infrastructure of the Internet.",
:creator => "Rael Dornfest (mailto:rael@oreilly.com)", :creator => "Rael Dornfest (mailto:rael@oreilly.com)",
:subject => "XML", :subject => "XML",
:publisher => "The O'Reilly Network", :publisher => "The O'Reilly Network",
@ -123,3 +123,4 @@ EOR
end end
end end
end

Просмотреть файл

@ -1,11 +1,19 @@
# -*- tab-width: 2 -*- vim: ts=2 # -*- tab-width: 2 -*- vim: ts=2
require "test/unit" require "rss-testcase"
require "rss/1.0"
require "common"
class TestParser < Test::Unit::TestCase require "rss/1.0"
include TestRSSMixin
module RSS
class TestParser < TestCase
def setup
@_default_parser = Parser.default_parser
end
def teardown
Parser.default_parser = @_default_parser
end
def test_RDF def test_RDF
assert_ns("", RDF::URI) do assert_ns("", RDF::URI) do
@ -427,3 +435,5 @@ EOR
end end
end end
end

Просмотреть файл

@ -1,15 +1,15 @@
# -*- tab-width: 2 -*- vim: ts=2 # -*- tab-width: 2 -*- vim: ts=2
require "test/unit"
require "cgi" require "cgi"
require "rexml/document" require "rexml/document"
require "rss-testcase"
require "rss/1.0" require "rss/1.0"
require "rss/syndication" require "rss/syndication"
require "common"
class TestSyndication < Test::Unit::TestCase module RSS
include TestRSSMixin class TestSyndication < TestCase
def setup def setup
@prefix = "sy" @prefix = "sy"
@ -122,3 +122,4 @@ EOR
end end
end end
end

Просмотреть файл

@ -1,16 +1,16 @@
# -*- tab-width: 2 -*- vim: ts=2 # -*- tab-width: 2 -*- vim: ts=2
require "test/unit"
require "cgi" require "cgi"
require "rexml/document" require "rexml/document"
require "rss-testcase"
require "rss/1.0" require "rss/1.0"
require "rss/2.0" require "rss/2.0"
require "rss/trackback" require "rss/trackback"
require "common"
class TestTrackBack < Test::Unit::TestCase module RSS
include TestRSSMixin class TestTrackBack < TestCase
def setup def setup
@prefix = "trackback" @prefix = "trackback"
@ -133,3 +133,5 @@ EOR
end end
end end
end

Просмотреть файл

@ -1,14 +1,14 @@
# -*- tab-width: 2 -*- vim: ts=2 # -*- tab-width: 2 -*- vim: ts=2
require "test/unit"
require "rexml/document" require "rexml/document"
require "rss-testcase"
require "rss/1.0" require "rss/1.0"
require "rss/xml-stylesheet" require "rss/xml-stylesheet"
require "common"
class TestXMLStyleSheet < Test::Unit::TestCase module RSS
include TestRSSMixin class TestXMLStyleSheet < TestCase
def test_accessor def test_accessor
[ [
@ -107,3 +107,4 @@ class TestXMLStyleSheet < Test::Unit::TestCase
end end
end end
end