From fb04c3dd5320927f78c9984bc66028b4259718e9 Mon Sep 17 00:00:00 2001 From: nobu Date: Tue, 27 Oct 2009 13:22:40 +0000 Subject: * ext/stringio/stringio.c (Init_stringio): added read_nonblock and write_nonblock aliases. [ruby-dev:39551] git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@25517 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/stringio/test_stringio.rb | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'test/stringio') diff --git a/test/stringio/test_stringio.rb b/test/stringio/test_stringio.rb index 212315ae1..63647683c 100644 --- a/test/stringio/test_stringio.rb +++ b/test/stringio/test_stringio.rb @@ -87,6 +87,28 @@ class TestStringIO < Test::Unit::TestCase 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 @@ class TestStringIO < Test::Unit::TestCase 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) -- cgit