[前][次][番号順一覧][スレッド一覧]

ruby-changes:28827

From: knu <ko1@a...>
Date: Tue, 21 May 2013 21:41:45 +0900 (JST)
Subject: [ruby-changes:28827] knu:r40879 (trunk): * ext/digest/lib/digest.rb (Digest::Class.file): Take optional

knu	2013-05-21 21:41:34 +0900 (Tue, 21 May 2013)

  New Revision: 40879

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=40879

  Log:
    * ext/digest/lib/digest.rb (Digest::Class.file): Take optional
      arguments that are passed to the constructor of the digest
      class.

  Modified files:
    trunk/ChangeLog
    trunk/ext/digest/lib/digest.rb
    trunk/test/digest/test_digest.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 40878)
+++ ChangeLog	(revision 40879)
@@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Tue May 21 19:57:22 2013  Akinori MUSHA  <knu@i...>
+
+	* ext/digest/lib/digest.rb (Digest::Class.file): Take optional
+	  arguments that are passed to the constructor of the digest
+	  class.
+
 Tue May 21 17:21:12 2013  Koichi Sasada  <ko1@a...>
 
 	* gc.c: remove gc_profile_record::is_marked. always true.
Index: ext/digest/lib/digest.rb
===================================================================
--- ext/digest/lib/digest.rb	(revision 40878)
+++ ext/digest/lib/digest.rb	(revision 40879)
@@ -22,11 +22,13 @@ module Digest https://github.com/ruby/ruby/blob/trunk/ext/digest/lib/digest.rb#L22
 
   class ::Digest::Class
     # creates a digest object and reads a given file, _name_.
+    # Optional arguments are passed to the constructor of the digest
+    # class.
     #
     #   p Digest::SHA256.file("X11R6.8.2-src.tar.bz2").hexdigest
     #   # => "f02e3c85572dc9ad7cb77c2a638e3be24cc1b5bea9fdbb0b0299c9668475c534"
-    def self.file(name)
-      new.file(name)
+    def self.file(name, *args)
+      new(*args).file(name)
     end
 
     # Returns the base64 encoded hash value of a given _string_.  The
Index: test/digest/test_digest.rb
===================================================================
--- test/digest/test_digest.rb	(revision 40878)
+++ test/digest/test_digest.rb	(revision 40879)
@@ -4,6 +4,7 @@ https://github.com/ruby/ruby/blob/trunk/test/digest/test_digest.rb#L4
 # $Id$
 
 require 'test/unit'
+require 'tempfile'
 
 require 'digest'
 %w[digest/md5 digest/rmd160 digest/sha1 digest/sha2].each do |lib|
@@ -78,6 +79,16 @@ module TestDigest https://github.com/ruby/ruby/blob/trunk/test/digest/test_digest.rb#L79
     assert_equal(md1, md2, self.class::ALGO)
   end
 
+  def test_s_file
+    Tempfile.create("test_digest_file") { |tmpfile|
+      str = "hello, world.\r\n"
+      tmpfile.print str
+      tmpfile.close
+
+      assert_equal self.class::ALGO.new.update(str), self.class::ALGO.file(tmpfile.path)
+    }
+  end
+
   def test_instance_eval
     assert_nothing_raised {
       self.class::ALGO.new.instance_eval { update "a" }
@@ -138,6 +149,20 @@ module TestDigest https://github.com/ruby/ruby/blob/trunk/test/digest/test_digest.rb#L149
     }
   end if defined?(Digest::SHA512)
 
+  class TestSHA2 < Test::Unit::TestCase
+
+  def test_s_file
+    Tempfile.create("test_digest_file") { |tmpfile|
+      str = Data1
+      tmpfile.print str
+      tmpfile.close
+
+      assert_equal "cb00753f45a35e8bb5a03d699ac65007272c32ab0eded1631a8b605a43ff5bed8086072ba1e7cc2358baeca134c825a7", Digest::SHA2.file(tmpfile.path, 384).hexdigest
+    }
+  end
+
+  end if defined?(Digest::SHA2)
+
   class TestRMD160 < Test::Unit::TestCase
     include TestDigest
     ALGO = Digest::RMD160

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]