summaryrefslogtreecommitdiff
path: root/test/digest
diff options
context:
space:
mode:
authornahi <nahi@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-11-25 15:08:06 +0000
committernahi <nahi@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-11-25 15:08:06 +0000
commitc7b0dbd002b3f5fcf3f6a5cf45f4cc877830da15 (patch)
treeb5483712cbeb4309d6f6b994f8dc5d25807fee39 /test/digest
parentfe976467437ade210d7b405614f8b8ac37aa31d7 (diff)
* test/digest/test_digest_extend.rb: Added tests for current digest
framework. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@25925 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/digest')
-rw-r--r--test/digest/test_digest_extend.rb67
1 files changed, 67 insertions, 0 deletions
diff --git a/test/digest/test_digest_extend.rb b/test/digest/test_digest_extend.rb
new file mode 100644
index 0000000..9b2e59c
--- /dev/null
+++ b/test/digest/test_digest_extend.rb
@@ -0,0 +1,67 @@
+require 'test/unit'
+require 'digest'
+
+class TestDigestExtend < Test::Unit::TestCase
+ class MyDigest < Digest::Class
+ def initialize(*arg)
+ super
+ @buf = []
+ end
+
+ def update(arg)
+ @buf << arg
+ self
+ end
+
+ alias << update
+
+ def finish
+ (@buf.join.length % 256).chr
+ end
+
+ def reset
+ @buf.clear
+ self
+ end
+ end
+
+ def test_digest
+ assert_equal("\3", MyDigest.digest("foo"))
+ end
+
+ def test_hexdigest
+ assert_equal("03", MyDigest.hexdigest("foo"))
+ end
+
+ def test_context
+ digester = MyDigest.new
+ digester.update("foo")
+ assert_equal("\3", digester.digest)
+ digester.update("foobar")
+ assert_equal("\6", digester.digest)
+ digester.update("foo")
+ assert_equal("\3", digester.digest)
+ end
+
+ def test_to_s
+ digester = MyDigest.new
+ digester.update("foo")
+ assert_equal("03", digester.to_s)
+ 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
+ end
+ end
+end