require 'test/minirunit' require 'stringio' string = <, $stdout) puts "HEL\nEEEE\n" n.rewind test_equal("HEL\n", n.gets) $stdout = old_stdout n = StringIO.new $> = n puts "HEL\nEEEE\n" n.rewind test_equal("HEL\n", n.gets) n = StringIO.new("123\n456\n789\n") test_equal("123\n456\n789\n", n.gets(nil)) $/="\n" saved_stdin = $stdin $stdin = StringIO.new("HEH\nWorld\n") #test_equal("HEH\n", gets) $stdin = saved_stdin n = StringIO.new old_stdout = $stdout $stdout = n test_equal($>, $stdout) puts "HEL\nEEEE\n" n.rewind test_equal("HEL\n", n.gets) $stdout = old_stdout n = StringIO.new $> = n puts "HEL\nEEEE\n" n.rewind test_equal("HEL\n", n.gets) n = StringIO.new("123\n456\n789\n") test_equal("123\n456\n789\n", n.gets(nil)) n = StringIO.new n.puts n.rewind test_equal("\n", n.gets) test_equal(nil, n.gets) test_equal(true, n.eof?) n = StringIO.new buf = "" s = StringIO.new(buf, "r+") s.puts "HEH" test_equal("HEH\n", buf) n = StringIO.new n.puts "test\n" test_equal("test\n",n.string) class Foo def to_int 65 end end s = StringIO.new("abc", File::WRONLY) s.putc(Foo.new) test_equal("Abc", s.string) test_exception(TypeError) { s.putc('') } test_exception(Errno::EINVAL) { s.seek(-40) } s = StringIO.new("foo\n", "r") s.gets s.gets test_equal(nil ,$_) # JRUBY-2629 test_exception(IOError) { StringIO.allocate.gets } test_exception(IOError) { StringIO.allocate << 5 } test_exception(IOError) { StringIO.allocate.close }