Skip to content
Open
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
65 changes: 65 additions & 0 deletions test/stdlib/Etc_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,68 @@ def test_uname
Etc, :uname
end
end

class EtcGroupSingletonTest < Test::Unit::TestCase
include TestHelper

library "etc"
testing "singleton(::Etc::Group)"

def test_each
assert_send_type "() { (::Etc::Group) -> void } -> singleton(::Etc::Group)",
Etc::Group, :each do |_g| end
assert_send_type "() -> ::Enumerator[::Etc::Group]",
Etc::Group, :each
end
end

class EtcPasswdSingletonTest < Test::Unit::TestCase
include TestHelper

library "etc"
testing "singleton(::Etc::Passwd)"

def test_each
assert_send_type "() { (::Etc::Passwd) -> void } -> singleton(::Etc::Passwd)",
Etc::Passwd, :each do |_u| end
assert_send_type "() -> ::Enumerator[::Etc::Passwd]",
Etc::Passwd, :each
end
end

class EtcPasswdInstanceTest < Test::Unit::TestCase
include TestHelper

library "etc"
testing "::Etc::Passwd"

def test_age
omit "no age member on this platform" unless Etc::Passwd.members.include?(:age)
pw = Etc.getpwuid

assert_send_type "() -> ::Integer",
pw, :age
assert_send_type "(::Integer) -> void",
pw, :age=, pw.age
end

def test_comment
omit "no comment member on this platform" unless Etc::Passwd.members.include?(:comment)
pw = Etc.getpwuid

assert_send_type "() -> ::String",
pw, :comment
assert_send_type "(::String) -> void",
pw, :comment=, pw.comment
end

def test_quota
omit "no quota member on this platform" unless Etc::Passwd.members.include?(:quota)
pw = Etc.getpwuid

assert_send_type "() -> ::Integer",
pw, :quota
assert_send_type "(::Integer) -> void",
pw, :quota=, pw.quota
end
end
10 changes: 10 additions & 0 deletions test/stdlib/IO_test.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require_relative "test_helper"
require 'tempfile'
require 'etc'

require "io/wait"

Expand Down Expand Up @@ -227,6 +228,15 @@ def test_append_symbol
end
end

def test_pathconf
IO.pipe do |r, w|
assert_send_type "(Integer) -> Integer",
w, :pathconf, Etc::PC_PIPE_BUF
end
rescue NotImplementedError
omit "Not implemented"
end

def test_advise
IO.open(IO.sysopen(File.expand_path(__FILE__))) do |io|
assert_send_type "(Symbol) -> nil",
Expand Down
87 changes: 87 additions & 0 deletions test/stdlib/StringIO_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,23 @@ def test_gets
end
end

class StringIOSingletonTest < Test::Unit::TestCase
include TestHelper

testing 'singleton(::StringIO)'

def test_open
assert_send_type "() -> ::StringIO",
StringIO, :open
assert_send_type "(::String) -> ::StringIO",
StringIO, :open, "abc"
assert_send_type "(::String, ::String) -> ::StringIO",
StringIO, :open, "abc", "r"
assert_send_type "() { (::StringIO) -> ::Integer } -> ::Integer",
StringIO, :open do |io| io.write("a") end
end
end

class StringIOTypeTest < Test::Unit::TestCase
include TestHelper

Expand Down Expand Up @@ -85,4 +102,74 @@ def test_readlines
assert_send_type "(::String sep, ::Integer limit, chomp: boolish) -> ::Array[::String]",
StringIO.new("\n"), :readlines, "\n", 1, chomp: true
end

def test_pread
assert_send_type "(Integer, Integer) -> String",
StringIO.new("abcdef"), :pread, 3, 0
assert_send_type "(Integer, Integer, String) -> String",
StringIO.new("abcdef"), :pread, 3, 0, +"buf"
end

def test_read_nonblock
assert_send_type "(int) -> String",
StringIO.new("abc"), :read_nonblock, 2
assert_send_type "(int, string) -> String",
StringIO.new("abc"), :read_nonblock, 2, +"buf"
assert_send_type "(int, exception: true) -> String",
StringIO.new("abc"), :read_nonblock, 2, exception: true
assert_send_type "(int, exception: false) -> String",
StringIO.new("abc"), :read_nonblock, 2, exception: false
assert_send_type "(int, exception: false) -> nil",
StringIO.new(""), :read_nonblock, 2, exception: false
end

def test_write_nonblock
assert_send_type "(_ToS) -> Integer",
StringIO.new(+""), :write_nonblock, "abc"
assert_send_type "(_ToS, exception: true) -> Integer",
StringIO.new(+""), :write_nonblock, "abc", exception: true
assert_send_type "(_ToS, exception: false) -> Integer",
StringIO.new(+""), :write_nonblock, "abc", exception: false
end

def test_sysread
assert_send_type "(Integer) -> String",
StringIO.new("abc"), :sysread, 2
assert_send_type "(Integer, String) -> String",
StringIO.new("abc"), :sysread, 2, +"buf"
end

def test_ungetc
assert_send_type "(String) -> nil",
StringIO.new(+"abc"), :ungetc, "x"
assert_send_type "(Integer) -> nil",
StringIO.new(+"abc"), :ungetc, 65
end

def test_set_encoding_by_bom
assert_send_type "() -> Encoding",
StringIO.new("\u{FEFF}abc"), :set_encoding_by_bom
assert_send_type "() -> nil",
StringIO.new("abc"), :set_encoding_by_bom
end

def test_fcntl
assert_send_type_error "(*untyped) -> bot", NotImplementedError,
StringIO.new("abc"), :fcntl, 1, 1
end

def test_fsync
assert_send_type "() -> Integer",
StringIO.new("abc"), :fsync
end

def test_internal_encoding
assert_send_type "() -> nil",
StringIO.new("abc"), :internal_encoding
end

def test_external_encoding
assert_send_type "() -> Encoding",
StringIO.new("abc"), :external_encoding
end
end
Loading