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

ruby-changes:56272

From: Nobuyoshi <ko1@a...>
Date: Sat, 29 Jun 2019 18:44:58 +0900 (JST)
Subject: [ruby-changes:56272] Nobuyoshi Nakada: 7ba14b029c (trunk): Add max option to TestProtocol#create_mockio

https://git.ruby-lang.org/ruby.git/commit/?id=7ba14b029c

From 7ba14b029c64c7f9ef080f5b22065b662145d5d5 Mon Sep 17 00:00:00 2001
From: Nobuyoshi Nakada <nobu@r...>
Date: Sat, 29 Jun 2019 17:52:57 +0900
Subject: Add max option to TestProtocol#create_mockio

* test/net/protocol/test_protocol.rb (TestProtocol#create_mockio):
  max option to limit maximum writable size at once, and unify
  mock method in test_write0_multibyte.

diff --git a/test/net/protocol/test_protocol.rb b/test/net/protocol/test_protocol.rb
index 2ad3709..d3dc2cc 100644
--- a/test/net/protocol/test_protocol.rb
+++ b/test/net/protocol/test_protocol.rb
@@ -27,10 +27,11 @@ class TestProtocol < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/net/protocol/test_protocol.rb#L27
     end
   end
 
-  def create_mockio(capacity: 100)
+  def create_mockio(capacity: 100, max: nil)
     mockio = Object.new
     mockio.instance_variable_set(:@str, +'')
     mockio.instance_variable_set(:@capacity, capacity)
+    mockio.instance_variable_set(:@max, max)
     def mockio.string; @str; end
     def mockio.to_io; self; end
     def mockio.wait_writable(sec); sleep sec; false; end
@@ -43,10 +44,11 @@ class TestProtocol < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/net/protocol/test_protocol.rb#L44
         end
       end
       len = 0
+      max = @max ? [@capacity, @str.bytesize + @max].min : @capacity
       strs.each do |str|
         len1 = @str.bytesize
-        break if @capacity <= len1
-        @str << str.byteslice(0, @capacity - @str.bytesize)
+        break if max <= len1
+        @str << str.byteslice(0, max - @str.bytesize)
         len2 = @str.bytesize
         len += len2 - len1
       end
@@ -56,11 +58,7 @@ class TestProtocol < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/net/protocol/test_protocol.rb#L58
   end
 
   def test_write0_multibyte
-    mockio = create_mockio(capacity: 1)
-    def mockio.write_nonblock(str, *strs, **kw)
-      @str << str.byteslice(0, 1)
-      1
-    end
+    mockio = create_mockio(max: 1)
     io = Net::BufferedIO.new(mockio)
     assert_equal(3, io.write("\u3042"))
   end
-- 
cgit v0.10.2


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

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