mirror of
https://github.com/zhigang1992/RubyMotion.git
synced 2026-04-01 09:31:20 +08:00
update TestUnit
This commit is contained in:
@@ -22,26 +22,26 @@ class TestDir < Test::Unit::TestCase
|
||||
|
||||
def teardown
|
||||
$VERBOSE = @verbose
|
||||
FileUtils.remove_entry_secure @root if File.directory?(@root)
|
||||
FileUtils.rm_rf @root
|
||||
end
|
||||
|
||||
# def test_seek
|
||||
# dir = Dir.open(@root)
|
||||
# begin
|
||||
# cache = []
|
||||
# loop do
|
||||
# pos = dir.tell
|
||||
# break unless name = dir.read
|
||||
# cache << [pos, name]
|
||||
# end
|
||||
# for x,y in cache.sort_by {|z| z[0] % 3 } # shuffle
|
||||
# dir.seek(x)
|
||||
# assert_equal(y, dir.read)
|
||||
# end
|
||||
# ensure
|
||||
# dir.close
|
||||
# end
|
||||
# end
|
||||
def test_seek
|
||||
dir = Dir.open(@root)
|
||||
begin
|
||||
cache = []
|
||||
loop do
|
||||
pos = dir.tell
|
||||
break unless name = dir.read
|
||||
cache << [pos, name]
|
||||
end
|
||||
for x,y in cache.sort_by {|z| z[0] % 3 } # shuffle
|
||||
dir.seek(x)
|
||||
assert_equal(y, dir.read)
|
||||
end
|
||||
ensure
|
||||
dir.close
|
||||
end
|
||||
end
|
||||
|
||||
# def test_JVN_13947696
|
||||
# skip("[BUG : #842] SecurityError Level 4")
|
||||
@@ -54,37 +54,37 @@ class TestDir < Test::Unit::TestCase
|
||||
# assert_raise(SecurityError) { b.call }
|
||||
# end
|
||||
|
||||
# def test_nodir
|
||||
# assert_raise(Errno::ENOENT) { Dir.open(@nodir) }
|
||||
# end
|
||||
def test_nodir
|
||||
assert_raise(Errno::ENOENT) { Dir.open(@nodir) }
|
||||
end
|
||||
|
||||
# def test_inspect
|
||||
# d = Dir.open(@root)
|
||||
# assert_match(/^#<Dir:#{ Regexp.quote(@root) }>$/, d.inspect)
|
||||
# assert_match(/^#<Dir:.*>$/, Dir.allocate.inspect)
|
||||
# ensure
|
||||
# d.close
|
||||
# end
|
||||
def test_inspect
|
||||
d = Dir.open(@root)
|
||||
# assert_match(/^#<Dir:#{ Regexp.quote(@root) }>$/, d.inspect)
|
||||
assert_match(/^#<Dir:.*>$/, Dir.allocate.inspect)
|
||||
ensure
|
||||
d.close
|
||||
end
|
||||
|
||||
# def test_path
|
||||
# d = Dir.open(@root)
|
||||
# assert_equal(@root, d.path)
|
||||
# assert_nil(Dir.allocate.path)
|
||||
# ensure
|
||||
# d.close
|
||||
# end
|
||||
def test_path
|
||||
d = Dir.open(@root)
|
||||
assert_equal(@root, d.path)
|
||||
assert_nil(Dir.allocate.path)
|
||||
ensure
|
||||
d.close
|
||||
end
|
||||
|
||||
# def test_set_pos
|
||||
# d = Dir.open(@root)
|
||||
# loop do
|
||||
# i = d.pos
|
||||
# break unless x = d.read
|
||||
# d.pos = i
|
||||
# assert_equal(x, d.read)
|
||||
# end
|
||||
# ensure
|
||||
# d.close
|
||||
# end
|
||||
def test_set_pos
|
||||
d = Dir.open(@root)
|
||||
loop do
|
||||
i = d.pos
|
||||
break unless x = d.read
|
||||
d.pos = i
|
||||
assert_equal(x, d.read)
|
||||
end
|
||||
ensure
|
||||
d.close
|
||||
end
|
||||
|
||||
# def test_rewind
|
||||
# d = Dir.open(@root)
|
||||
@@ -102,76 +102,76 @@ class TestDir < Test::Unit::TestCase
|
||||
# d.close
|
||||
# end
|
||||
|
||||
# def test_chdir
|
||||
# @pwd = Dir.pwd
|
||||
# @env_home = ENV["HOME"]
|
||||
# @env_logdir = ENV["LOGDIR"]
|
||||
# ENV.delete("HOME")
|
||||
# ENV.delete("LOGDIR")
|
||||
def test_chdir
|
||||
@pwd = Dir.pwd
|
||||
@env_home = ENV["HOME"]
|
||||
@env_logdir = ENV["LOGDIR"]
|
||||
ENV.delete("HOME")
|
||||
ENV.delete("LOGDIR")
|
||||
|
||||
# assert_raise(Errno::ENOENT) { Dir.chdir(@nodir) }
|
||||
# assert_raise(ArgumentError) { Dir.chdir }
|
||||
# ENV["HOME"] = @pwd
|
||||
# Dir.chdir do
|
||||
# assert_equal(@pwd, Dir.pwd)
|
||||
# Dir.chdir(@root)
|
||||
# assert_equal(@root, Dir.pwd)
|
||||
# end
|
||||
assert_raise(Errno::ENOENT) { Dir.chdir(@nodir) }
|
||||
assert_raise(ArgumentError) { Dir.chdir }
|
||||
ENV["HOME"] = @pwd
|
||||
Dir.chdir do
|
||||
assert_equal(@pwd, Dir.pwd)
|
||||
Dir.chdir(@root)
|
||||
assert_equal(@root, Dir.pwd)
|
||||
end
|
||||
|
||||
# ensure
|
||||
# begin
|
||||
# Dir.chdir(@pwd)
|
||||
# rescue
|
||||
# abort("cannot return the original directory: #{ @pwd }")
|
||||
# end
|
||||
# if @env_home
|
||||
# ENV["HOME"] = @env_home
|
||||
# else
|
||||
# ENV.delete("HOME")
|
||||
# end
|
||||
# if @env_logdir
|
||||
# ENV["LOGDIR"] = @env_logdir
|
||||
# else
|
||||
# ENV.delete("LOGDIR")
|
||||
# end
|
||||
# end
|
||||
ensure
|
||||
begin
|
||||
Dir.chdir(@pwd)
|
||||
rescue
|
||||
abort("cannot return the original directory: #{ @pwd }")
|
||||
end
|
||||
if @env_home
|
||||
ENV["HOME"] = @env_home
|
||||
else
|
||||
ENV.delete("HOME")
|
||||
end
|
||||
if @env_logdir
|
||||
ENV["LOGDIR"] = @env_logdir
|
||||
else
|
||||
ENV.delete("LOGDIR")
|
||||
end
|
||||
end
|
||||
|
||||
# def test_chroot_nodir
|
||||
# assert_raise(NotImplementedError, Errno::ENOENT, Errno::EPERM
|
||||
# ) { Dir.chroot(File.join(@nodir, "")) }
|
||||
# end
|
||||
def test_chroot_nodir
|
||||
assert_raise(NotImplementedError, Errno::ENOENT, Errno::EPERM
|
||||
) { Dir.chroot(File.join(@nodir, "")) }
|
||||
end
|
||||
|
||||
# def test_close
|
||||
# d = Dir.open(@root)
|
||||
# d.close
|
||||
# assert_raise(IOError) { d.read }
|
||||
# end
|
||||
def test_close
|
||||
d = Dir.open(@root)
|
||||
d.close
|
||||
assert_raise(IOError) { d.read }
|
||||
end
|
||||
|
||||
# def test_glob
|
||||
# assert_equal((%w(. ..) + (?a..?z).to_a).map{|f| File.join(@root, f) },
|
||||
# Dir.glob(File.join(@root, "*"), File::FNM_DOTMATCH).sort)
|
||||
# assert_equal([@root] + (?a..?z).map {|f| File.join(@root, f) }.sort,
|
||||
# Dir.glob([@root, File.join(@root, "*")]).sort)
|
||||
# assert_equal([@root] + (?a..?z).map {|f| File.join(@root, f) }.sort,
|
||||
# Dir.glob(@root + "\0\0\0" + File.join(@root, "*")).sort)
|
||||
def test_glob
|
||||
assert_equal((%w(. ..) + (?a..?z).to_a).map{|f| File.join(@root, f) },
|
||||
Dir.glob(File.join(@root, "*"), File::FNM_DOTMATCH).sort)
|
||||
assert_equal([@root] + (?a..?z).map {|f| File.join(@root, f) }.sort,
|
||||
Dir.glob([@root, File.join(@root, "*")]).sort)
|
||||
assert_equal([@root] + (?a..?z).map {|f| File.join(@root, f) }.sort,
|
||||
Dir.glob(@root + "\0\0\0" + File.join(@root, "*")).sort)
|
||||
|
||||
# assert_equal((?a..?z).step(2).map {|f| File.join(File.join(@root, f), "") }.sort,
|
||||
# Dir.glob(File.join(@root, "*/")).sort)
|
||||
assert_equal((?a..?z).step(2).map {|f| File.join(File.join(@root, f), "") }.sort,
|
||||
Dir.glob(File.join(@root, "*/")).sort)
|
||||
|
||||
# FileUtils.touch(File.join(@root, "{}"))
|
||||
# assert_equal(%w({} a).map{|f| File.join(@root, f) },
|
||||
# Dir.glob(File.join(@root, '{\{\},a}')))
|
||||
# assert_equal([], Dir.glob(File.join(@root, '[')))
|
||||
# assert_equal([], Dir.glob(File.join(@root, '[a-\\')))
|
||||
FileUtils.touch(File.join(@root, "{}"))
|
||||
assert_equal(%w({} a).map{|f| File.join(@root, f) },
|
||||
Dir.glob(File.join(@root, '{\{\},a}')))
|
||||
assert_equal([], Dir.glob(File.join(@root, '[')))
|
||||
assert_equal([], Dir.glob(File.join(@root, '[a-\\')))
|
||||
|
||||
# assert_equal([File.join(@root, "a")], Dir.glob(File.join(@root, 'a\\')))
|
||||
# assert_equal((?a..?f).map {|f| File.join(@root, f) }.sort, Dir.glob(File.join(@root, '[abc/def]')).sort)
|
||||
assert_equal([File.join(@root, "a")], Dir.glob(File.join(@root, 'a\\')))
|
||||
assert_equal((?a..?f).map {|f| File.join(@root, f) }.sort, Dir.glob(File.join(@root, '[abc/def]')).sort)
|
||||
|
||||
# d = "\u{3042}\u{3044}".encode("utf-16le")
|
||||
# assert_raise(Encoding::CompatibilityError) {Dir.glob(d)}
|
||||
# m = Class.new {define_method(:to_path) {d}}
|
||||
# assert_raise(Encoding::CompatibilityError) {Dir.glob(m.new)}
|
||||
# end
|
||||
# d = "\u{3042}\u{3044}".encode("utf-16le")
|
||||
# assert_raise(Encoding::CompatibilityError) {Dir.glob(d)}
|
||||
# m = Class.new {define_method(:to_path) {d}}
|
||||
# assert_raise(Encoding::CompatibilityError) {Dir.glob(m.new)}
|
||||
end
|
||||
|
||||
# def test_foreach
|
||||
# assert_equal(Dir.foreach(@root).to_a.sort, %w(. ..) + (?a..?z).to_a)
|
||||
|
||||
@@ -47,16 +47,16 @@ class TestFile < Test::Unit::TestCase
|
||||
f.close
|
||||
end
|
||||
|
||||
# def test_truncate_rbuf
|
||||
# f = Tempfile.new("test-truncate")
|
||||
# f.puts "abc"
|
||||
# f.puts "def"
|
||||
# f.close
|
||||
# f.open
|
||||
# assert_equal("abc\n", f.gets)
|
||||
# f.truncate(3)
|
||||
# assert_equal(nil, f.gets, "[ruby-dev:24197]")
|
||||
# end
|
||||
def test_truncate_rbuf
|
||||
f = Tempfile.new("test-truncate")
|
||||
f.puts "abc"
|
||||
f.puts "def"
|
||||
f.close
|
||||
f.open
|
||||
assert_equal("abc\n", f.gets)
|
||||
# f.truncate(3)
|
||||
# assert_equal(nil, f.gets, "[ruby-dev:24197]")
|
||||
end
|
||||
|
||||
def test_truncate_beyond_eof
|
||||
f = Tempfile.new("test-truncate")
|
||||
@@ -153,10 +153,10 @@ class TestFile < Test::Unit::TestCase
|
||||
}
|
||||
end
|
||||
|
||||
# def test_uninitialized
|
||||
# assert_raise(TypeError) { File::Stat.allocate.readable? }
|
||||
# assert_nothing_raised { File::Stat.allocate.inspect }
|
||||
# end
|
||||
def test_uninitialized
|
||||
assert_raise(TypeError) { File::Stat.allocate.readable? }
|
||||
# assert_nothing_raised { File::Stat.allocate.inspect }
|
||||
end
|
||||
|
||||
# def test_realpath
|
||||
# Dir.mktmpdir('rubytest-realpath') {|tmpdir|
|
||||
|
||||
@@ -566,24 +566,24 @@ class TestObject < Test::Unit::TestCase
|
||||
# end.call
|
||||
# end
|
||||
|
||||
# def test_singleton_class
|
||||
# x = Object.new
|
||||
# xs = class << x; self; end
|
||||
# assert_equal(xs, x.singleton_class)
|
||||
def test_singleton_class
|
||||
x = Object.new
|
||||
xs = class << x; self; end
|
||||
assert_equal(xs, x.singleton_class)
|
||||
|
||||
# y = Object.new
|
||||
# ys = y.singleton_class
|
||||
# assert_equal(class << y; self; end, ys)
|
||||
y = Object.new
|
||||
ys = y.singleton_class
|
||||
assert_equal(class << y; self; end, ys)
|
||||
|
||||
# assert_equal(NilClass, nil.singleton_class)
|
||||
# assert_equal(TrueClass, true.singleton_class)
|
||||
# assert_equal(FalseClass, false.singleton_class)
|
||||
assert_equal(NilClass, nil.singleton_class)
|
||||
assert_equal(TrueClass, true.singleton_class)
|
||||
assert_equal(FalseClass, false.singleton_class)
|
||||
|
||||
# assert_raise(TypeError) do
|
||||
# 123.singleton_class
|
||||
# end
|
||||
# assert_raise(TypeError) do
|
||||
# :foo.singleton_class
|
||||
# end
|
||||
# end
|
||||
assert_raise(TypeError) do
|
||||
123.singleton_class
|
||||
end
|
||||
assert_raise(TypeError) do
|
||||
:foo.singleton_class
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -14,7 +14,7 @@ class TestRange < Test::Unit::TestCase
|
||||
def test_range_numeric_string
|
||||
assert_equal(["6", "7", "8"], ("6".."8").to_a, "[ruby-talk:343187]")
|
||||
assert_equal(["6", "7"], ("6"..."8").to_a)
|
||||
# assert_equal(["9", "10"], ("9".."10").to_a)
|
||||
assert_equal(["9", "10"], ("9".."10").to_a)
|
||||
assert_equal(["09", "10"], ("09".."10").to_a, "[ruby-dev:39361]")
|
||||
# assert_equal(["9", "10"], (SimpleDelegator.new("9").."10").to_a)
|
||||
# assert_equal(["9", "10"], ("9"..SimpleDelegator.new("10")).to_a)
|
||||
@@ -307,11 +307,11 @@ class TestRange < Test::Unit::TestCase
|
||||
class CyclicRange < Range
|
||||
def <=>(other); true; end
|
||||
end
|
||||
# def test_cyclic_range_inspect
|
||||
# o = CyclicRange.allocate
|
||||
# o.instance_eval { initialize(o, 1) }
|
||||
# assert_equal("(... .. ...)..1", o.inspect)
|
||||
# end
|
||||
def test_cyclic_range_inspect
|
||||
o = CyclicRange.allocate
|
||||
o.instance_eval { initialize(o, 1) }
|
||||
assert_equal("(... .. ...)..1", o.inspect)
|
||||
end
|
||||
|
||||
# def test_comparison_when_recursive
|
||||
# x = CyclicRange.allocate; x.send(:initialize, x, 1)
|
||||
|
||||
@@ -190,11 +190,11 @@ class TestRegexp < Test::Unit::TestCase
|
||||
assert_equal(false, /(?i:a)/.casefold?)
|
||||
end
|
||||
|
||||
# def test_options
|
||||
# assert_equal(Regexp::IGNORECASE, /a/i.options)
|
||||
# assert_equal(Regexp::EXTENDED, /a/x.options)
|
||||
# assert_equal(Regexp::MULTILINE, /a/m.options)
|
||||
# end
|
||||
def test_options
|
||||
assert_equal(Regexp::IGNORECASE, /a/i.options)
|
||||
assert_equal(Regexp::EXTENDED, /a/x.options)
|
||||
assert_equal(Regexp::MULTILINE, /a/m.options)
|
||||
end
|
||||
|
||||
def test_match_init_copy
|
||||
m = /foo/.match("foo")
|
||||
|
||||
Reference in New Issue
Block a user