1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* test/ruby/test_array.rb: add a test for Array#rotate, rotate!.

* test/ruby/test_dir.rb, test/ruby/test_fnmatch.rb: add some tests
  (for coverage of dir.c).

* test/ruby/test_enum.rb: add a test for Enumerable#minmax.

* test/ruby/test_enumerator.rb: add some tests for Enumerator#inspect,
  Enumerator::Generator and Yielder.

* test/ruby/test_env.rb: add a test for ENV#index.

* test/ruby/test_exception.rb: add some tests (for coverage of
  error.c).

* test/ruby/test_hash.rb: add a test for recursive check.

* test/ruby/test_integer.rb: add a test for number of argument of
  Integer.

* test/ruby/test_method.rb: add a test for define_method.

* test/ruby/test_module.rb: add a test for constant of included
  module.

* test/ruby/test_proc.rb: add a test for parameters with cfunc.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@26379 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
mame 2010-01-22 15:03:32 +00:00
parent d8d5e67184
commit bebd7e4511
13 changed files with 205 additions and 5 deletions

View file

@ -1,3 +1,32 @@
Fri Jan 22 23:54:04 2010 Yusuke Endoh <mame@tsg.ne.jp>
* test/ruby/test_array.rb: add a test for Array#rotate, rotate!.
* test/ruby/test_dir.rb, test/ruby/test_fnmatch.rb: add some tests
(for coverage of dir.c).
* test/ruby/test_enum.rb: add a test for Enumerable#minmax.
* test/ruby/test_enumerator.rb: add some tests for Enumerator#inspect,
Enumerator::Generator and Yielder.
* test/ruby/test_env.rb: add a test for ENV#index.
* test/ruby/test_exception.rb: add some tests (for coverage of
error.c).
* test/ruby/test_hash.rb: add a test for recursive check.
* test/ruby/test_integer.rb: add a test for number of argument of
Integer.
* test/ruby/test_method.rb: add a test for define_method.
* test/ruby/test_module.rb: add a test for constant of included
module.
* test/ruby/test_proc.rb: add a test for parameters with cfunc.
Fri Jan 22 23:50:03 2010 Yusuke Endoh <mame@tsg.ne.jp>
* test/ruby/test_regexp.rb, test/ruby/test_symbol.rb,

View file

@ -1788,6 +1788,8 @@ class TestArray < Test::Unit::TestCase
assert_equal([], a.rotate(-4))
assert_equal([], a.rotate(13))
assert_equal([], a.rotate(-13))
a = [1,2,3]
assert_raise(ArgumentError) { a.rotate(1, 1) }
end
def test_rotate!
@ -1813,5 +1815,7 @@ class TestArray < Test::Unit::TestCase
a = [].freeze
e = assert_raise(RuntimeError) {a.rotate!}
assert_match(/can't modify frozen array/, e.message)
a = [1,2,3]
assert_raise(ArgumentError) { a.rotate!(1, 1) }
end
end

View file

@ -162,6 +162,9 @@ class TestDir < Test::Unit::TestCase
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)
d = "\u{3042}\u{3044}".encode("utf-16le")
assert_raise(Encoding::CompatibilityError) {Dir.glob(d)}
m = Class.new {define_method(:to_path) {d}}
@ -172,4 +175,42 @@ class TestDir < Test::Unit::TestCase
assert_equal(Dir.foreach(@root).to_a.sort, %w(. ..) + (?a..?z).to_a)
end
def test_dir_enc
dir = Dir.open(@root, encoding: "UTF-8")
begin
while name = dir.read
assert_equal(Encoding.find("UTF-8"), name.encoding)
end
ensure
dir.close
end
dir = Dir.open(@root, encoding: "ASCII-8BIT")
begin
while name = dir.read
assert_equal(Encoding.find("ASCII-8BIT"), name.encoding)
end
ensure
dir.close
end
end
def test_symlink
begin
[:dummy, *?a..?z].each do |f|
File.symlink(File.join(@root, f),
File.join(@root, "symlink-#{ f }"))
end
rescue NotImplementedError
return
end
assert_equal([*?a..?z, *"symlink-a".."symlink-z"].each_slice(2).map {|f, _| File.join(@root, f + "/") }.sort,
Dir.glob(File.join(@root, "*/")).sort)
puts("1");
Dir.glob(File.join(@root, "**/"))
puts("2");
end
end

View file

@ -166,6 +166,7 @@ class TestEnumerable < Test::Unit::TestCase
assert_equal(["dog", "albatross"], a.minmax {|a,b| a.length <=> b.length })
assert_equal([1, 3], [2,3,1].minmax)
assert_equal([3, 1], [2,3,1].minmax {|a,b| b <=> a })
assert_equal([1, 3], [2,2,3,3,1,1].minmax)
end
def test_min_by

View file

