From 3586aef4b8a18fca685f883c80367a80182b943e Mon Sep 17 00:00:00 2001 From: nobu Date: Tue, 29 Dec 2015 23:44:01 +0000 Subject: test_stringio.rb: test_initialize * test/stringio/test_stringio.rb (test_initialize): add test for StringIO#initialize. [ruby-core:72585] [Feature #11920] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53378 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/stringio/test_stringio.rb | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'test/stringio') diff --git a/test/stringio/test_stringio.rb b/test/stringio/test_stringio.rb index 9a041c2148..77a98726d8 100644 --- a/test/stringio/test_stringio.rb +++ b/test/stringio/test_stringio.rb @@ -13,6 +13,27 @@ class TestStringIO < Test::Unit::TestCase include TestEOF::Seek + def test_initialize + assert_kind_of StringIO, StringIO.new + assert_kind_of StringIO, StringIO.new('str') + assert_kind_of StringIO, StringIO.new('str', 'r+') + assert_raise(ArgumentError) { StringIO.new('', 'x') } + assert_raise(ArgumentError) { StringIO.new('', 'rx') } + assert_raise(ArgumentError) { StringIO.new('', 'rbt') } + assert_raise(TypeError) { StringIO.new(nil) } + assert_raise(TypeError) { StringIO.new('str', nil) } + + o = Object.new + def o.to_str + nil + end + assert_raise(TypeError) { StringIO.new(o) } + def o.to_str + 'str' + end + assert_kind_of StringIO, StringIO.new(o) + end + def test_truncate io = StringIO.new("") io.puts "abc" -- cgit v1.2.3