mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
add test for [ruby-dev:24060], [ruby-dev:24065], [ruby-dev:24103],
[ruby-dev:24190], [ruby-dev:24191], [ruby-dev:24194], [ruby-dev:24197], [ruby-dev:24202], [ruby-dev:24213], [ruby-dev:24223] and [ruby-dev:24228]. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6865 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
eb136f8643
commit
08907d87e0
5 changed files with 110 additions and 4 deletions
|
@ -88,4 +88,10 @@ class TestDigest < Test::Unit::TestCase
|
|||
assert_equal(md1, md2, algo)
|
||||
end
|
||||
end
|
||||
|
||||
def test_instance_eval # [ruby-dev:24202]
|
||||
assert_nothing_raised {
|
||||
Digest::SHA1.new.instance_eval { update "a" }
|
||||
}
|
||||
end
|
||||
end
|
||||
|
|
|
@ -119,4 +119,39 @@ class TestEval < Test::Unit::TestCase
|
|||
assert_equal(5, p1.call)
|
||||
assert_nil(i7)
|
||||
end
|
||||
|
||||
def test_nil_instance_eval_cvar # [ruby-dev:24103]
|
||||
def nil.test_binding
|
||||
binding
|
||||
end
|
||||
bb = eval("nil.instance_eval \"binding\"", nil.test_binding)
|
||||
assert_raise(NameError) { eval("@@a", bb) }
|
||||
class << nil
|
||||
remove_method :test_binding
|
||||
end
|
||||
end
|
||||
|
||||
def test_fixnum_instance_eval_cvar # [ruby-dev:24213]
|
||||
assert_raise(NameError) { 1.instance_eval "@@a" }
|
||||
end
|
||||
|
||||
def test_cvar_scope_with_instance_eval # [ruby-dev:24223]
|
||||
Fixnum.class_eval "@@test_cvar_scope_with_instance_eval = 1" # depends on [ruby-dev:24229]
|
||||
@@test_cvar_scope_with_instance_eval = 4
|
||||
assert_equal(4, 1.instance_eval("@@test_cvar_scope_with_instance_eval"))
|
||||
Fixnum.__send__(:remove_class_variable, :@@test_cvar_scope_with_instance_eval)
|
||||
end
|
||||
|
||||
def test_eval_and_define_method # [ruby-dev:24228]
|
||||
assert_nothing_raised {
|
||||
def temporally_method_for_test_eval_and_define_method(&block)
|
||||
lambda {
|
||||
class << Object.new; self end.__send__(:define_method, :zzz, &block)
|
||||
}
|
||||
end
|
||||
v = eval("temporally_method_for_test_eval_and_define_method {}")
|
||||
{}[0] = {}
|
||||
v.call
|
||||
}
|
||||
end
|
||||
end
|
||||
|
|
|
@ -226,4 +226,23 @@ class TestFile < Test::Unit::TestCase
|
|||
assert(File.fnmatch('**/foo', 'c:/root/foo', File::FNM_PATHNAME))
|
||||
end
|
||||
|
||||
def test_truncate_wbuf # [ruby-dev:24191]
|
||||
f = Tempfile.new("test-truncate")
|
||||
f.puts "abc"
|
||||
f.truncate(0)
|
||||
f.puts "def"
|
||||
f.close
|
||||
assert_equal("\0\0\0\0def\n", File.read(f.path))
|
||||
end
|
||||
|
||||
def test_truncate_rbuf # [ruby-dev:24197]
|
||||
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)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -14,4 +14,20 @@ class TestStringIO < Test::Unit::TestCase
|
|||
alias open_file_rw open_file
|
||||
|
||||
include TestEOF::Seek
|
||||
|
||||
def test_truncate # [ruby-dev:24190]
|
||||
io = StringIO.new("")
|
||||
io.puts "abc"
|
||||
io.truncate(0)
|
||||
io.puts "def"
|
||||
assert_equal("\0\0\0def\n", io.string)
|
||||
end
|
||||
|
||||
def test_seek_beyond_eof # [ruby-dev:24194]
|
||||
io = StringIO.new
|
||||
n = 100
|
||||
io.seek(n)
|
||||
io.print "last"
|
||||
assert_equal("\0" * n + "last", io.string)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -13,16 +13,46 @@ if defined? Zlib
|
|||
def test_read0
|
||||
assert_equal("", Zlib::GzipReader.new(StringIO.new(D0)).read(0))
|
||||
end
|
||||
|
||||
def test_ungetc # [ruby-dev:24060]
|
||||
s = ""
|
||||
w = Zlib::GzipWriter.new(StringIO.new(s))
|
||||
w << (1...1000).to_a.inspect
|
||||
w.close
|
||||
r = Zlib::GzipReader.new(StringIO.new(s))
|
||||
r.read(100)
|
||||
r.ungetc ?a
|
||||
assert_nothing_raised {
|
||||
r.read(100)
|
||||
r.read
|
||||
r.close
|
||||
}
|
||||
end
|
||||
|
||||
def test_ungetc_paragraph # [ruby-dev:24065]
|
||||
s = ""
|
||||
w = Zlib::GzipWriter.new(StringIO.new(s))
|
||||
w << "abc"
|
||||
w.close
|
||||
r = Zlib::GzipReader.new(StringIO.new(s))
|
||||
$/ = ""
|
||||
r.ungetc ?\n
|
||||
assert_equal("abc", r.gets)
|
||||
assert_nothing_raised {
|
||||
r.read
|
||||
r.close
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
class TestZlibGzipWriter < Test::Unit::TestCase
|
||||
def test_invalid_new
|
||||
# [ruby-dev:23228]
|
||||
assert_raises(NoMethodError) { Zlib::GzipWriter.new(nil).close }
|
||||
assert_raise(NoMethodError) { Zlib::GzipWriter.new(nil).close }
|
||||
# [ruby-dev:23344]
|
||||
assert_raises(NoMethodError) { Zlib::GzipWriter.new(true).close }
|
||||
assert_raises(NoMethodError) { Zlib::GzipWriter.new(0).close }
|
||||
assert_raises(NoMethodError) { Zlib::GzipWriter.new(:hoge).close }
|
||||
assert_raise(NoMethodError) { Zlib::GzipWriter.new(true).close }
|
||||
assert_raise(NoMethodError) { Zlib::GzipWriter.new(0).close }
|
||||
assert_raise(NoMethodError) { Zlib::GzipWriter.new(:hoge).close }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue