Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions core/io.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -2278,7 +2278,7 @@ class IO < Object
# potential security vulnerabilities if called with untrusted input; see
# [Command Injection](rdoc-ref:command_injection.rdoc).
#
def self.binread: (String name, ?Integer? length, ?Integer offset) -> String
def self.binread: (path name, ?Integer? length, ?Integer offset) -> String

# <!--
# rdoc-file=io.c
Expand All @@ -2291,7 +2291,7 @@ class IO < Object
# potential security vulnerabilities if called with untrusted input; see
# [Command Injection](rdoc-ref:command_injection.rdoc).
#
def self.binwrite: (String name, _ToS string, ?Integer offset, ?mode: String mode) -> Integer
def self.binwrite: (path name, _ToS string, ?Integer offset, ?mode: String mode) -> Integer

# <!--
# rdoc-file=io.c
Expand Down Expand Up @@ -2716,7 +2716,7 @@ class IO < Object
# * [Open Options](rdoc-ref:IO@Open+Options).
# * [Encoding options](rdoc-ref:encodings.rdoc@Encoding+Options).
#
def self.read: (String name, ?Integer? length, ?Integer offset, ?external_encoding: String | Encoding | nil, ?internal_encoding: String | Encoding | nil, ?encoding: String | Encoding | nil, ?textmode: boolish, ?binmode: boolish, ?autoclose: boolish, ?mode: String) -> String
def self.read: (path name, ?Integer? length, ?Integer offset, ?external_encoding: String | Encoding | nil, ?internal_encoding: String | Encoding | nil, ?encoding: String | Encoding | nil, ?textmode: boolish, ?binmode: boolish, ?autoclose: boolish, ?mode: String) -> String

# <!--
# rdoc-file=io.c
Expand Down Expand Up @@ -2986,7 +2986,7 @@ class IO < Object
# * [Open Options](rdoc-ref:IO@Open+Options).
# * [Encoding options](rdoc-ref:encodings.rdoc@Encoding+Options).
#
def self.write: (String path, _ToS data, ?Integer offset, ?external_encoding: String | Encoding | nil, ?internal_encoding: String | Encoding | nil, ?encoding: String | Encoding | nil, ?textmode: boolish, ?binmode: boolish, ?autoclose: boolish, ?mode: String) -> Integer
def self.write: (path path, _ToS data, ?Integer offset, ?external_encoding: String | Encoding | nil, ?internal_encoding: String | Encoding | nil, ?encoding: String | Encoding | nil, ?textmode: boolish, ?binmode: boolish, ?autoclose: boolish, ?mode: String) -> Integer

# <!--
# rdoc-file=io.c
Expand Down
33 changes: 33 additions & 0 deletions test/stdlib/IO_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ class IOSingletonTest < Test::Unit::TestCase
def test_binread
assert_send_type "(String) -> String",
IO, :binread, File.expand_path(__FILE__)
assert_send_type "(Pathname) -> String",
IO, :binread, Pathname(File.expand_path(__FILE__))
assert_send_type "(String, Integer) -> String",
IO, :binread, File.expand_path(__FILE__), 3
assert_send_type "(String, Integer, Integer) -> String",
Expand All @@ -26,6 +28,8 @@ def test_binwrite

assert_send_type "(String, String) -> Integer",
IO, :binwrite, filename, content
assert_send_type "(Pathname, String) -> Integer",
IO, :binwrite, Pathname(filename), content
assert_send_type "(String, String, Integer) -> Integer",
IO, :binwrite, filename, content, 0
assert_send_type "(String, String, mode: String) -> Integer",
Expand All @@ -35,6 +39,35 @@ def test_binwrite
end
end

def test_read
assert_send_type "(String) -> String",
IO, :read, File.expand_path(__FILE__)
assert_send_type "(Pathname) -> String",
IO, :read, Pathname(File.expand_path(__FILE__))
assert_send_type "(String, Integer) -> String",
IO, :read, File.expand_path(__FILE__), 3
assert_send_type "(String, Integer, Integer) -> String",
IO, :read, File.expand_path(__FILE__), 3, 0
end

def test_write
Dir.mktmpdir do |dir|
filename = File.join(dir, "some_file")
content = "foo"

assert_send_type "(String, String) -> Integer",
IO, :write, filename, content
assert_send_type "(Pathname, String) -> Integer",
IO, :write, Pathname(filename), content
assert_send_type "(String, String, Integer) -> Integer",
IO, :write, filename, content, 0
assert_send_type "(String, String, mode: String) -> Integer",
IO, :write, filename, content, mode: "a"
assert_send_type "(String, String, Integer, mode: String) -> Integer",
IO, :write, filename, content, 0, mode: "a"
end
end

def test_open
Dir.mktmpdir do |dir|
assert_send_type "(Integer) -> IO",
Expand Down