mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
This commit was manufactured by cvs2svn to create branch 'ruby_1_8'.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@6109 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
8e773df6d3
commit
5923a2c0e7
20 changed files with 6348 additions and 0 deletions
4057
ext/bigdecimal/bigdecimal.c
Normal file
4057
ext/bigdecimal/bigdecimal.c
Normal file
File diff suppressed because it is too large
Load diff
409
lib/rss/0.9.rb
Normal file
409
lib/rss/0.9.rb
Normal file
|
@ -0,0 +1,409 @@
|
||||||
|
require "rss/parser"
|
||||||
|
|
||||||
|
module RSS
|
||||||
|
|
||||||
|
module RSS09
|
||||||
|
NSPOOL = {}
|
||||||
|
ELEMENTS = []
|
||||||
|
end
|
||||||
|
|
||||||
|
class Rss < Element
|
||||||
|
|
||||||
|
include RSS09
|
||||||
|
include RootElementMixin
|
||||||
|
include XMLStyleSheetMixin
|
||||||
|
|
||||||
|
[
|
||||||
|
["channel", nil],
|
||||||
|
].each do |tag, occurs|
|
||||||
|
install_model(tag, occurs)
|
||||||
|
end
|
||||||
|
|
||||||
|
%w(channel).each do |x|
|
||||||
|
install_have_child_element(x)
|
||||||
|
end
|
||||||
|
|
||||||
|
attr_accessor :rss_version, :version, :encoding, :standalone
|
||||||
|
|
||||||
|
def initialize(rss_version, version=nil, encoding=nil, standalone=nil)
|
||||||
|
super
|
||||||
|
end
|
||||||
|
|
||||||
|
def items
|
||||||
|
if @channel
|
||||||
|
@channel.items
|
||||||
|
else
|
||||||
|
[]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def image
|
||||||
|
if @channel
|
||||||
|
@channel.image
|
||||||
|
else
|
||||||
|
nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def to_s(convert=true)
|
||||||
|
rv = <<-EOR
|
||||||
|
#{xmldecl}
|
||||||
|
#{xml_stylesheet_pi}<rss version="#{@rss_version}"#{ns_declaration}>
|
||||||
|
#{channel_element(false)}
|
||||||
|
#{other_element(false, "\t")}
|
||||||
|
</rss>
|
||||||
|
EOR
|
||||||
|
rv = @converter.convert(rv) if convert and @converter
|
||||||
|
rv
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
def children
|
||||||
|
[@channel]
|
||||||
|
end
|
||||||
|
|
||||||
|
class Channel < Element
|
||||||
|
|
||||||
|
include RSS09
|
||||||
|
|
||||||
|
[
|
||||||
|
["title", nil],
|
||||||
|
["link", nil],
|
||||||
|
["description", nil],
|
||||||
|
["language", nil],
|
||||||
|
["copyright", "?"],
|
||||||
|
["managingEditor", "?"],
|
||||||
|
["webMaster", "?"],
|
||||||
|
["rating", "?"],
|
||||||
|
["docs", "?"],
|
||||||
|
["skipDays", "?"],
|
||||||
|
["skipHours", "?"],
|
||||||
|
].each do |x, occurs|
|
||||||
|
install_text_element(x)
|
||||||
|
install_model(x, occurs)
|
||||||
|
end
|
||||||
|
|
||||||
|
[
|
||||||
|
["pubDate", "?"],
|
||||||
|
["lastBuildDate", "?"],
|
||||||
|
].each do |x, occurs|
|
||||||
|
install_date_element(x, 'rfc822')
|
||||||
|
install_model(x, occurs)
|
||||||
|
end
|
||||||
|
|
||||||
|
[
|
||||||
|
["image", nil],
|
||||||
|
["textInput", "?"],
|
||||||
|
["cloud", "?"]
|
||||||
|
].each do |x, occurs|
|
||||||
|
install_have_child_element(x)
|
||||||
|
install_model(x, occurs)
|
||||||
|
end
|
||||||
|
|
||||||
|
[
|
||||||
|
["item", "*"]
|
||||||
|
].each do |x, occurs|
|
||||||
|
install_have_children_element(x)
|
||||||
|
install_model(x, occurs)
|
||||||
|
end
|
||||||
|
|
||||||
|
def initialize()
|
||||||
|
super()
|
||||||
|
end
|
||||||
|
|
||||||
|
def to_s(convert=true)
|
||||||
|
rv = <<-EOT
|
||||||
|
<channel>
|
||||||
|
#{title_element(false)}
|
||||||
|
#{link_element(false)}
|
||||||
|
#{description_element(false)}
|
||||||
|
#{language_element(false)}
|
||||||
|
#{copyright_element(false)}
|
||||||
|
#{managingEditor_element(false)}
|
||||||
|
#{webMaster_element(false)}
|
||||||
|
#{rating_element(false)}
|
||||||
|
#{pubDate_element(false)}
|
||||||
|
#{lastBuildDate_element(false)}
|
||||||
|
#{docs_element(false)}
|
||||||
|
#{skipDays_element(false)}
|
||||||
|
#{skipHours_element(false)}
|
||||||
|
#{image_element(false)}
|
||||||
|
#{item_elements(false)}
|
||||||
|
#{textInput_element(false)}
|
||||||
|
#{other_element(false, "\t\t")}
|
||||||
|
</channel>
|
||||||
|
EOT
|
||||||
|
rv = @converter.convert(rv) if convert and @converter
|
||||||
|
rv
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
def children
|
||||||
|
[@image, @textInput, @cloud, *@item]
|
||||||
|
end
|
||||||
|
|
||||||
|
class Image < Element
|
||||||
|
|
||||||
|
include RSS09
|
||||||
|
|
||||||
|
%w(url title link width height description).each do |x|
|
||||||
|
install_text_element(x)
|
||||||
|
end
|
||||||
|
|
||||||
|
def to_s(convert=true)
|
||||||
|
rv = <<-EOT
|
||||||
|
<image>
|
||||||
|
#{url_element(false)}
|
||||||
|
#{title_element(false)}
|
||||||
|
#{link_element(false)}
|
||||||
|
#{width_element(false)}
|
||||||
|
#{height_element(false)}
|
||||||
|
#{description_element(false)}
|
||||||
|
#{other_element(false, "\t\t\t\t")}
|
||||||
|
</image>
|
||||||
|
EOT
|
||||||
|
rv = @converter.convert(rv) if convert and @converter
|
||||||
|
rv
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
class Cloud < Element
|
||||||
|
|
||||||
|
include RSS09
|
||||||
|
|
||||||
|
[
|
||||||
|
["domain", nil, false],
|
||||||
|
["port", nil, false],
|
||||||
|
["path", nil, false],
|
||||||
|
["registerProcedure", nil, false],
|
||||||
|
["protocol", nil ,false],
|
||||||
|
].each do |name, uri, required|
|
||||||
|
install_get_attribute(name, uri, required)
|
||||||
|
end
|
||||||
|
|
||||||
|
def to_s(convert=true)
|
||||||
|
rv = <<-EOT
|
||||||
|
<cloud
|
||||||
|
domain="#{h @domain}"
|
||||||
|
port="#{h @port}"
|
||||||
|
path="#{h @path}"
|
||||||
|
registerProcedure="#{h @registerProcedure}"
|
||||||
|
protocol="#{h @protocol}"/>
|
||||||
|
EOT
|
||||||
|
rv = @converter.convert(rv) if convert and @converter
|
||||||
|
rv
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
class Item < Element
|
||||||
|
|
||||||
|
include RSS09
|
||||||
|
|
||||||
|
%w(title link description author comments).each do |x|
|
||||||
|
install_text_element(x)
|
||||||
|
end
|
||||||
|
|
||||||
|
%w(category source enclosure).each do |x|
|
||||||
|
install_have_child_element(x)
|
||||||
|
end
|
||||||
|
|
||||||
|
[
|
||||||
|
["title", '?'],
|
||||||
|
["link", '?'],
|
||||||
|
["description", '?'],
|
||||||
|
["author", '?'],
|
||||||
|
["comments", '?'],
|
||||||
|
["category", '?'],
|
||||||
|
["source", '?'],
|
||||||
|
["enclosure", '?'],
|
||||||
|
].each do |tag, occurs|
|
||||||
|
install_model(tag, occurs)
|
||||||
|
end
|
||||||
|
|
||||||
|
def to_s(convert=true)
|
||||||
|
rv = <<-EOT
|
||||||
|
<item>
|
||||||
|
#{title_element(false)}
|
||||||
|
#{link_element(false)}
|
||||||
|
#{description_element(false)}
|
||||||
|
#{author_element(false)}
|
||||||
|
#{category_element(false)}
|
||||||
|
#{comments_element(false)}
|
||||||
|
#{enclosure_element(false)}
|
||||||
|
#{source_element(false)}
|
||||||
|
#{other_element(false, "\t\t\t\t")}
|
||||||
|
</item>
|
||||||
|
EOT
|
||||||
|
rv = @converter.convert(rv) if convert and @converter
|
||||||
|
rv
|
||||||
|
end
|
||||||
|
|
||||||
|
class Source < Element
|
||||||
|
|
||||||
|
include RSS09
|
||||||
|
|
||||||
|
[
|
||||||
|
["url", nil, true]
|
||||||
|
].each do |name, uri, required|
|
||||||
|
install_get_attribute(name, uri, required)
|
||||||
|
end
|
||||||
|
|
||||||
|
content_setup
|
||||||
|
|
||||||
|
def initialize(url=nil, content=nil)
|
||||||
|
super()
|
||||||
|
@url = url
|
||||||
|
@content = content
|
||||||
|
end
|
||||||
|
|
||||||
|
def to_s(convert=true)
|
||||||
|
if @url
|
||||||
|
rv = %Q! <source url="#{@url}">!
|
||||||
|
rv << %Q!#{@content}</source>!
|
||||||
|
rv = @converter.convert(rv) if convert and @converter
|
||||||
|
rv
|
||||||
|
else
|
||||||
|
''
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
def _attrs
|
||||||
|
[
|
||||||
|
["url", true]
|
||||||
|
]
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
class Enclosure < Element
|
||||||
|
|
||||||
|
include RSS09
|
||||||
|
|
||||||
|
[
|
||||||
|
["url", nil, true],
|
||||||
|
["length", nil, true],
|
||||||
|
["type", nil, true],
|
||||||
|
].each do |name, uri, required|
|
||||||
|
install_get_attribute(name, uri, required)
|
||||||
|
end
|
||||||
|
|
||||||
|
def initialize(url=nil, length=nil, type=nil)
|
||||||
|
super()
|
||||||
|
@url = url
|
||||||
|
@length = length
|
||||||
|
@type = type
|
||||||
|
end
|
||||||
|
|
||||||
|
def to_s(convert=true)
|
||||||
|
if @url and @length and @type
|
||||||
|
rv = %Q!<enclosure url="#{h @url}" !
|
||||||
|
rv << %Q!length="#{h @length}" type="#{h @type}"/>!
|
||||||
|
rv = @converter.convert(rv) if convert and @converter
|
||||||
|
rv
|
||||||
|
else
|
||||||
|
''
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
def _attrs
|
||||||
|
[
|
||||||
|
["url", true],
|
||||||
|
["length", true],
|
||||||
|
["type", true],
|
||||||
|
]
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
class Category < Element
|
||||||
|
|
||||||
|
include RSS09
|
||||||
|
|
||||||
|
[
|
||||||
|
["domain", nil, true]
|
||||||
|
].each do |name, uri, required|
|
||||||
|
install_get_attribute(name, uri, required)
|
||||||
|
end
|
||||||
|
|
||||||
|
content_setup
|
||||||
|
|
||||||
|
def initialize(domain=nil, content=nil)
|
||||||
|
super()
|
||||||
|
@domain = domain
|
||||||
|
@content = content
|
||||||
|
end
|
||||||
|
|
||||||
|
def to_s(convert=true)
|
||||||
|
if @domain
|
||||||
|
rv = %Q!<category domain="#{h @domain}">!
|
||||||
|
rv << %Q!#{h @content}</category>!
|
||||||
|
rv = @converter.convert(rv) if convert and @converter
|
||||||
|
rv
|
||||||
|
else
|
||||||
|
''
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
def _attrs
|
||||||
|
[
|
||||||
|
["domain", true]
|
||||||
|
]
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
class TextInput < Element
|
||||||
|
|
||||||
|
include RSS09
|
||||||
|
|
||||||
|
%w(title description name link).each do |x|
|
||||||
|
install_text_element(x)
|
||||||
|
end
|
||||||
|
|
||||||
|
def to_s(convert=true)
|
||||||
|
rv = <<-EOT
|
||||||
|
<textInput>
|
||||||
|
#{title_element(false)}
|
||||||
|
#{description_element(false)}
|
||||||
|
#{name_element(false)}
|
||||||
|
#{link_element(false)}
|
||||||
|
#{other_element(false, "\t\t\t\t")}
|
||||||
|
</textInput>
|
||||||
|
EOT
|
||||||
|
rv = @converter.convert(rv) if convert and @converter
|
||||||
|
rv
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
RSS09::ELEMENTS.each do |x|
|
||||||
|
BaseListener.install_get_text_element(x, nil, "#{x}=")
|
||||||
|
end
|
||||||
|
|
||||||
|
module ListenerMixin
|
||||||
|
private
|
||||||
|
def start_rss(tag_name, prefix, attrs, ns)
|
||||||
|
check_ns(tag_name, prefix, ns, nil)
|
||||||
|
|
||||||
|
@rss = Rss.new(attrs['version'], @version, @encoding, @standalone)
|
||||||
|
@rss.xml_stylesheets = @xml_stylesheets
|
||||||
|
@last_element = @rss
|
||||||
|
@proc_stack.push Proc.new { |text, tags|
|
||||||
|
@rss.validate_for_stream(tags) if @do_validate
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
147
lib/rss/2.0.rb
Normal file
147
lib/rss/2.0.rb
Normal file
|
@ -0,0 +1,147 @@
|
||||||
|
require "rss/0.9"
|
||||||
|
|
||||||
|
module RSS
|
||||||
|
|
||||||
|
class Rss
|
||||||
|
|
||||||
|
# URI = "http://backend.userland.com/rss2"
|
||||||
|
|
||||||
|
# install_ns('', URI)
|
||||||
|
|
||||||
|
# def self.required_uri
|
||||||
|
# URI
|
||||||
|
# end
|
||||||
|
|
||||||
|
class Channel
|
||||||
|
|
||||||
|
# def self.required_uri
|
||||||
|
# URI
|
||||||
|
# end
|
||||||
|
|
||||||
|
%w(generator ttl).each do |x|
|
||||||
|
install_text_element(x)
|
||||||
|
end
|
||||||
|
|
||||||
|
%w(category).each do |x|
|
||||||
|
install_have_child_element(x)
|
||||||
|
end
|
||||||
|
|
||||||
|
[
|
||||||
|
["image", "?"],
|
||||||
|
].each do |x, occurs|
|
||||||
|
install_model(x, occurs)
|
||||||
|
end
|
||||||
|
|
||||||
|
def other_element(convert, indent='')
|
||||||
|
rv = <<-EOT
|
||||||
|
#{indent}#{category_element(convert)}
|
||||||
|
#{indent}#{generator_element(convert)}
|
||||||
|
#{indent}#{ttl_element(convert)}
|
||||||
|
EOT
|
||||||
|
rv << super
|
||||||
|
end
|
||||||
|
|
||||||
|
Category = Item::Category
|
||||||
|
# def Category.required_uri
|
||||||
|
# URI
|
||||||
|
# end
|
||||||
|
|
||||||
|
class Item
|
||||||
|
|
||||||
|
# def self.required_uri
|
||||||
|
# URI
|
||||||
|
# end
|
||||||
|
|
||||||
|
[
|
||||||
|
["pubDate", '?'],
|
||||||
|
].each do |x, occurs|
|
||||||
|
install_date_element(x, 'rfc822')
|
||||||
|
install_model(x, occurs)
|
||||||
|
end
|
||||||
|
|
||||||
|
[
|
||||||
|
["guid", '?'],
|
||||||
|
].each do |x, occurs|
|
||||||
|
install_have_child_element(x)
|
||||||
|
install_model(x, occurs)
|
||||||
|
end
|
||||||
|
|
||||||
|
def other_element(convert, indent='')
|
||||||
|
rv = <<-EOT
|
||||||
|
#{indent}#{pubDate_element(false)}
|
||||||
|
#{indent}#{guid_element(false)}
|
||||||
|
EOT
|
||||||
|
rv << super
|
||||||
|
end
|
||||||
|
|
||||||
|
class Guid < Element
|
||||||
|
|
||||||
|
include RSS09
|
||||||
|
|
||||||
|
# def self.required_uri
|
||||||
|
# URI
|
||||||
|
# end
|
||||||
|
|
||||||
|
[
|
||||||
|
["isPermaLink", nil, false]
|
||||||
|
].each do |name, uri, required|
|
||||||
|
install_get_attribute(name, uri, required)
|
||||||
|
end
|
||||||
|
|
||||||
|
content_setup
|
||||||
|
|
||||||
|
def initialize(isPermaLink=nil, content=nil)
|
||||||
|
super()
|
||||||
|
@isPermaLink = isPermaLink
|
||||||
|
@content = content
|
||||||
|
end
|
||||||
|
|
||||||
|
def to_s(convert=true)
|
||||||
|
if @content
|
||||||
|
rv = %Q!<guid!
|
||||||
|
rv << %Q! isPermaLink="#{h @isPermaLink}"! if @isPermaLink
|
||||||
|
rv << %Q!>#{h @content}</guid>!
|
||||||
|
rv = @converter.convert(rv) if convert and @converter
|
||||||
|
rv
|
||||||
|
else
|
||||||
|
''
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
def _attrs
|
||||||
|
[
|
||||||
|
["isPermaLink", false]
|
||||||
|
]
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
RSS09::ELEMENTS.each do |x|
|
||||||
|
# BaseListener.install_get_text_element(x, Rss::URI, "#{x}=")
|
||||||
|
BaseListener.install_get_text_element(x, nil, "#{x}=")
|
||||||
|
end
|
||||||
|
|
||||||
|
module ListenerMixin
|
||||||
|
private
|
||||||
|
alias start_rss09 start_rss
|
||||||
|
def start_rss(tag_name, prefix, attrs, ns)
|
||||||
|
# check_ns(tag_name, prefix, ns, Rss::URI)
|
||||||
|
|
||||||
|
@rss = Rss.new(attrs['version'], @version, @encoding, @standalone)
|
||||||
|
@rss.xml_stylesheets = @xml_stylesheets
|
||||||
|
@last_element = @rss
|
||||||
|
@proc_stack.push Proc.new { |text, tags|
|
||||||
|
@rss.validate_for_stream(tags) if @do_validate
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
154
lib/rss/converter.rb
Normal file
154
lib/rss/converter.rb
Normal file
|
@ -0,0 +1,154 @@
|
||||||
|
require "rss/utils"
|
||||||
|
|
||||||
|
module RSS
|
||||||
|
|
||||||
|
class Converter
|
||||||
|
|
||||||
|
include Utils
|
||||||
|
|
||||||
|
def initialize(to_enc, from_enc=nil)
|
||||||
|
to_enc = to_enc.downcase.gsub(/-/, '_')
|
||||||
|
from_enc ||= 'utf-8'
|
||||||
|
from_enc = from_enc.downcase.gsub(/-/, '_')
|
||||||
|
if to_enc == from_enc
|
||||||
|
def_same_enc()
|
||||||
|
else
|
||||||
|
if respond_to?("def_to_#{to_enc}_from_#{from_enc}")
|
||||||
|
send("def_to_#{to_enc}_from_#{from_enc}")
|
||||||
|
else
|
||||||
|
def_else_enc(to_enc, from_enc)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def convert(value)
|
||||||
|
value
|
||||||
|
end
|
||||||
|
|
||||||
|
def def_convert(depth=0)
|
||||||
|
instance_eval(<<-EOC, *get_file_and_line_from_caller(depth))
|
||||||
|
def convert(value)
|
||||||
|
if value.kind_of?(String)
|
||||||
|
#{yield('value')}
|
||||||
|
else
|
||||||
|
value
|
||||||
|
end
|
||||||
|
end
|
||||||
|
EOC
|
||||||
|
end
|
||||||
|
|
||||||
|
def def_iconv_convert(to_enc, from_enc, depth=0)
|
||||||
|
begin
|
||||||
|
require "iconv"
|
||||||
|
def_convert(depth+1) do |value|
|
||||||
|
<<-EOC
|
||||||
|
@iconv ||= Iconv.new("#{to_enc}", "#{from_enc}")
|
||||||
|
begin
|
||||||
|
@iconv.iconv(#{value})
|
||||||
|
rescue Iconv::Failure
|
||||||
|
raise ConversionError.new(#{value}, "#{to_enc}", "#{from_enc}")
|
||||||
|
end
|
||||||
|
EOC
|
||||||
|
end
|
||||||
|
rescue LoadError, ArgumentError, SystemCallError
|
||||||
|
raise UnknownConversionMethodError.new(to_enc, from_enc)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def def_else_enc(to_enc, from_enc)
|
||||||
|
raise UnknownConversionMethodError.new(to_enc, from_enc)
|
||||||
|
end
|
||||||
|
|
||||||
|
def def_same_enc()
|
||||||
|
def_convert do |value|
|
||||||
|
value
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def def_uconv_convert_if_can(meth, to_enc, from_enc)
|
||||||
|
begin
|
||||||
|
require "uconv"
|
||||||
|
def_convert(1) do |value|
|
||||||
|
<<-EOC
|
||||||
|
begin
|
||||||
|
Uconv.#{meth}(#{value})
|
||||||
|
rescue Uconv::Error
|
||||||
|
raise ConversionError.new(#{value}, "#{to_enc}", "#{from_enc}")
|
||||||
|
end
|
||||||
|
EOC
|
||||||
|
end
|
||||||
|
rescue LoadError
|
||||||
|
def_iconv_convert(to_enc, from_enc, 1)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def def_to_euc_jp_from_utf_8
|
||||||
|
def_uconv_convert_if_can('u8toeuc', 'EUC-JP', 'UTF-8')
|
||||||
|
end
|
||||||
|
|
||||||
|
def def_to_utf_8_from_euc_jp
|
||||||
|
def_uconv_convert_if_can('euctou8', 'UTF-8', 'EUC-JP')
|
||||||
|
end
|
||||||
|
|
||||||
|
def def_to_shift_jis_from_utf_8
|
||||||
|
def_uconv_convert_if_can('u8tosjis', 'Shift_JIS', 'UTF-8')
|
||||||
|
end
|
||||||
|
|
||||||
|
def def_to_utf_8_from_shift_jis
|
||||||
|
def_uconv_convert_if_can('sjistou8', 'UTF-8', 'Shift_JIS')
|
||||||
|
end
|
||||||
|
|
||||||
|
def def_to_euc_jp_from_shift_jis
|
||||||
|
require "nkf"
|
||||||
|
def_convert do |value|
|
||||||
|
"NKF.nkf('-Se', #{value})"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def def_to_shift_jis_from_euc_jp
|
||||||
|
require "nkf"
|
||||||
|
def_convert do |value|
|
||||||
|
"NKF.nkf('-Es', #{value})"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def def_to_euc_jp_from_iso_2022_jp
|
||||||
|
require "nkf"
|
||||||
|
def_convert do |value|
|
||||||
|
"NKF.nkf('-Je', #{value})"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def def_to_iso_2022_jp_from_euc_jp
|
||||||
|
require "nkf"
|
||||||
|
def_convert do |value|
|
||||||
|
"NKF.nkf('-Ej', #{value})"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def def_to_utf_8_from_iso_8859_1
|
||||||
|
def_convert do |value|
|
||||||
|
"#{value}.unpack('C*').pack('U*')"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def def_to_iso_8859_1_from_utf_8
|
||||||
|
def_convert do |value|
|
||||||
|
<<-EOC
|
||||||
|
array_utf8 = #{value}.unpack('U*')
|
||||||
|
array_enc = []
|
||||||
|
array_utf8.each do |num|
|
||||||
|
if num <= 0xFF
|
||||||
|
array_enc << num
|
||||||
|
else
|
||||||
|
array_enc.concat "&\#\#{num};".unpack('C*')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
array_enc.pack('C*')
|
||||||
|
EOC
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
83
lib/rss/syndication.rb
Normal file
83
lib/rss/syndication.rb
Normal file
|
@ -0,0 +1,83 @@
|
||||||
|
require "rss/1.0"
|
||||||
|
|
||||||
|
module RSS
|
||||||
|
|
||||||
|
SY_PREFIX = 'sy'
|
||||||
|
SY_URI = "http://purl.org/rss/1.0/modules/syndication/"
|
||||||
|
|
||||||
|
RDF.install_ns(SY_PREFIX, SY_URI)
|
||||||
|
|
||||||
|
module SyndicationModel
|
||||||
|
|
||||||
|
extend BaseModel
|
||||||
|
|
||||||
|
ELEMENTS = []
|
||||||
|
|
||||||
|
def self.included(mod)
|
||||||
|
mod.module_eval(<<-EOC)
|
||||||
|
%w(updatePeriod updateFrequency).each do |x|
|
||||||
|
install_text_element("\#{SY_PREFIX}_\#{x}")
|
||||||
|
end
|
||||||
|
|
||||||
|
%w(updateBase).each do |x|
|
||||||
|
install_date_element("\#{SY_PREFIX}_\#{x}", 'w3cdtf', x)
|
||||||
|
end
|
||||||
|
|
||||||
|
alias_method(:_sy_updatePeriod=, :sy_updatePeriod=)
|
||||||
|
def sy_updatePeriod=(new_value)
|
||||||
|
new_value = new_value.strip
|
||||||
|
validate_sy_updatePeriod(new_value) if @do_validate
|
||||||
|
self._sy_updatePeriod = new_value
|
||||||
|
end
|
||||||
|
|
||||||
|
alias_method(:_sy_updateFrequency=, :sy_updateFrequency=)
|
||||||
|
def sy_updateFrequency=(new_value)
|
||||||
|
new_value = new_value.strip
|
||||||
|
validate_sy_updateFrequency(new_value) if @do_validate
|
||||||
|
self._sy_updateFrequency = new_value.to_i
|
||||||
|
end
|
||||||
|
EOC
|
||||||
|
end
|
||||||
|
|
||||||
|
def sy_validate(tags)
|
||||||
|
counter = {}
|
||||||
|
ELEMENTS.each do |x|
|
||||||
|
counter[x] = 0
|
||||||
|
end
|
||||||
|
|
||||||
|
tags.each do |tag|
|
||||||
|
key = "#{SY_PREFIX}_#{tag}"
|
||||||
|
raise UnknownTagError.new(tag, SY_URI) unless counter.has_key?(key)
|
||||||
|
counter[key] += 1
|
||||||
|
raise TooMuchTagError.new(tag, tag_name) if counter[key] > 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
SY_UPDATEPERIOD_AVAILABLE_VALUES = %w(hourly daily weekly monthly yearly)
|
||||||
|
def validate_sy_updatePeriod(value)
|
||||||
|
unless SY_UPDATEPERIOD_AVAILABLE_VALUES.include?(value)
|
||||||
|
raise NotAvailableValueError.new("updatePeriod", value)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
SY_UPDATEFREQUENCY_AVAILABLE_RE = /\A\s*\+?\d+\s*\z/
|
||||||
|
def validate_sy_updateFrequency(value)
|
||||||
|
if SY_UPDATEFREQUENCY_AVAILABLE_RE !~ value
|
||||||
|
raise NotAvailableValueError.new("updateFrequency", value)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
class RDF
|
||||||
|
class Channel; include SyndicationModel; end
|
||||||
|
end
|
||||||
|
|
||||||
|
prefix_size = SY_PREFIX.size + 1
|
||||||
|
SyndicationModel::ELEMENTS.uniq!
|
||||||
|
SyndicationModel::ELEMENTS.each do |x|
|
||||||
|
BaseListener.install_get_text_element(x[prefix_size..-1], SY_URI, "#{x}=")
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
32
lib/rss/taxonomy.rb
Normal file
32
lib/rss/taxonomy.rb
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
# Experimental
|
||||||
|
|
||||||
|
require "rss/1.0"
|
||||||
|
|
||||||
|
module RSS
|
||||||
|
|
||||||
|
TAXO_PREFIX = "taxo"
|
||||||
|
TAXO_NS = "http://purl.org/rss/1.0/modules/taxonomy/"
|
||||||
|
|
||||||
|
Element.install_ns(TAXO_PREFIX, TAXO_NS)
|
||||||
|
|
||||||
|
TAXO_ELEMENTS = []
|
||||||
|
|
||||||
|
%w(link).each do |x|
|
||||||
|
if const_defined? :Listener
|
||||||
|
Listener.install_get_text_element(x, TAXO_NS, "#{TAXO_PREFIX}_#{x}=")
|
||||||
|
end
|
||||||
|
TAXO_ELEMENTS << "#{TAXO_PREFIX}_#{x}"
|
||||||
|
end
|
||||||
|
|
||||||
|
module TaxonomyModel
|
||||||
|
attr_writer(*%w(title description creator subject publisher
|
||||||
|
contributor date format identifier source
|
||||||
|
language relation coverage rights).collect{|x| "#{TAXO_PREFIX}_#{x}"})
|
||||||
|
end
|
||||||
|
|
||||||
|
class Channel; extend TaxonomyModel; end
|
||||||
|
class Item; extend TaxonomyModel; end
|
||||||
|
class Image; extend TaxonomyModel; end
|
||||||
|
class TextInput; extend TaxonomyModel; end
|
||||||
|
|
||||||
|
end
|
17
lib/rss/utils.rb
Normal file
17
lib/rss/utils.rb
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
module RSS
|
||||||
|
|
||||||
|
module Utils
|
||||||
|
|
||||||
|
def get_file_and_line_from_caller(i=0)
|
||||||
|
file, line, = caller[i].split(':')
|
||||||
|
[file, line.to_i]
|
||||||
|
end
|
||||||
|
|
||||||
|
def html_escape(s)
|
||||||
|
s.to_s.gsub(/&/, "&").gsub(/\"/, """).gsub(/>/, ">").gsub(/</, "<")
|
||||||
|
end
|
||||||
|
alias h html_escape
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
94
lib/rss/xml-stylesheet.rb
Normal file
94
lib/rss/xml-stylesheet.rb
Normal file
|
@ -0,0 +1,94 @@
|
||||||
|
require "rss/utils"
|
||||||
|
|
||||||
|
module RSS
|
||||||
|
|
||||||
|
module XMLStyleSheetMixin
|
||||||
|
attr_accessor :xml_stylesheets
|
||||||
|
def initialize(*args)
|
||||||
|
super
|
||||||
|
@xml_stylesheets = []
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
def xml_stylesheet_pi
|
||||||
|
xsss = @xml_stylesheets.collect do |xss|
|
||||||
|
pi = xss.to_s
|
||||||
|
pi = nil if /\A\s*\z/ =~ pi
|
||||||
|
pi
|
||||||
|
end.compact
|
||||||
|
xsss.push("") unless xsss.empty?
|
||||||
|
xsss.join("\n")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
class XMLStyleSheet
|
||||||
|
|
||||||
|
include Utils
|
||||||
|
|
||||||
|
ATTRIBUTES = %w(href type title media charset alternate)
|
||||||
|
|
||||||
|
GUESS_TABLE = {
|
||||||
|
"xsl" => "text/xsl",
|
||||||
|
"css" => "text/css",
|
||||||
|
}
|
||||||
|
|
||||||
|
attr_accessor(*ATTRIBUTES)
|
||||||
|
attr_accessor(:do_validate)
|
||||||
|
def initialize(*attrs)
|
||||||
|
@do_validate = true
|
||||||
|
ATTRIBUTES.each do |attr|
|
||||||
|
self.send("#{attr}=", nil)
|
||||||
|
end
|
||||||
|
vars = ATTRIBUTES.dup
|
||||||
|
vars.unshift(:do_validate)
|
||||||
|
attrs.each do |name, value|
|
||||||
|
if vars.include?(name.to_s)
|
||||||
|
self.send("#{name}=", value)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def to_s
|
||||||
|
rv = ""
|
||||||
|
if @href
|
||||||
|
rv << %Q[<?xml-stylesheet]
|
||||||
|
ATTRIBUTES.each do |name|
|
||||||
|
if self.send(name)
|
||||||
|
rv << %Q[ #{name}="#{h self.send(name)}"]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
rv << %Q[?>]
|
||||||
|
end
|
||||||
|
rv
|
||||||
|
end
|
||||||
|
|
||||||
|
remove_method(:href=)
|
||||||
|
def href=(value)
|
||||||
|
@href = value
|
||||||
|
if @href and @type.nil?
|
||||||
|
@type = guess_type(@href)
|
||||||
|
end
|
||||||
|
@href
|
||||||
|
end
|
||||||
|
|
||||||
|
remove_method(:alternate=)
|
||||||
|
def alternate=(value)
|
||||||
|
if value.nil? or /\A(?:yes|no)\z/ =~ value
|
||||||
|
@alternate = value
|
||||||
|
else
|
||||||
|
if @do_validate
|
||||||
|
args = ["?xml-stylesheet?", %Q[alternate="#{value}"]]
|
||||||
|
raise NotAvailableValueError.new(*args)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
@alternate
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
def guess_type(filename)
|
||||||
|
/\.([^.]+)/ =~ filename
|
||||||
|
GUESS_TABLE[$1]
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
102
lib/rss/xmlscanner.rb
Normal file
102
lib/rss/xmlscanner.rb
Normal file
|
@ -0,0 +1,102 @@
|
||||||
|
require 'xmlscan/scanner'
|
||||||
|
|
||||||
|
module RSS
|
||||||
|
|
||||||
|
class XMLScanParser < BaseParser
|
||||||
|
|
||||||
|
private
|
||||||
|
def listener
|
||||||
|
XMLScanListener
|
||||||
|
end
|
||||||
|
|
||||||
|
def _parse
|
||||||
|
begin
|
||||||
|
XMLScan::XMLScanner.new(@listener).parse(@rss)
|
||||||
|
rescue XMLScan::Error => e
|
||||||
|
raise NotWellFormedError.new(e.lineno){e.message}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
class XMLScanListener < BaseListener
|
||||||
|
|
||||||
|
include XMLScan::Visitor
|
||||||
|
include ListenerMixin
|
||||||
|
|
||||||
|
ENTITIES = {
|
||||||
|
'lt' => '<',
|
||||||
|
'gt' => '>',
|
||||||
|
'amp' => '&',
|
||||||
|
'quot' => '"',
|
||||||
|
'apos' => '\''
|
||||||
|
}
|
||||||
|
|
||||||
|
def on_xmldecl_version(str)
|
||||||
|
@version = str
|
||||||
|
end
|
||||||
|
|
||||||
|
def on_xmldecl_encoding(str)
|
||||||
|
@encoding = str
|
||||||
|
end
|
||||||
|
|
||||||
|
def on_xmldecl_standalone(str)
|
||||||
|
@standalone = str
|
||||||
|
end
|
||||||
|
|
||||||
|
def on_xmldecl_end
|
||||||
|
xmldecl(@version, @encoding, @standalone)
|
||||||
|
end
|
||||||
|
|
||||||
|
alias_method(:on_pi, :instruction)
|
||||||
|
alias_method(:on_chardata, :text)
|
||||||
|
alias_method(:on_cdata, :text)
|
||||||
|
|
||||||
|
def on_etag(name)
|
||||||
|
tag_end(name)
|
||||||
|
end
|
||||||
|
|
||||||
|
def on_entityref(ref)
|
||||||
|
text(ENTITIES[ref])
|
||||||
|
end
|
||||||
|
|
||||||
|
def on_charref(code)
|
||||||
|
text([code].pack('U'))
|
||||||
|
end
|
||||||
|
|
||||||
|
alias_method(:on_charref_hex, :on_charref)
|
||||||
|
|
||||||
|
def on_stag(name)
|
||||||
|
@attrs = {}
|
||||||
|
end
|
||||||
|
|
||||||
|
def on_attribute(name)
|
||||||
|
@attrs[name] = @current_attr = ''
|
||||||
|
end
|
||||||
|
|
||||||
|
def on_attr_value(str)
|
||||||
|
@current_attr << str
|
||||||
|
end
|
||||||
|
|
||||||
|
def on_attr_entityref(ref)
|
||||||
|
@current_attr << ENTITIES[ref]
|
||||||
|
end
|
||||||
|
|
||||||
|
def on_attr_charref(code)
|
||||||
|
@current_attr << [code].pack('U')
|
||||||
|
end
|
||||||
|
|
||||||
|
alias_method(:on_attr_charref_hex, :on_attr_charref)
|
||||||
|
|
||||||
|
def on_stag_end(name)
|
||||||
|
tag_start(name, @attrs)
|
||||||
|
end
|
||||||
|
|
||||||
|
def on_stag_end_empty(name)
|
||||||
|
tag_start(name, @attrs)
|
||||||
|
tag_end(name)
|
||||||
|
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
|
164
test/rss/rss-testcase.rb
Normal file
164
test/rss/rss-testcase.rb
Normal file
|
@ -0,0 +1,164 @@
|
||||||
|
# -*- tab-width: 2 -*- vim: ts=2
|
||||||
|
|
||||||
|
require "test/unit"
|
||||||
|
require 'rss-assertions'
|
||||||
|
|
||||||
|
module RSS
|
||||||
|
class TestCase < Test::Unit::TestCase
|
||||||
|
|
||||||
|
include RSS
|
||||||
|
include Assertions
|
||||||
|
|
||||||
|
XMLDECL_VERSION = "1.0"
|
||||||
|
XMLDECL_ENCODING = "UTF-8"
|
||||||
|
XMLDECL_STANDALONE = "no"
|
||||||
|
|
||||||
|
RDF_ABOUT = "http://www.xml.com/xml/news.rss"
|
||||||
|
RDF_RESOURCE = "http://xml.com/universal/images/xml_tiny.gif"
|
||||||
|
TITLE_VALUE = "XML.com"
|
||||||
|
LINK_VALUE = "http://xml.com/pub"
|
||||||
|
URL_VALUE = "http://xml.com/universal/images/xml_tiny.gif"
|
||||||
|
NAME_VALUE = "hogehoge"
|
||||||
|
DESCRIPTION_VALUE = "
|
||||||
|
XML.com features a rich mix of information and services
|
||||||
|
for the XML community.
|
||||||
|
"
|
||||||
|
RESOURCES = [
|
||||||
|
"http://xml.com/pub/2000/08/09/xslt/xslt.html",
|
||||||
|
"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}'"
|
||||||
|
rv << " encoding='#{e}'" if e
|
||||||
|
rv << " standalone='#{s}'" if s
|
||||||
|
rv << "?>"
|
||||||
|
rv
|
||||||
|
end
|
||||||
|
|
||||||
|
def make_RDF(content=nil, xmlns=[])
|
||||||
|
<<-EORSS
|
||||||
|
#{make_xmldecl}
|
||||||
|
<rdf:RDF xmlns="#{URI}" xmlns:rdf="#{RDF::URI}"
|
||||||
|
#{xmlns.collect {|pre, uri| "xmlns:#{pre}='#{uri}'"}.join(' ')}>
|
||||||
|
#{block_given? ? yield : content}
|
||||||
|
</rdf:RDF>
|
||||||
|
EORSS
|
||||||
|
end
|
||||||
|
|
||||||
|
def make_channel(content=nil)
|
||||||
|
<<-EOC
|
||||||
|
<channel rdf:about="#{RDF_ABOUT}">
|
||||||
|
<title>#{TITLE_VALUE}</title>
|
||||||
|
<link>#{LINK_VALUE}</link>
|
||||||
|
<description>#{DESCRIPTION_VALUE}</description>
|
||||||
|
|
||||||
|
<image rdf:resource="#{RDF_RESOURCE}" />
|
||||||
|
|
||||||
|
<items>
|
||||||
|
<rdf:Seq>
|
||||||
|
#{RESOURCES.collect do |res| '<rdf:li resource="' + res + '" />' end.join("\n")}
|
||||||
|
</rdf:Seq>
|
||||||
|
</items>
|
||||||
|
|
||||||
|
<textinput rdf:resource="#{RDF_RESOURCE}" />
|
||||||
|
|
||||||
|
#{block_given? ? yield : content}
|
||||||
|
</channel>
|
||||||
|
EOC
|
||||||
|
end
|
||||||
|
|
||||||
|
def make_image(content=nil)
|
||||||
|
<<-EOI
|
||||||
|
<image rdf:about="#{RDF_ABOUT}">
|
||||||
|
<title>#{TITLE_VALUE}</title>
|
||||||
|
<url>#{URL_VALUE}</url>
|
||||||
|
<link>#{LINK_VALUE}</link>
|
||||||
|
#{block_given? ? yield : content}
|
||||||
|
</image>
|
||||||
|
EOI
|
||||||
|
end
|
||||||
|
|
||||||
|
def make_item(content=nil)
|
||||||
|
<<-EOI
|
||||||
|
<item rdf:about="#{RDF_ABOUT}">
|
||||||
|
<title>#{TITLE_VALUE}</title>
|
||||||
|
<link>#{LINK_VALUE}</link>
|
||||||
|
<description>#{DESCRIPTION_VALUE}</description>
|
||||||
|
#{block_given? ? yield : content}
|
||||||
|
</item>
|
||||||
|
EOI
|
||||||
|
end
|
||||||
|
|
||||||
|
def make_textinput(content=nil)
|
||||||
|
<<-EOT
|
||||||
|
<textinput rdf:about="#{RDF_ABOUT}">
|
||||||
|
<title>#{TITLE_VALUE}</title>
|
||||||
|
<description>#{DESCRIPTION_VALUE}</description>
|
||||||
|
<name>#{NAME_VALUE}</name>
|
||||||
|
<link>#{LINK_VALUE}</link>
|
||||||
|
#{block_given? ? yield : content}
|
||||||
|
</textinput>
|
||||||
|
EOT
|
||||||
|
end
|
||||||
|
|
||||||
|
def make_sample_RDF
|
||||||
|
make_RDF(<<-EOR)
|
||||||
|
#{make_channel}
|
||||||
|
#{make_image}
|
||||||
|
#{make_item}
|
||||||
|
#{make_textinput}
|
||||||
|
EOR
|
||||||
|
end
|
||||||
|
|
||||||
|
def make_Rss2(content=nil, xmlns=[])
|
||||||
|
<<-EORSS
|
||||||
|
#{make_xmldecl}
|
||||||
|
<rss version="2.0"
|
||||||
|
#{xmlns.collect {|pre, uri| "xmlns:#{pre}='#{uri}'"}.join(' ')}>
|
||||||
|
#{block_given? ? yield : content}
|
||||||
|
</rss>
|
||||||
|
EORSS
|
||||||
|
end
|
||||||
|
|
||||||
|
def make_channel2(content=nil)
|
||||||
|
<<-EOC
|
||||||
|
<channel>
|
||||||
|
<title>#{TITLE_VALUE}</title>
|
||||||
|
<link>#{LINK_VALUE}</link>
|
||||||
|
<description>#{DESCRIPTION_VALUE}</description>
|
||||||
|
|
||||||
|
<image>
|
||||||
|
<url>#{RDF_RESOURCE}</url>
|
||||||
|
<title>#{TITLE_VALUE}</title>
|
||||||
|
<link>#{LINK_VALUE}</link>
|
||||||
|
</image>
|
||||||
|
|
||||||
|
#{RESOURCES.collect do |res| '<item><link>' + res + '</link></item>' end.join("\n")}
|
||||||
|
|
||||||
|
<textInput>
|
||||||
|
<link>#{RDF_RESOURCE}</link>
|
||||||
|
</textInput>
|
||||||
|
|
||||||
|
#{block_given? ? yield : content}
|
||||||
|
</channel>
|
||||||
|
EOC
|
||||||
|
end
|
||||||
|
|
||||||
|
def make_item2(content=nil)
|
||||||
|
<<-EOI
|
||||||
|
<item>
|
||||||
|
<title>#{TITLE_VALUE}</title>
|
||||||
|
<link>#{LINK_VALUE}</link>
|
||||||
|
<description>#{DESCRIPTION_VALUE}</description>
|
||||||
|
#{block_given? ? yield : content}
|
||||||
|
</item>
|
||||||
|
EOI
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
259
test/rss/test_1.0.rb
Normal file
259
test/rss/test_1.0.rb
Normal file
|
@ -0,0 +1,259 @@
|
||||||
|
# -*- tab-width: 2 -*- vim: ts=2
|
||||||
|
|
||||||
|
require "rexml/document"
|
||||||
|
|
||||||
|
require "rss-testcase"
|
||||||
|
|
||||||
|
require "rss/1.0"
|
||||||
|
|
||||||
|
module RSS
|
||||||
|
class TestCore < TestCase
|
||||||
|
|
||||||
|
def setup
|
||||||
|
|
||||||
|
@rdf_prefix = "rdf"
|
||||||
|
@rdf_uri = "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||||
|
@uri = "http://purl.org/rss/1.0/"
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_RDF
|
||||||
|
|
||||||
|
version = "1.0"
|
||||||
|
encoding = "UTF-8"
|
||||||
|
standalone = "no"
|
||||||
|
|
||||||
|
rdf = RDF.new(version, encoding, standalone)
|
||||||
|
|
||||||
|
doc = REXML::Document.new(rdf.to_s(false))
|
||||||
|
|
||||||
|
xmldecl = doc.xml_decl
|
||||||
|
|
||||||
|
%w(version encoding standalone).each do |x|
|
||||||
|
assert_equal(instance_eval(x), xmldecl.send(x))
|
||||||
|
end
|
||||||
|
|
||||||
|
assert_equal(@rdf_uri, doc.root.namespace)
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_not_displayed_xml_stylesheets
|
||||||
|
rdf = RDF.new()
|
||||||
|
plain_rdf = rdf.to_s
|
||||||
|
3.times do
|
||||||
|
rdf.xml_stylesheets.push(XMLStyleSheet.new)
|
||||||
|
assert_equal(plain_rdf, rdf.to_s)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_xml_stylesheets
|
||||||
|
[
|
||||||
|
[{:href => "a.xsl", :type => "text/xsl"}],
|
||||||
|
[
|
||||||
|
{:href => "a.xsl", :type => "text/xsl"},
|
||||||
|
{:href => "a.css", :type => "text/css"},
|
||||||
|
],
|
||||||
|
].each do |attrs_ary|
|
||||||
|
assert_xml_stylesheet_pis(attrs_ary)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_channel
|
||||||
|
about = "http://hoge.com"
|
||||||
|
title = "fugafuga"
|
||||||
|
link = "http://hoge.com"
|
||||||
|
description = "fugafugafugafuga"
|
||||||
|
resource = "http://hoge.com/hoge.png"
|
||||||
|
image = RDF::Channel::Image.new(resource)
|
||||||
|
items = RDF::Channel::Items.new
|
||||||
|
textinput = RDF::Channel::Textinput.new(resource)
|
||||||
|
|
||||||
|
channel = RDF::Channel.new(about)
|
||||||
|
%w(title link description image items textinput).each do |x|
|
||||||
|
channel.send("#{x}=", instance_eval(x))
|
||||||
|
end
|
||||||
|
|
||||||
|
doc = REXML::Document.new(make_RDF(channel.to_s))
|
||||||
|
c = doc.root.elements[1]
|
||||||
|
|
||||||
|
assert_equal(about, c.attributes["about"])
|
||||||
|
%w(title link description image textinput).each do |x|
|
||||||
|
elem = c.elements[x]
|
||||||
|
assert_equal(x, elem.name)
|
||||||
|
assert_equal(@uri, elem.namespace)
|
||||||
|
if x == "image" or x == "textinput"
|
||||||
|
excepted = resource
|
||||||
|
res = elem.attributes.get_attribute("resource")
|
||||||
|
assert_equal(@rdf_uri, res.namespace)
|
||||||
|
value = res.value
|
||||||
|
else
|
||||||
|
excepted = instance_eval(x)
|
||||||
|
value = elem.text
|
||||||
|
end
|
||||||
|
assert_equal(excepted, value)
|
||||||
|
end
|
||||||
|
assert_equal(@uri, c.elements["items"].namespace)
|
||||||
|
assert_equal("items", c.elements["items"].name)
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_channel_image
|
||||||
|
|
||||||
|
resource = "http://hoge.com/hoge.png"
|
||||||
|
image = RDF::Channel::Image.new(resource)
|
||||||
|
|
||||||
|
doc = REXML::Document.new(make_RDF(image.to_s))
|
||||||
|
i = doc.root.elements[1]
|
||||||
|
|
||||||
|
assert_equal("image", i.name)
|
||||||
|
assert_equal(@uri, i.namespace)
|
||||||
|
|
||||||
|
res = i.attributes.get_attribute("resource")
|
||||||
|
|
||||||
|
assert_equal(@rdf_uri, res.namespace)
|
||||||
|
assert_equal(resource, res.value)
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_channel_textinput
|
||||||
|
|
||||||
|
resource = "http://hoge.com/hoge.png"
|
||||||
|
textinput = RDF::Channel::Textinput.new(resource)
|
||||||
|
|
||||||
|
doc = REXML::Document.new(make_RDF(textinput.to_s))
|
||||||
|
t = doc.root.elements[1]
|
||||||
|
|
||||||
|
assert_equal("textinput", t.name)
|
||||||
|
assert_equal(@uri, t.namespace)
|
||||||
|
|
||||||
|
res = t.attributes.get_attribute("resource")
|
||||||
|
|
||||||
|
assert_equal(@rdf_uri, res.namespace)
|
||||||
|
assert_equal(resource, res.value)
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_items
|
||||||
|
|
||||||
|
items = RDF::Channel::Items.new
|
||||||
|
|
||||||
|
doc = REXML::Document.new(make_RDF(items.to_s))
|
||||||
|
i = doc.root.elements[1]
|
||||||
|
|
||||||
|
assert_equal("items", i.name)
|
||||||
|
assert_equal(@uri, i.namespace)
|
||||||
|
|
||||||
|
assert_equal(1, i.elements.size)
|
||||||
|
assert_equal("Seq", i.elements[1].name)
|
||||||
|
assert_equal(@rdf_uri, i.elements[1].namespace)
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_seq
|
||||||
|
|
||||||
|
seq = RDF::Seq.new
|
||||||
|
|
||||||
|
doc = REXML::Document.new(make_RDF(seq.to_s))
|
||||||
|
s = doc.root.elements[1]
|
||||||
|
|
||||||
|
assert_equal("Seq", s.name)
|
||||||
|
assert_equal(@rdf_uri, s.namespace)
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_li
|
||||||
|
|
||||||
|
resource = "http://hoge.com/"
|
||||||
|
li = RDF::Li.new(resource)
|
||||||
|
|
||||||
|
doc = REXML::Document.new(make_RDF(li.to_s))
|
||||||
|
l = doc.root.elements[1]
|
||||||
|
|
||||||
|
assert_equal("li", l.name)
|
||||||
|
assert_equal(@rdf_uri, l.namespace(l.prefix))
|
||||||
|
|
||||||
|
res = l.attributes.get_attribute("resource")
|
||||||
|
|
||||||
|
assert_equal('', res.instance_eval("@prefix"))
|
||||||
|
assert_equal(resource, res.value)
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_image
|
||||||
|
|
||||||
|
about = "http://hoge.com"
|
||||||
|
title = "fugafuga"
|
||||||
|
url = "http://hoge.com/hoge"
|
||||||
|
link = "http://hoge.com/fuga"
|
||||||
|
|
||||||
|
image = RDF::Image.new(about)
|
||||||
|
%w(title url link).each do |x|
|
||||||
|
image.send("#{x}=", instance_eval(x))
|
||||||
|
end
|
||||||
|
|
||||||
|
doc = REXML::Document.new(make_RDF(image.to_s))
|
||||||
|
i = doc.root.elements[1]
|
||||||
|
|
||||||
|
assert_equal(about, i.attributes["about"])
|
||||||
|
%w(title url link).each do |x|
|
||||||
|
elem = i.elements[x]
|
||||||
|
assert_equal(x, elem.name)
|
||||||
|
assert_equal(@uri, elem.namespace)
|
||||||
|
assert_equal(instance_eval(x), elem.text)
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_item
|
||||||
|
|
||||||
|
about = "http://hoge.com"
|
||||||
|
title = "fugafuga"
|
||||||
|
link = "http://hoge.com/fuga"
|
||||||
|
description = "hogehogehoge"
|
||||||
|
|
||||||
|
item = RDF::Item.new(about)
|
||||||
|
%w(title link description).each do |x|
|
||||||
|
item.send("#{x}=", instance_eval(x))
|
||||||
|
end
|
||||||
|
|
||||||
|
doc = REXML::Document.new(make_RDF(item.to_s))
|
||||||
|
i = doc.root.elements[1]
|
||||||
|
|
||||||
|
assert_equal(about, i.attributes["about"])
|
||||||
|
%w(title link description).each do |x|
|
||||||
|
elem = i.elements[x]
|
||||||
|
assert_equal(x, elem.name)
|
||||||
|
assert_equal(@uri, elem.namespace)
|
||||||
|
assert_equal(instance_eval(x), elem.text)
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_textinput
|
||||||
|
|
||||||
|
about = "http://hoge.com"
|
||||||
|
title = "fugafuga"
|
||||||
|
link = "http://hoge.com/fuga"
|
||||||
|
name = "foo"
|
||||||
|
description = "hogehogehoge"
|
||||||
|
|
||||||
|
textinput = RDF::Textinput.new(about)
|
||||||
|
%w(title link name description).each do |x|
|
||||||
|
textinput.send("#{x}=", instance_eval(x))
|
||||||
|
end
|
||||||
|
|
||||||
|
doc = REXML::Document.new(make_RDF(textinput.to_s))
|
||||||
|
t = doc.root.elements[1]
|
||||||
|
|
||||||
|
assert_equal(about, t.attributes["about"])
|
||||||
|
%w(title link name description).each do |x|
|
||||||
|
elem = t.elements[x]
|
||||||
|
assert_equal(x, elem.name)
|
||||||
|
assert_equal(@uri, elem.namespace)
|
||||||
|
assert_equal(instance_eval(x), elem.text)
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
26
test/rss/test_accessor.rb
Normal file
26
test/rss/test_accessor.rb
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
# -*- tab-width: 2 -*- vim: ts=2
|
||||||
|
|
||||||
|
require "rss-testcase"
|
||||||
|
|
||||||
|
require "rss/1.0"
|
||||||
|
require "rss/2.0"
|
||||||
|
|
||||||
|
module RSS
|
||||||
|
class TestAccessor < TestCase
|
||||||
|
|
||||||
|
def test_date
|
||||||
|
channel = Rss::Channel.new
|
||||||
|
channel.do_validate = false
|
||||||
|
channel.pubDate = nil
|
||||||
|
assert_nil(channel.pubDate)
|
||||||
|
|
||||||
|
time = Time.now
|
||||||
|
channel.pubDate = time
|
||||||
|
assert_equal(time, channel.pubDate)
|
||||||
|
|
||||||
|
channel.pubDate = nil
|
||||||
|
assert_nil(channel.pubDate)
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
97
test/rss/test_content.rb
Normal file
97
test/rss/test_content.rb
Normal file
|
@ -0,0 +1,97 @@
|
||||||
|
# -*- tab-width: 2 -*- vim: ts=2
|
||||||
|
|
||||||
|
require "cgi"
|
||||||
|
require "rexml/document"
|
||||||
|
|
||||||
|
require "rss-testcase"
|
||||||
|
|
||||||
|
require "rss/1.0"
|
||||||
|
require "rss/content"
|
||||||
|
|
||||||
|
module RSS
|
||||||
|
class TestContent < TestCase
|
||||||
|
|
||||||
|
def setup
|
||||||
|
@prefix = "content"
|
||||||
|
@uri = "http://purl.org/rss/1.0/modules/content/"
|
||||||
|
|
||||||
|
@parents = %w(item)
|
||||||
|
|
||||||
|
@elems = {
|
||||||
|
:encoded => "<em>ATTENTION</em>",
|
||||||
|
}
|
||||||
|
|
||||||
|
@content_nodes = @elems.collect do |name, value|
|
||||||
|
"<#{@prefix}:#{name}>#{CGI.escapeHTML(value.to_s)}</#{@prefix}:#{name}>"
|
||||||
|
end.join("\n")
|
||||||
|
|
||||||
|
@rss_source = make_RDF(<<-EOR, {@prefix => @uri})
|
||||||
|
#{make_channel()}
|
||||||
|
#{make_image()}
|
||||||
|
#{make_item(@content_nodes)}
|
||||||
|
#{make_textinput()}
|
||||||
|
EOR
|
||||||
|
|
||||||
|
@rss = Parser.parse(@rss_source)
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_parser
|
||||||
|
|
||||||
|
assert_nothing_raised do
|
||||||
|
Parser.parse(@rss_source)
|
||||||
|
end
|
||||||
|
|
||||||
|
@elems.each do |tag, value|
|
||||||
|
assert_too_much_tag(tag.to_s, "item") do
|
||||||
|
Parser.parse(make_RDF(<<-EOR, {@prefix => @uri}))
|
||||||
|
#{make_channel()}
|
||||||
|
#{make_item(("<" + @prefix + ":" + tag.to_s + ">" +
|
||||||
|
CGI.escapeHTML(value.to_s) +
|
||||||
|
"</" + @prefix + ":" + tag.to_s + ">") * 2)}
|
||||||
|
EOR
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_accessor
|
||||||
|
|
||||||
|
new_value = {
|
||||||
|
:encoded => "<![CDATA[<it>hoge</it>]]>",
|
||||||
|
}
|
||||||
|
|
||||||
|
@elems.each do |name, value|
|
||||||
|
@parents.each do |parent|
|
||||||
|
meth = "#{RSS::CONTENT_PREFIX}_#{name}"
|
||||||
|
assert_equal(value, @rss.send(parent).send(meth))
|
||||||
|
@rss.send(parent).send("#{meth}=", new_value[name].to_s)
|
||||||
|
assert_equal(new_value[name], @rss.send(parent).send(meth))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_to_s
|
||||||
|
|
||||||
|
@elems.each do |name, value|
|
||||||
|
excepted = "<#{@prefix}:#{name}>#{CGI.escapeHTML(value)}</#{@prefix}:#{name}>"
|
||||||
|
@parents.each do |parent|
|
||||||
|
meth = "#{RSS::CONTENT_PREFIX}_#{name}_element"
|
||||||
|
assert_equal(excepted, @rss.send(parent).send(meth))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
REXML::Document.new(@rss_source).root.each_element do |parent|
|
||||||
|
if @parents.include?(parent.name)
|
||||||
|
parent.each_element do |elem|
|
||||||
|
if elem.namespace == @uri
|
||||||
|
assert_equal(elem.text, @elems[elem.name.intern].to_s)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
126
test/rss/test_dublincore.rb
Normal file
126
test/rss/test_dublincore.rb
Normal file
|
@ -0,0 +1,126 @@
|
||||||
|
# -*- tab-width: 2 -*- vim: ts=2
|
||||||
|
|
||||||
|
require "cgi"
|
||||||
|
require "rexml/document"
|
||||||
|
|
||||||
|
require "rss-testcase"
|
||||||
|
|
||||||
|
require "rss/1.0"
|
||||||
|
require "rss/dublincore"
|
||||||
|
|
||||||
|
module RSS
|
||||||
|
class TestDublinCore < TestCase
|
||||||
|
|
||||||
|
def setup
|
||||||
|
@prefix = "dc"
|
||||||
|
@uri = "http://purl.org/dc/elements/1.1/"
|
||||||
|
|
||||||
|
@parents = %w(channel image item textinput)
|
||||||
|
|
||||||
|
t = Time.iso8601("2000-01-01T12:00:05+00:00")
|
||||||
|
class << t
|
||||||
|
alias_method(:to_s, :iso8601)
|
||||||
|
end
|
||||||
|
|
||||||
|
@elems = {
|
||||||
|
:title => "hoge",
|
||||||
|
:description =>
|
||||||
|
" 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",
|
||||||
|
:contributor => "hogehoge",
|
||||||
|
:type => "fugafuga",
|
||||||
|
:format => "hohoho",
|
||||||
|
:identifier => "fufufu",
|
||||||
|
:source => "barbar",
|
||||||
|
:language => "ja",
|
||||||
|
:relation => "cococo",
|
||||||
|
:rights => "Copyright (c) 2000 O'Reilly & Associates, Inc.",
|
||||||
|
:date => t,
|
||||||
|
}
|
||||||
|
|
||||||
|
@dc_nodes = @elems.collect do |name, value|
|
||||||
|
"<#{@prefix}:#{name}>#{value}</#{@prefix}:#{name}>"
|
||||||
|
end.join("\n")
|
||||||
|
|
||||||
|
@rss_source = make_RDF(<<-EOR, {@prefix => @uri})
|
||||||
|
#{make_channel(@dc_nodes)}
|
||||||
|
#{make_image(@dc_nodes)}
|
||||||
|
#{make_item(@dc_nodes)}
|
||||||
|
#{make_textinput(@dc_nodes)}
|
||||||
|
EOR
|
||||||
|
|
||||||
|
@rss = Parser.parse(@rss_source)
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_parser
|
||||||
|
|
||||||
|
assert_nothing_raised do
|
||||||
|
Parser.parse(@rss_source)
|
||||||
|
end
|
||||||
|
|
||||||
|
@elems.each do |tag, value|
|
||||||
|
assert_too_much_tag(tag.to_s, "channel") do
|
||||||
|
Parser.parse(make_RDF(<<-EOR, {@prefix => @uri}))
|
||||||
|
#{make_channel(("<" + @prefix + ":" + tag.to_s + ">" +
|
||||||
|
value.to_s +
|
||||||
|
"</" + @prefix + ":" + tag.to_s + ">") * 2)}
|
||||||
|
#{make_item}
|
||||||
|
EOR
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_accessor
|
||||||
|
|
||||||
|
new_value = "hoge"
|
||||||
|
|
||||||
|
@elems.each do |name, value|
|
||||||
|
@parents.each do |parent|
|
||||||
|
parsed_value = @rss.send(parent).send("dc_#{name}")
|
||||||
|
if parsed_value.kind_of?(String)
|
||||||
|
parsed_value = CGI.escapeHTML(parsed_value)
|
||||||
|
end
|
||||||
|
assert_equal(value, parsed_value)
|
||||||
|
if name == :date
|
||||||
|
t = Time.iso8601("2003-01-01T02:30:23+09:00")
|
||||||
|
class << t
|
||||||
|
alias_method(:to_s, :iso8601)
|
||||||
|
end
|
||||||
|
@rss.send(parent).send("dc_#{name}=", t.iso8601)
|
||||||
|
assert_equal(t, @rss.send(parent).send("dc_#{name}"))
|
||||||
|
else
|
||||||
|
@rss.send(parent).send("dc_#{name}=", new_value)
|
||||||
|
assert_equal(new_value, @rss.send(parent).send("dc_#{name}"))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_to_s
|
||||||
|
|
||||||
|
@elems.each do |name, value|
|
||||||
|
excepted = "<#{@prefix}:#{name}>#{value}</#{@prefix}:#{name}>"
|
||||||
|
@parents.each do |parent|
|
||||||
|
assert_equal(excepted, @rss.send(parent).send("dc_#{name}_element"))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
REXML::Document.new(@rss_source).root.each_element do |parent|
|
||||||
|
if @parents.include?(parent.name)
|
||||||
|
parent.each_element do |elem|
|
||||||
|
if elem.namespace == @uri
|
||||||
|
assert_equal(CGI.escapeHTML(elem.text), @elems[elem.name.intern].to_s)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
125
test/rss/test_syndication.rb
Normal file
125
test/rss/test_syndication.rb
Normal file
|
@ -0,0 +1,125 @@
|
||||||
|
# -*- tab-width: 2 -*- vim: ts=2
|
||||||
|
|
||||||
|
require "cgi"
|
||||||
|
require "rexml/document"
|
||||||
|
|
||||||
|
require "rss-testcase"
|
||||||
|
|
||||||
|
require "rss/1.0"
|
||||||
|
require "rss/syndication"
|
||||||
|
|
||||||
|
module RSS
|
||||||
|
class TestSyndication < TestCase
|
||||||
|
|
||||||
|
def setup
|
||||||
|
@prefix = "sy"
|
||||||
|
@uri = "http://purl.org/rss/1.0/modules/syndication/"
|
||||||
|
|
||||||
|
@parents = %w(channel)
|
||||||
|
|
||||||
|
t = Time.iso8601("2000-01-01T12:00:05+00:00")
|
||||||
|
class << t
|
||||||
|
alias_method(:to_s, :iso8601)
|
||||||
|
end
|
||||||
|
|
||||||
|
@elems = {
|
||||||
|
:updatePeriod => "hourly",
|
||||||
|
:updateFrequency => 2,
|
||||||
|
:updateBase => t,
|
||||||
|
}
|
||||||
|
|
||||||
|
@sy_nodes = @elems.collect do |name, value|
|
||||||
|
"<#{@prefix}:#{name}>#{CGI.escapeHTML(value.to_s)}</#{@prefix}:#{name}>"
|
||||||
|
end.join("\n")
|
||||||
|
|
||||||
|
@rss_source = make_RDF(<<-EOR, {@prefix => @uri})
|
||||||
|
#{make_channel(@sy_nodes)}
|
||||||
|
#{make_image()}
|
||||||
|
#{make_item()}
|
||||||
|
#{make_textinput()}
|
||||||
|
EOR
|
||||||
|
|
||||||
|
@rss = Parser.parse(@rss_source)
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_parser
|
||||||
|
|
||||||
|
assert_nothing_raised do
|
||||||
|
Parser.parse(@rss_source)
|
||||||
|
end
|
||||||
|
|
||||||
|
@elems.each do |tag, value|
|
||||||
|
assert_too_much_tag(tag.to_s, "channel") do
|
||||||
|
Parser.parse(make_RDF(<<-EOR, {@prefix => @uri}))
|
||||||
|
#{make_channel(("<" + @prefix + ":" + tag.to_s + ">" +
|
||||||
|
CGI.escapeHTML(value.to_s) +
|
||||||
|
"</" + @prefix + ":" + tag.to_s + ">") * 2)}
|
||||||
|
#{make_item}
|
||||||
|
EOR
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_accessor
|
||||||
|
|
||||||
|
t = Time.iso8601("2003-01-01T12:00:23+09:00")
|
||||||
|
class << t
|
||||||
|
alias_method(:to_s, :iso8601)
|
||||||
|
end
|
||||||
|
|
||||||
|
new_value = {
|
||||||
|
:updatePeriod => "daily",
|
||||||
|
:updateFrequency => +11,
|
||||||
|
:updateBase => t,
|
||||||
|
}
|
||||||
|
|
||||||
|
@elems.each do |name, value|
|
||||||
|
@parents.each do |parent|
|
||||||
|
assert_equal(value, @rss.send(parent).send("sy_#{name}"))
|
||||||
|
@rss.send(parent).send("sy_#{name}=", new_value[name].to_s)
|
||||||
|
assert_equal(new_value[name], @rss.send(parent).send("sy_#{name}"))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
%w(hourly daily weekly monthly yearly).each do |x|
|
||||||
|
@parents.each do |parent|
|
||||||
|
assert_nothing_raised do
|
||||||
|
@rss.send(parent).sy_updatePeriod = x
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
%w(-2 0.3 -0.4).each do |x|
|
||||||
|
@parents.each do |parent|
|
||||||
|
assert_not_available_value("updateBase", x) do
|
||||||
|
@rss.send(parent).sy_updateBase = x
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_to_s
|
||||||
|
|
||||||
|
@elems.each do |name, value|
|
||||||
|
excepted = "<#{@prefix}:#{name}>#{value}</#{@prefix}:#{name}>"
|
||||||
|
@parents.each do |parent|
|
||||||
|
assert_equal(excepted, @rss.send(parent).send("sy_#{name}_element"))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
REXML::Document.new(@rss_source).root.each_element do |parent|
|
||||||
|
if @parents.include?(parent.name)
|
||||||
|
parent.each_element do |elem|
|
||||||
|
if elem.namespace == @uri
|
||||||
|
assert_equal(elem.text, @elems[elem.name.intern].to_s)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
137
test/rss/test_trackback.rb
Normal file
137
test/rss/test_trackback.rb
Normal file
|
@ -0,0 +1,137 @@
|
||||||
|
# -*- tab-width: 2 -*- vim: ts=2
|
||||||
|
|
||||||
|
require "cgi"
|
||||||
|
require "rexml/document"
|
||||||
|
|
||||||
|
require "rss-testcase"
|
||||||
|
|
||||||
|
require "rss/1.0"
|
||||||
|
require "rss/2.0"
|
||||||
|
require "rss/trackback"
|
||||||
|
|
||||||
|
module RSS
|
||||||
|
class TestTrackBack < TestCase
|
||||||
|
|
||||||
|
def setup
|
||||||
|
@prefix = "trackback"
|
||||||
|
@uri = "http://madskills.com/public/xml/rss/module/trackback/"
|
||||||
|
|
||||||
|
@parents = %w(item)
|
||||||
|
|
||||||
|
@elems = {
|
||||||
|
:ping => "http://bar.com/tb.cgi?tb_id=rssplustrackback",
|
||||||
|
:about => "http://foo.com/trackback/tb.cgi?tb_id=20020923",
|
||||||
|
}
|
||||||
|
|
||||||
|
@content_nodes = @elems.collect do |name, value|
|
||||||
|
"<#{@prefix}:#{name} rdf:resource=\"#{CGI.escapeHTML(value.to_s)}\"/>"
|
||||||
|
end.join("\n")
|
||||||
|
|
||||||
|
@content_nodes2 = @elems.collect do |name, value|
|
||||||
|
"<#{@prefix}:#{name}>#{CGI.escapeHTML(value.to_s)}</#{@prefix}:#{name}>"
|
||||||
|
end.join("\n")
|
||||||
|
|
||||||
|
@rss_source = make_RDF(<<-EOR, {@prefix => @uri})
|
||||||
|
#{make_channel()}
|
||||||
|
#{make_image()}
|
||||||
|
#{make_item(@content_nodes)}
|
||||||
|
#{make_textinput()}
|
||||||
|
EOR
|
||||||
|
|
||||||
|
@rss = Parser.parse(@rss_source)
|
||||||
|
|
||||||
|
@rss2_source = make_Rss2(nil, {@prefix => @uri}) do
|
||||||
|
make_channel2(nil) do
|
||||||
|
make_item2(@content_nodes2)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
@rss2 = Parser.parse(@rss2_source, false)
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_parser
|
||||||
|
|
||||||
|
assert_nothing_raised do
|
||||||
|
Parser.parse(@rss_source)
|
||||||
|
end
|
||||||
|
|
||||||
|
@elems.find_all{|k, v| k == :ping}.each do |tag, value|
|
||||||
|
assert_too_much_tag(tag.to_s, "item") do
|
||||||
|
Parser.parse(make_RDF(<<-EOR, {@prefix => @uri}))
|
||||||
|
#{make_channel()}
|
||||||
|
#{make_item(("<" + @prefix + ":" + tag.to_s + " rdf:resource=\"" +
|
||||||
|
CGI.escapeHTML(value.to_s) +
|
||||||
|
"\"/>") * 2)}
|
||||||
|
EOR
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
@elems.find_all{|k, v| k == :about}.each do |tag, value|
|
||||||
|
assert_missing_tag("trackback:ping", "item") do
|
||||||
|
Parser.parse(make_RDF(<<-EOR, {@prefix => @uri}))
|
||||||
|
#{make_channel()}
|
||||||
|
#{make_item(("<" + @prefix + ":" + tag.to_s + " rdf:resource=\"" +
|
||||||
|
CGI.escapeHTML(value.to_s) +
|
||||||
|
"\"/>") * 2)}
|
||||||
|
EOR
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_accessor
|
||||||
|
|
||||||
|
new_value = {
|
||||||
|
:ping => "http://baz.com/trackback/tb.cgi?tb_id=20030808",
|
||||||
|
:about => "http://hoge.com/trackback/tb.cgi?tb_id=90030808",
|
||||||
|
}
|
||||||
|
|
||||||
|
@elems.each do |name, value|
|
||||||
|
@parents.each do |parent|
|
||||||
|
accessor = "#{RSS::TRACKBACK_PREFIX}_#{name}"
|
||||||
|
target_accessor = "resource"
|
||||||
|
target = @rss.send(parent).send(accessor)
|
||||||
|
target2 = @rss2.channel.send(parent, -1)
|
||||||
|
assert_equal(value, target.send(target_accessor))
|
||||||
|
assert_equal(value, target2.send(accessor))
|
||||||
|
target.send("#{target_accessor}=", new_value[name].to_s)
|
||||||
|
if name == :about
|
||||||
|
# abount is zero or more
|
||||||
|
target2.send("#{accessor}=", 0, new_value[name].to_s)
|
||||||
|
else
|
||||||
|
target2.send("#{accessor}=", new_value[name].to_s)
|
||||||
|
end
|
||||||
|
assert_equal(new_value[name], target.send(target_accessor))
|
||||||
|
assert_equal(new_value[name], target2.send(accessor))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_to_s
|
||||||
|
|
||||||
|
@elems.each do |name, value|
|
||||||
|
excepted = %Q!<#{@prefix}:#{name} rdf:resource="#{CGI.escapeHTML(value)}"/>!
|
||||||
|
@parents.each do |parent|
|
||||||
|
meth = "#{RSS::TRACKBACK_PREFIX}_#{name}_element"
|
||||||
|
meth << "s" if name == :about
|
||||||
|
assert_equal(excepted, @rss.send(parent).send(meth))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
REXML::Document.new(@rss_source).root.each_element do |parent|
|
||||||
|
if @parents.include?(parent.name)
|
||||||
|
parent.each_element do |elem|
|
||||||
|
if elem.namespace == @uri
|
||||||
|
assert_equal(elem.attributes["resource"], @elems[elem.name.intern])
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
110
test/rss/test_xml-stylesheet.rb
Normal file
110
test/rss/test_xml-stylesheet.rb
Normal file
|
@ -0,0 +1,110 @@
|
||||||
|
# -*- tab-width: 2 -*- vim: ts=2
|
||||||
|
|
||||||
|
require "rexml/document"
|
||||||
|
|
||||||
|
require "rss-testcase"
|
||||||
|
|
||||||
|
require "rss/1.0"
|
||||||
|
require "rss/xml-stylesheet"
|
||||||
|
|
||||||
|
module RSS
|
||||||
|
class TestXMLStyleSheet < TestCase
|
||||||
|
|
||||||
|
def test_accessor
|
||||||
|
[
|
||||||
|
{:href => "a.xsl", :type => "text/xsl"},
|
||||||
|
{:media => "print", :title => "FOO"},
|
||||||
|
{:charset => "UTF-8", :alternate => "yes"},
|
||||||
|
].each do |attrs|
|
||||||
|
assert_xml_stylesheet_attrs(XMLStyleSheet.new(*attrs), attrs)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_to_s
|
||||||
|
[
|
||||||
|
{:href => "a.xsl", :type => "text/xsl"},
|
||||||
|
{:type => "text/xsl"},
|
||||||
|
{:href => "a.xsl", :guess_type => "text/xsl"},
|
||||||
|
{:href => "a.css", :type => "text/css"},
|
||||||
|
{:href => "a.css", :type => "text/xsl",
|
||||||
|
:guess_type => "text/css"},
|
||||||
|
{:href => "a.xsl", :type => "text/xsl",
|
||||||
|
:title => "sample", :media => "printer",
|
||||||
|
:charset => "UTF-8", :alternate => "yes"},
|
||||||
|
{:href => "a.css", :guess_type => "text/css",
|
||||||
|
:alternate => "no"},
|
||||||
|
{:type => "text/xsl", :title => "sample",
|
||||||
|
:media => "printer", :charset => "UTF-8",
|
||||||
|
:alternate => "yes"},
|
||||||
|
].each do |attrs|
|
||||||
|
target, contents = parse_pi(XMLStyleSheet.new(*attrs).to_s)
|
||||||
|
assert_xml_stylesheet(target, XMLStyleSheet.new(*contents), attrs)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_bad_alternate
|
||||||
|
%w(a ___ ??? BAD_ALTERNATE).each do |value|
|
||||||
|
xss = XMLStyleSheet.new
|
||||||
|
assert_raise(NotAvailableValueError) do
|
||||||
|
xss.alternate = value
|
||||||
|
end
|
||||||
|
xss.do_validate = false
|
||||||
|
assert_nothing_raised do
|
||||||
|
xss.alternate = value
|
||||||
|
end
|
||||||
|
assert_nil(xss.alternate)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_parse
|
||||||
|
[
|
||||||
|
[{:href => "a.xsl", :type => "text/xsl"},],
|
||||||
|
[{:media => "print", :title => "FOO"},],
|
||||||
|
[{:charset => "UTF-8", :alternate => "yes"},],
|
||||||
|
[{:href => "a.xsl", :type => "text/xsl"},
|
||||||
|
{:type => "text/xsl"},
|
||||||
|
{:href => "a.xsl", :guess_type => "text/xsl"},
|
||||||
|
{:href => "a.css", :type => "text/css"},
|
||||||
|
{:href => "a.css", :type => "text/xsl",
|
||||||
|
:guess_type => "text/css"},
|
||||||
|
{:href => "a.xsl", :type => "text/xsl",
|
||||||
|
:title => "sample", :media => "printer",
|
||||||
|
:charset => "UTF-8", :alternate => "yes"},
|
||||||
|
{:href => "a.css", :guess_type => "text/css",
|
||||||
|
:alternate => "no"},
|
||||||
|
{:type => "text/xsl", :title => "sample",
|
||||||
|
:media => "printer", :charset => "UTF-8",
|
||||||
|
:alternate => "yes"},],
|
||||||
|
].each do |xsss|
|
||||||
|
doc = REXML::Document.new(make_sample_RDF)
|
||||||
|
root = doc.root
|
||||||
|
xsss.each do |xss|
|
||||||
|
content = xss.collect do |key, name|
|
||||||
|
%Q[#{key}="#{name}"]
|
||||||
|
end.join(" ")
|
||||||
|
pi = REXML::Instruction.new("xml-stylesheet", content)
|
||||||
|
root.previous_sibling = pi
|
||||||
|
end
|
||||||
|
rss = Parser.parse(doc.to_s)
|
||||||
|
have_href_xsss = xsss.find_all {|xss| xss.has_key?(:href)}
|
||||||
|
assert_equal(have_href_xsss.size, rss.xml_stylesheets.size)
|
||||||
|
rss.xml_stylesheets.each_with_index do |stylesheet, i|
|
||||||
|
target, = parse_pi(stylesheet.to_s)
|
||||||
|
assert_xml_stylesheet(target, stylesheet, have_href_xsss[i])
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def parse_pi(pi)
|
||||||
|
/\A\s*<\?(\S+)([^(?:\?>)]+)\?>\s*\z/ =~ pi
|
||||||
|
target = $1
|
||||||
|
dummy = REXML::Document.new("<dummy #{$2}/>").root
|
||||||
|
contents = {}
|
||||||
|
dummy.attributes.each do |name, value|
|
||||||
|
contents[name] = value
|
||||||
|
end
|
||||||
|
[target, contents]
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
73
test/ruby/test_time.rb
Normal file
73
test/ruby/test_time.rb
Normal file
|
@ -0,0 +1,73 @@
|
||||||
|
require 'test/unit'
|
||||||
|
|
||||||
|
class TestTime < Test::Unit::TestCase
|
||||||
|
def test_time_add()
|
||||||
|
assert_equal(Time.utc(2000, 3, 21, 3, 30) + 3 * 3600,
|
||||||
|
Time.utc(2000, 3, 21, 6, 30))
|
||||||
|
assert_equal(Time.utc(2000, 3, 21, 3, 30) + (-3 * 3600),
|
||||||
|
Time.utc(2000, 3, 21, 0, 30))
|
||||||
|
assert_equal(0, (Time.at(1.1) + 0.9).usec)
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_time_subt()
|
||||||
|
assert_equal(Time.utc(2000, 3, 21, 3, 30) - 3 * 3600,
|
||||||
|
Time.utc(2000, 3, 21, 0, 30))
|
||||||
|
assert_equal(Time.utc(2000, 3, 21, 3, 30) - (-3 * 3600),
|
||||||
|
Time.utc(2000, 3, 21, 6, 30))
|
||||||
|
assert_equal(900000, (Time.at(1.1) - 0.2).usec)
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_time_time()
|
||||||
|
assert_equal(Time.utc(2000, 3, 21, 3, 30) \
|
||||||
|
-Time.utc(2000, 3, 21, 0, 30), 3*3600)
|
||||||
|
assert_equal(Time.utc(2000, 3, 21, 0, 30) \
|
||||||
|
-Time.utc(2000, 3, 21, 3, 30), -3*3600)
|
||||||
|
end
|
||||||
|
|
||||||
|
def negative_time_t?
|
||||||
|
begin
|
||||||
|
Time.at(-1)
|
||||||
|
true
|
||||||
|
rescue ArgumentError
|
||||||
|
false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_timegm
|
||||||
|
if negative_time_t?
|
||||||
|
assert_equal(-0x80000000, Time.utc(1901, 12, 13, 20, 45, 52).tv_sec)
|
||||||
|
assert_equal(-2, Time.utc(1969, 12, 31, 23, 59, 58).tv_sec)
|
||||||
|
assert_equal(-1, Time.utc(1969, 12, 31, 23, 59, 59).tv_sec)
|
||||||
|
end
|
||||||
|
|
||||||
|
assert_equal(0, Time.utc(1970, 1, 1, 0, 0, 0).tv_sec) # the Epoch
|
||||||
|
assert_equal(1, Time.utc(1970, 1, 1, 0, 0, 1).tv_sec)
|
||||||
|
assert_equal(31535999, Time.utc(1970, 12, 31, 23, 59, 59).tv_sec)
|
||||||
|
assert_equal(31536000, Time.utc(1971, 1, 1, 0, 0, 0).tv_sec)
|
||||||
|
assert_equal(78796799, Time.utc(1972, 6, 30, 23, 59, 59).tv_sec)
|
||||||
|
|
||||||
|
# 1972-06-30T23:59:60Z is the first leap second.
|
||||||
|
if Time.utc(1972, 7, 1, 0, 0, 0) - Time.utc(1972, 6, 30, 23, 59, 59) == 1
|
||||||
|
# no leap second.
|
||||||
|
assert_equal(78796800, Time.utc(1972, 7, 1, 0, 0, 0).tv_sec)
|
||||||
|
assert_equal(78796801, Time.utc(1972, 7, 1, 0, 0, 1).tv_sec)
|
||||||
|
assert_equal(946684800, Time.utc(2000, 1, 1, 0, 0, 0).tv_sec)
|
||||||
|
assert_equal(0x7fffffff, Time.utc(2038, 1, 19, 3, 14, 7).tv_sec)
|
||||||
|
else
|
||||||
|
# leap seconds supported.
|
||||||
|
assert_equal(78796800, Time.utc(1972, 6, 30, 23, 59, 60).tv_sec)
|
||||||
|
assert_equal(78796801, Time.utc(1972, 7, 1, 0, 0, 0).tv_sec)
|
||||||
|
assert_equal(78796802, Time.utc(1972, 7, 1, 0, 0, 1).tv_sec)
|
||||||
|
assert_equal(946684822, Time.utc(2000, 1, 1, 0, 0, 0).tv_sec)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_huge_difference # [ruby-dev:22619]
|
||||||
|
if negative_time_t?
|
||||||
|
assert_equal(Time.at(-0x80000000), Time.at(0x7fffffff) - 0xffffffff)
|
||||||
|
assert_equal(Time.at(-0x80000000), Time.at(0x7fffffff) + (-0xffffffff))
|
||||||
|
assert_equal(Time.at(0x7fffffff), Time.at(-0x80000000) + 0xffffffff)
|
||||||
|
assert_equal(Time.at(0x7fffffff), Time.at(-0x80000000) - (-0xffffffff))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
9
win32/rm.bat
Executable file
9
win32/rm.bat
Executable file
|
@ -0,0 +1,9 @@
|
||||||
|
@echo off
|
||||||
|
::: $Id: rm.bat,v 1.1 2004/03/21 23:21:30 nobu Exp $
|
||||||
|
if "%1" == "-f" shift
|
||||||
|
:begin
|
||||||
|
if "%1" == "" goto :end
|
||||||
|
if exist "%1" del "%1"
|
||||||
|
shift
|
||||||
|
goto :begin
|
||||||
|
:end
|
Loading…
Add table
Add a link
Reference in a new issue