1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
|
# Copyright (C) 2004-2024 Kouhei Sutou <kou@cozmixng.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
require "rabbit/source"
require "rabbit/logger"
class RabbitSourceTest < Test::Unit::TestCase
class BaseTest < self
class EncodingDetectionTest < self
def test_euc_jp_like_utf8
assert_equal(Encoding::UTF_8, guess_encoding("résumé"))
end
private
def guess_encoding(string)
logger = Rabbit::Logger::STDERR.new
source = Rabbit::Source::Memory.new(nil, logger)
source.source = string
source.__send__(:guess_encoding, string)
end
end
class ReadTest < self
def test_binary
pdf_header = +"%PDF-1.5\n%\xb5\xed\xae\xfb\n"
pdf_header.force_encoding("ASCII-8BIT")
assert_equal(pdf_header, read(pdf_header))
end
private
def read(string)
logger = Rabbit::Logger::STDERR.new
source = Rabbit::Source::Memory.new(string.encoding, logger)
source.source = string
source.read
end
end
end
class ARGFTest < self
def setup
logger = Rabbit::Logger::STDERR.new
@input, @output = IO.pipe
@source = Rabbit::Source::ARGF.new("UTF-8", logger, @input)
end
def teardown
@input.close
@output.close
end
def test_base
assert_equal(".", @source.base)
end
def test_full_path
image = "sample.png"
assert_equal(File.join(".", image), @source.full_path(image))
end
end
class FileTest < self
def setup
logger = Rabbit::Logger::STDERR.new
@dir = File.dirname(__FILE__)
@file = File.join(@dir, "sample.rd")
FileUtils.touch(@file)
@source = Rabbit::Source::File.new("UTF-8", logger, @file)
end
def teardown
FileUtils.rm_f(@file)
end
def test_base
assert_equal(@dir, @source.base)
end
def test_full_path
image = "sample.png"
assert_equal(File.join(@dir, image), @source.full_path(image))
end
end
class URITest < self
def setup
logger = Rabbit::Logger::STDERR.new
@base = "http://example.com/sample"
@uri = "#{@base}/rabbit.rd"
@source = Rabbit::Source::URI.new("UTF-8", logger, @uri)
end
def test_base
assert_equal(@base, @source.base)
end
def test_full_path
image = "sample.png"
assert_equal("#{@base}/#{image}", @source.full_path(image))
end
end
end
|