diff options
author | Jean byroot Boussier <[email protected]> | 2023-06-08 05:27:04 +0200 |
---|---|---|
committer | Hiroshi SHIBATA <[email protected]> | 2023-08-02 18:18:17 +0900 |
commit | fd8dd7199665ed26818a140de945cca71d6fc84b (patch) | |
tree | 01e7363f8c2ef43f62db5bf7ceb7d55b211821da /test/stringio/test_stringio.rb | |
parent | 201fd5751897618eb2a9a91f6f14241f0bad4744 (diff) |
Implement StringIO#pread (#56)
Both for being closer to real IOs and also because it's a convenient API
in multithreaded scenarios.
Co-authored-by: Jean Boussier <[email protected]>
Diffstat (limited to 'test/stringio/test_stringio.rb')
-rw-r--r-- | test/stringio/test_stringio.rb | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/test/stringio/test_stringio.rb b/test/stringio/test_stringio.rb index fd9974caeb..246f107d05 100644 --- a/test/stringio/test_stringio.rb +++ b/test/stringio/test_stringio.rb @@ -729,6 +729,25 @@ class TestStringIO < Test::Unit::TestCase assert_equal Encoding::ASCII_8BIT, f.sysread(3).encoding end + def test_pread + f = StringIO.new("pread") + f.read + + assert_equal "pre".b, f.pread(3, 0) + assert_equal "read".b, f.pread(4, 1) + assert_equal Encoding::ASCII_8BIT, f.pread(4, 1).encoding + + buf = "".b + f.pread(3, 0, buf) + assert_equal "pre".b, buf + f.pread(4, 1, buf) + assert_equal "read".b, buf + + assert_raise(EOFError) { f.pread(1, 5) } + assert_raise(ArgumentError) { f.pread(-1, 0) } + assert_raise(Errno::EINVAL) { f.pread(3, -1) } + end + def test_size f = StringIO.new("1234") assert_equal(4, f.size) |