summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornahi <nahi@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-12-01 09:03:29 +0000
committernahi <nahi@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-12-01 09:03:29 +0000
commit7d299148ade142edde6dbef672b37071c882e3a2 (patch)
tree1aa90acb0c2251dac89ea0c078f8f94f1fe9d59f
parent4148f1c51a70d0e7838a748980d96c6bc17a0ae0 (diff)
downloadruby-7d299148ade142edde6dbef672b37071c882e3a2.tar.gz
ruby-7d299148ade142edde6dbef672b37071c882e3a2.tar.xz
ruby-7d299148ade142edde6dbef672b37071c882e3a2.zip
* test/digest/test_digest_extend.rb: added tests for digest framework.
git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@25970 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog4
-rw-r--r--test/digest/test_digest_extend.rb82
2 files changed, 84 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index 7643c58f6..8677453b5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+Tue Dec 1 18:01:43 2009 NAKAMURA, Hiroshi <nahi@ruby-lang.org>
+
+ * test/digest/test_digest_extend.rb: added tests for digest framework.
+
Tue Dec 1 12:01:13 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
* parse.y (dyna_push_gen, dyna_pop_gen): no needs to save both of
diff --git a/test/digest/test_digest_extend.rb b/test/digest/test_digest_extend.rb
index 9b2e59cdf..9b8eda03f 100644
--- a/test/digest/test_digest_extend.rb
+++ b/test/digest/test_digest_extend.rb
@@ -8,6 +8,10 @@ class TestDigestExtend < Test::Unit::TestCase
@buf = []
end
+ def initialize_copy(org)
+ @buf = org.buf.dup
+ end
+
def update(arg)
@buf << arg
self
@@ -23,6 +27,32 @@ class TestDigestExtend < Test::Unit::TestCase
@buf.clear
self
end
+
+ protected
+
+ def buf
+ @buf
+ end
+ end
+
+ def test_digest_s_hexencode
+ assert_equal('', Digest.hexencode(''))
+ assert_equal('0102', Digest.hexencode("\1\2"))
+ assert_equal(
+ (0..0xff).to_a.map { |c| sprintf("%02x", c ) }.join,
+ Digest.hexencode((0..0xff).to_a.map { |c| c.chr }.join)
+ )
+ end
+
+ def test_class_reset
+ a = Digest::SHA1.new
+ base = a.to_s
+ assert_equal(base, a.reset.to_s)
+ b = a.new
+ assert_equal(base, b.to_s)
+ b.update('1')
+ assert_not_equal(base, b.to_s)
+ assert_equal(base, b.reset.to_s)
end
def test_digest
@@ -38,9 +68,51 @@ class TestDigestExtend < Test::Unit::TestCase
digester.update("foo")
assert_equal("\3", digester.digest)
digester.update("foobar")
- assert_equal("\6", digester.digest)
+ assert_equal("\t", digester.digest)
digester.update("foo")
- assert_equal("\3", digester.digest)
+ assert_equal("\f", digester.digest)
+ end
+
+ def test_new
+ a = Digest::SHA1.new
+ b = a.new
+ obj = a.to_s
+ assert_equal(obj, a.to_s)
+ assert_equal(obj, b.to_s)
+ a.update('1')
+ assert_not_equal(obj, a.to_s)
+ assert_equal(obj, b.to_s)
+ end
+
+ def test_digest_hexdigest
+ [: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.update("foo")
+ obj = digester.send(m)
+ # digest w/o param does not reset the org digester.
+ assert_equal(exp_1st, obj)
+ digester.update("bar")
+ obj = digester.send(m)
+ assert_equal(exp_2nd, obj)
+ obj = digester.send(m, "baz")
+ # digest with param resets the org digester.
+ assert_equal(exp_1st, obj)
+ end
+ end
+
+ 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.update("foo")
+ obj = digester.send(m) # digest! always resets the org digester.
+ assert_equal(exp_1st, obj)
+ digester.update("bar")
+ obj = digester.send(m)
+ assert_equal(exp_1st, obj)
+ end
end
def test_to_s
@@ -49,6 +121,12 @@ class TestDigestExtend < Test::Unit::TestCase
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