@ -332,6 +332,46 @@ class TestEnumerator < Test::Unit::TestCase
assert_equal(10, exc.result)
end
def test_inspect
e = (0..10).each_cons(2)
assert_equal("#<Enumerator: 0..10:each_cons(2)>", e.inspect)
e = Enumerator.new {|y| x = y.yield; 10 }
assert_match(/\A#<Enumerator: .*:each>/, e.inspect)
a = []
e = a.each_with_object(a)
a << e
assert_equal("#<Enumerator: [#<Enumerator: ...>]:each_with_object([#<Enumerator: ...>])>",
e.inspect)
end
def test_generator
# note: Enumerator::Generator is a class just for internal
g = Enumerator::Generator.new {|y| y << 1 << 2 << 3; :foo }
g2 = g.dup
a = []
assert_equal(:foo, g.each {|x| a << x })
assert_equal([1, 2, 3], a)
a = []
assert_equal(:foo, g2.each {|x| a << x })
assert_equal([1, 2, 3], a)
end
def test_yielder
# note: Enumerator::Yielder is a class just for internal
a = []
y = Enumerator::Yielder.new {|x| a << x }
assert_equal(y, y << 1 << 2 << 3)
assert_equal([1, 2, 3], a)
a = []
y = Enumerator::Yielder.new {|x| a << x }
assert_equal([1], y.yield(1))
assert_equal([1, 2], y.yield(2))
assert_equal([1, 2, 3], y.yield(3))
assert_raise(LocalJumpError) { Enumerator::Yielder.new }
end
end

View file

@ -68,6 +68,7 @@ class TestEnv < Test::Unit::TestCase
ENV['test'] = val[0...-1]
assert_nil(ENV.key(val))
assert_nil(ENV.index(val))
assert_nil(ENV.key(val.upcase))
ENV['test'] = val
if IGNORE_CASE

View file

@ -255,4 +255,53 @@ end.join
RUBY
assert_not_match(/:0/, stderr, "[ruby-dev:39116]")
end
def test_errinfo
begin
raise "foo"
assert(false)
rescue => e
assert_equal(e, $!)
1.times { assert_equal(e, $!) }
end
assert_equal(nil, $!)
end
def test_inspect
assert_equal("#<Exception: Exception>", Exception.new.inspect)
e = Class.new(Exception)
e.class_eval do
def to_s; ""; end
end
assert_equal(e.inspect, e.new.inspect)
end
def test_set_backtrace
e = Exception.new
e.set_backtrace("foo")
assert_equal(["foo"], e.backtrace)
e.set_backtrace(%w(foo bar baz))
assert_equal(%w(foo bar baz), e.backtrace)
assert_raise(TypeError) { e.set_backtrace(1) }
assert_raise(TypeError) { e.set_backtrace([1]) }
end
def test_exit_success_p
begin
exit
rescue SystemExit => e
end
assert(e.success?)
begin
abort
rescue SystemExit => e
end
assert(!e.success?)
end
end

View file

@ -79,6 +79,8 @@ class TestFnmatch < Test::Unit::TestCase
assert(File.fnmatch('cat', 'CAT', File::FNM_CASEFOLD))
assert(!File.fnmatch('[a-z]', 'D'))
assert(File.fnmatch('[a-z]', 'D', File::FNM_CASEFOLD))
assert(!File.fnmatch('[abc]', 'B'))
assert(File.fnmatch('[abc]', 'B', File::FNM_CASEFOLD))
# wildcard doesn't match '/' if FNM_PATHNAME is set
assert(File.fnmatch('foo?boo', 'foo/boo'))
assert(File.fnmatch('foo*', 'foo/boo'))

View file

@ -875,4 +875,9 @@ class TestHash < Test::Unit::TestCase
def test_hash_poped
assert_nothing_raised { eval("a = 1; {a => a}; a") }
end
def test_recursive_check
h = {}
assert_raise(ArgumentError) { h[h] = :foo }
end
end

View file

@ -84,6 +84,12 @@ class TestInteger < Test::Unit::TestCase
assert_raise(ArgumentError) { Integer("0x123", 10) }
assert_raise(ArgumentError) { Integer(1234, 10) }
assert_raise(ArgumentError) { Integer(12.34, 10) }
assert_raise(ArgumentError) { Integer(Object.new, 1) }
assert_raise(ArgumentError) { Integer(1, 1, 1) }
assert_equal(2 ** 50, Integer(2.0 ** 50))
assert_raise(TypeError) { Integer(nil) }
end
def test_int_p
@ -192,9 +198,4 @@ class TestInteger < Test::Unit::TestCase
assert_equal(-1111_1111_1111_1111_1111_1111_1111_1110, (-1111_1111_1111_1111_1111_1111_1111_1111).round(-1))
assert_equal(Bignum, (-1111_1111_1111_1111_1111_1111_1111_1111).round(-1).class)
end
def test_Integer2
assert_equal(2 ** 50, Integer(2.0 ** 50))
assert_raise(TypeError) { Integer(nil) }
end
end

View file

@ -179,6 +179,10 @@ class TestMethod < Test::Unit::TestCase
o = Object.new
o.instance_eval { define_singleton_method(:foo) { :foo } }
assert_equal(:foo, o.foo)
assert_raise(TypeError) do
Class.new.class_eval { define_method(:foo, Object.new) }
end
end
def test_clone

View file

@ -380,6 +380,25 @@ class TestModule < Test::Unit::TestCase
Object.module_eval "WALTER = 99"
c2 = Module.constants
assert_equal([:WALTER], c2 - c1)
assert_equal([], Module.constants(true))
assert_equal([], Module.constants(false))
src = <<-INPUT
module M
WALTER = 99
end
class Module
include M
end
p Module.constants, Module.constants(true), Module.constants(false)
INPUT
assert_in_out_err([], src) do |out, err|
assert_equal([:BasicObject, :M], eval(out[0]).sort - Module.constants)
assert_equal("[:WALTER]", out[1])
assert_equal("[]", out[2])
assert_equal([], err)
end
end
module M1

View file

@ -735,6 +735,10 @@ class TestProc < Test::Unit::TestCase
assert_equal([[:req, :a], [:rest, :b], [:req, :c], [:block, :d]], method(:pmo6).to_proc.parameters)
assert_equal([[:req, :a], [:opt, :b], [:rest, :c], [:req, :d], [:block, :e]], method(:pmo7).to_proc.parameters)
assert_equal([[:req], [:block, :b]], method(:pma1).to_proc.parameters)
assert_equal([], "".method(:upcase).to_proc.parameters)
assert_equal([[:rest]], "".method(:gsub).to_proc.parameters)
assert_equal([[:rest]], proc {}.curry.parameters)
end
def test_to_s