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

ruby-changes:19965

From: nahi <ko1@a...>
Date: Sat, 11 Jun 2011 23:07:53 +0900 (JST)
Subject: [ruby-changes:19965] nahi:r32012 (trunk): * ext/openssl/lib/openssl/buffering.rb (module OpenSSL):

nahi	2011-06-11 23:07:42 +0900 (Sat, 11 Jun 2011)

  New Revision: 32012

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

  Log:
    * ext/openssl/lib/openssl/buffering.rb (module OpenSSL):
      Buffering#each_byte should return String in accordance with IO in
      1.9. 
    
    * test/openssl/test_buffering.rb (class OpenSSL): add tests for getc
      and each_byte.

  Modified files:
    trunk/ChangeLog
    trunk/ext/openssl/lib/openssl/buffering.rb
    trunk/test/openssl/test_buffering.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 32011)
+++ ChangeLog	(revision 32012)
@@ -1,3 +1,12 @@
+Sat Jun 11 23:02:36 2011  Hiroshi Nakamura  <nahi@r...>
+
+	* ext/openssl/lib/openssl/buffering.rb (module OpenSSL):
+	  Buffering#each_byte should return String in accordance with IO in
+	  1.9.
+
+	* test/openssl/test_buffering.rb (class OpenSSL): add tests for getc
+	  and each_byte.
+
 Sat Jun 11 22:41:37 2011  Tadayoshi Funaba  <tadf@d...>
 
 	* time.c: a correction of doc for strftime (%v).
Index: ext/openssl/lib/openssl/buffering.rb
===================================================================
--- ext/openssl/lib/openssl/buffering.rb	(revision 32011)
+++ ext/openssl/lib/openssl/buffering.rb	(revision 32012)
@@ -252,8 +252,7 @@
   # file.
 
   def getc
-    c = read(1)
-    c ? c[0] : nil
+    read(1)
   end
 
   ##
@@ -261,7 +260,7 @@
 
   def each_byte # :yields: byte
     while c = getc
-      yield(c)
+      yield(c.ord)
     end
   end
 
Index: test/openssl/test_buffering.rb
===================================================================
--- test/openssl/test_buffering.rb	(revision 32011)
+++ test/openssl/test_buffering.rb	(revision 32012)
@@ -10,7 +10,10 @@
     attr_accessor :sync
 
     def initialize
-      @io = StringIO.new
+      @io = ""
+      def @io.sync
+        true
+      end
 
       super
 
@@ -18,15 +21,18 @@
     end
 
     def string
-      @io.string
+      @io
     end
 
-    def sysread *a
-      @io.sysread *a
+    def sysread(size)
+      str = @io.slice!(0, size)
+      raise EOFError if str.empty?
+      str
     end
 
-    def syswrite *a
-      @io.syswrite *a
+    def syswrite(str)
+      @io << str
+      str.size
     end
   end
 
@@ -63,4 +69,21 @@
     refute @io.sync, 'sync must not change'
   end
 
+  def test_getc
+    @io.syswrite('abc')
+    res = []
+    assert_equal(?a, @io.getc)
+    assert_equal(?b, @io.getc)
+    assert_equal(?c, @io.getc)
+  end
+
+  def test_each_byte
+    @io.syswrite('abc')
+    res = []
+    @io.each_byte do |c|
+      res << c
+    end
+    assert_equal([97, 98, 99], res)
+  end
+
 end if defined?(OpenSSL)

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

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