mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* test/digest/test_digest_extend.rb (TestDigestExtend#setup):
should not depend on the result of previous tests * test/with_diffent_ofs.rb (DifferentOFS::WithDifferentOFS): give name. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@30368 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
7df8b94926
commit
3e7c68119c
3 changed files with 36 additions and 24 deletions
10
ChangeLog
10
ChangeLog
|
@ -1,4 +1,10 @@
|
|||
Sat Dec 25 22:08:04 2010 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
Sat Dec 25 22:32:45 2010 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* test/digest/test_digest_extend.rb (TestDigestExtend#setup):
|
||||
should not depend on the result of previous tests
|
||||
|
||||
* test/with_diffent_ofs.rb (DifferentOFS::WithDifferentOFS): give
|
||||
name.
|
||||
|
||||
* test/with_diffent_ofs.rb (DifferentOFS): test suite for test
|
||||
suites affected by $,.
|
||||
|
@ -7,7 +13,7 @@ Sat Dec 25 22:08:04 2010 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
|||
assume $, invariant.
|
||||
|
||||
* test/csv/test_data_converters.rb, test/csv/test_table.rb: don't
|
||||
not call setup within tests.
|
||||
call setup within tests.
|
||||
|
||||
Sat Dec 25 20:01:40 2010 KOSAKI Motohiro <kosaki.motohiro@gmail.com>
|
||||
|
||||
|
|
|
@ -38,6 +38,10 @@ class TestDigestExtend < Test::Unit::TestCase
|
|||
end
|
||||
end
|
||||
|
||||
def setup
|
||||
@MyDigest = Class.new(MyDigest)
|
||||
end
|
||||
|
||||
def test_digest_s_hexencode
|
||||
assert_equal('', Digest.hexencode(''))
|
||||
assert_equal('0102', Digest.hexencode("\1\2"))
|
||||
|
@ -63,11 +67,11 @@ class TestDigestExtend < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
def test_hexdigest
|
||||
assert_equal("03", MyDigest.hexdigest("foo"))
|
||||
assert_equal("03", @MyDigest.hexdigest("foo"))
|
||||
end
|
||||
|
||||
def test_context
|
||||
digester = MyDigest.new
|
||||
digester = @MyDigest.new
|
||||
digester.update("foo")
|
||||
assert_equal("\3", digester.digest)
|
||||
digester.update("foobar")
|
||||
|
@ -91,7 +95,7 @@ class TestDigestExtend < Test::Unit::TestCase
|
|||
[:digest, :hexdigest].each do |m|
|
||||
exp_1st = "\3"; exp_1st = Digest.hexencode(exp_1st) if m == :hexdigest
|
||||
exp_2nd = "\6"; exp_2nd = Digest.hexencode(exp_2nd) if m == :hexdigest
|
||||
digester = MyDigest.new
|
||||
digester = @MyDigest.new
|
||||
digester.update("foo")
|
||||
obj = digester.send(m)
|
||||
# digest w/o param does not reset the org digester.
|
||||
|
@ -108,7 +112,7 @@ class TestDigestExtend < Test::Unit::TestCase
|
|||
def test_digest_hexdigest_bang
|
||||
[:digest!, :hexdigest!].each do |m|
|
||||
exp_1st = "\3"; exp_1st = Digest.hexencode(exp_1st) if m == :hexdigest!
|
||||
digester = MyDigest.new
|
||||
digester = @MyDigest.new
|
||||
digester.update("foo")
|
||||
obj = digester.send(m) # digest! always resets the org digester.
|
||||
assert_equal(exp_1st, obj)
|
||||
|
@ -119,30 +123,35 @@ class TestDigestExtend < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
def test_to_s
|
||||
digester = MyDigest.new
|
||||
digester = @MyDigest.new
|
||||
digester.update("foo")
|
||||
assert_equal("03", digester.to_s)
|
||||
end
|
||||
|
||||
def test_length
|
||||
digester = MyDigest.new
|
||||
assert_equal(2, digester.length)
|
||||
assert_equal(2, digester.size)
|
||||
end
|
||||
|
||||
def test_digest_length # breaks MyDigest#digest_length
|
||||
assert_equal(1, MyDigest.new.digest_length)
|
||||
MyDigest.class_eval do
|
||||
@MyDigest.class_eval do
|
||||
def digest_length
|
||||
2
|
||||
end
|
||||
end
|
||||
assert_equal(2, MyDigest.new.digest_length)
|
||||
digester = @MyDigest.new
|
||||
assert_equal(2, digester.length)
|
||||
assert_equal(2, digester.size)
|
||||
end
|
||||
|
||||
def test_digest_length # breaks @MyDigest#digest_length
|
||||
assert_equal(1, @MyDigest.new.digest_length)
|
||||
@MyDigest.class_eval do
|
||||
def digest_length
|
||||
2
|
||||
end
|
||||
end
|
||||
assert_equal(2, @MyDigest.new.digest_length)
|
||||
end
|
||||
|
||||
def test_block_length
|
||||
assert_raises(RuntimeError) do
|
||||
MyDigest.new.block_length
|
||||
@MyDigest.new.block_length
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -8,15 +8,12 @@ module DifferentOFS
|
|||
super
|
||||
end
|
||||
|
||||
mod = Module.new do
|
||||
module WithDifferentOFS
|
||||
def with_diffrent_ofs
|
||||
const_set(:DifferentOFS, Class.new(self).class_eval {include DifferentOFS}).name
|
||||
end
|
||||
end
|
||||
class << self; self; end.class_eval do
|
||||
define_method(:included) do |klass|
|
||||
super(klass)
|
||||
klass.extend(mod)
|
||||
end
|
||||
def self.included(klass)
|
||||
super(klass)
|
||||
klass.const_set(:DifferentOFS, Class.new(klass).class_eval {include WithDifferentOFS}).name
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue