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

ruby-changes:13725

From: nobu <ko1@a...>
Date: Tue, 27 Oct 2009 22:22:59 +0900 (JST)
Subject: [ruby-changes:13725] Ruby:r25517 (trunk): * ext/stringio/stringio.c (Init_stringio): added read_nonblock and

nobu	2009-10-27 22:22:40 +0900 (Tue, 27 Oct 2009)

  New Revision: 25517

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

  Log:
    * ext/stringio/stringio.c (Init_stringio): added read_nonblock and
      write_nonblock aliases.  [ruby-dev:39551]

  Modified files:
    trunk/ChangeLog
    trunk/ext/stringio/stringio.c
    trunk/test/stringio/test_stringio.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 25516)
+++ ChangeLog	(revision 25517)
@@ -1,5 +1,8 @@
-Tue Oct 27 22:14:50 2009  Nobuyoshi Nakada  <nobu@r...>
+Tue Oct 27 22:22:38 2009  Nobuyoshi Nakada  <nobu@r...>
 
+	* ext/stringio/stringio.c (Init_stringio): added read_nonblock and
+	  write_nonblock aliases.  [ruby-dev:39551]
+
 	* ext/stringio/stringio.c (strio_data_type): typed.
 
 Tue Oct 27 21:20:35 2009  Hidetoshi NAGAI  <nagai@a...>
Index: ext/stringio/stringio.c
===================================================================
--- ext/stringio/stringio.c	(revision 25516)
+++ ext/stringio/stringio.c	(revision 25517)
@@ -1410,6 +1410,7 @@
     rb_define_method(StringIO, "read", strio_read, -1);
     rb_define_method(StringIO, "sysread", strio_sysread, -1);
     rb_define_method(StringIO, "readpartial", strio_sysread, -1);
+    rb_define_method(StringIO, "read_nonblock", strio_sysread, -1);
 
     rb_define_method(StringIO, "write", strio_write, 1);
     rb_define_method(StringIO, "<<", strio_addstr, 1);
@@ -1418,6 +1419,7 @@
     rb_define_method(StringIO, "putc", strio_putc, 1);
     rb_define_method(StringIO, "puts", strio_puts, -1);
     rb_define_method(StringIO, "syswrite", strio_syswrite, 1);
+    rb_define_method(StringIO, "write_nonblock", strio_syswrite, 1);
 
     rb_define_method(StringIO, "isatty", strio_isatty, 0);
     rb_define_method(StringIO, "tty?", strio_isatty, 0);
Index: test/stringio/test_stringio.rb
===================================================================
--- test/stringio/test_stringio.rb	(revision 25516)
+++ test/stringio/test_stringio.rb	(revision 25517)
@@ -87,6 +87,28 @@
     f.close unless f.closed?
   end
 
+  def test_write_nonblock
+    s = ""
+    f = StringIO.new(s, "w")
+    f.write_nonblock("foo")
+    f.close
+    assert_equal("foo", s)
+
+    f = StringIO.new(s, File::WRONLY)
+    f.write_nonblock("bar")
+    f.close
+    assert_equal("bar", s)
+
+    f = StringIO.new(s, "a")
+    o = Object.new
+    def o.to_s; "baz"; end
+    f.write_nonblock(o)
+    f.close
+    assert_equal("barbaz", s)
+  ensure
+    f.close unless f.closed?
+  end
+
   def test_mode_error
     f = StringIO.new("", "r")
     assert_raise(IOError) { f.write("foo") }
@@ -390,6 +412,24 @@
     assert_equal("\u3042\u3044".force_encoding(Encoding::ASCII_8BIT), f.read(f.size))
   end
 
+  def test_readpartial
+    f = StringIO.new("\u3042\u3044")
+    assert_raise(ArgumentError) { f.readpartial(-1) }
+    assert_raise(ArgumentError) { f.readpartial(1, 2, 3) }
+    assert_equal("\u3042\u3044", f.readpartial)
+    f.rewind
+    assert_equal("\u3042\u3044".force_encoding(Encoding::ASCII_8BIT), f.readpartial(f.size))
+  end
+
+  def test_read_nonblock
+    f = StringIO.new("\u3042\u3044")
+    assert_raise(ArgumentError) { f.read_nonblock(-1) }
+    assert_raise(ArgumentError) { f.read_nonblock(1, 2, 3) }
+    assert_equal("\u3042\u3044", f.read_nonblock)
+    f.rewind
+    assert_equal("\u3042\u3044".force_encoding(Encoding::ASCII_8BIT), f.read_nonblock(f.size))
+  end
+
   def test_size
     f = StringIO.new("1234")
     assert_equal(4, f.size)

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

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