1 # frozen_string_literal: false
6 class TestReadPartial < Test::Unit::TestCase
14 r.close unless r.closed?
15 w.close unless w.closed?
23 return unless defined?(Fcntl::F_SETFL)
24 return unless defined?(Fcntl::F_GETFL)
25 return unless defined?(Fcntl::O_NONBLOCK)
27 r.fcntl(Fcntl::F_SETFL, r.fcntl(Fcntl::F_GETFL) | Fcntl::O_NONBLOCK)
34 assert_equal('', r.readpartial(0))
42 assert_equal('ab', r.readpartial(2))
43 assert_equal('c', r.readpartial(2))
44 assert_raise(EOFError) { r.readpartial(2) }
45 assert_raise(EOFError) { r.readpartial(2) }
52 assert_equal('ab', r.readpartial(2))
53 assert_equal('c', r.readpartial(2))
54 assert_raise(Timeout::Error) {
55 Timeout.timeout(0.1) { r.readpartial(2) }
63 assert_equal("abc\n", r.gets)
65 assert_equal("de", r.readpartial(2))
66 assert_equal("f\n", r.readpartial(4096))
67 assert_equal("ghi\n", r.readpartial(4096))
68 assert_raise(Timeout::Error) {
69 Timeout.timeout(0.1) { r.readpartial(2) }