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
161 changes: 84 additions & 77 deletions test/stdlib/CGI_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,37 +7,6 @@ class CGISingletonTest < Test::Unit::TestCase
library "cgi"
testing "singleton(::CGI)"

def test_new
ARGV.replace(%w(abc=001 def=002))
assert_send_type "() -> void",
CGI, :new
assert_send_type "(?::String options) -> void",
CGI, :new, 'html3'
assert_send_type "(?::String options) ?{ (::String name, ::String value) -> void } -> void",
CGI, :new, 'html3' do |name, value| name + value end
assert_send_type "(::Hash[::Symbol, untyped] options_hash) -> void",
CGI, :new, { tag_maker: 'html5', max_multipart_length: 2048 }
assert_send_type "(::Hash[::Symbol, untyped] options_hash) ?{ (::String name, ::String value) -> void } -> void",
CGI, :new, { tag_maker: 'html5', max_multipart_length: 2048 } do |name, value| name + value end
end

def test_accept_charset
assert_send_type "() -> ::encoding",
CGI, :accept_charset
end

def test_accept_charset=
assert_send_type "(::String accept_charset) -> ::String",
CGI, :accept_charset=, 'utf-8'
assert_send_type "(::Encoding accept_charset) -> ::Encoding",
CGI, :accept_charset=, Encoding::UTF_8
end

def test_parse
assert_send_type "(::String query) -> ::Hash[::String, String | Array[String]]",
CGI, :parse, 'a=hoge&b=1&c[]=test1&c[]=test2'
end

def test_escapeURIComponent
assert_send_type(
"(String) -> String",
Expand All @@ -59,6 +28,41 @@ def test_unescapeURIComponent
CGI, :unescapeURIComponent, ToStr.new("hogehoge")
)
end

# These methods are removed in Ruby 3.5.
unless RUBY_VERSION >= "3.5"
def test_new
ARGV.replace(%w(abc=001 def=002))
assert_send_type "() -> void",
CGI, :new

assert_send_type "(?::String options) -> void",
CGI, :new, 'html3'
assert_send_type "(?::String options) ?{ (::String name, ::String value) -> void } -> void",
CGI, :new, 'html3' do |name, value| name + value end
assert_send_type "(::Hash[::Symbol, untyped] options_hash) -> void",
CGI, :new, { tag_maker: 'html5', max_multipart_length: 2048 }
assert_send_type "(::Hash[::Symbol, untyped] options_hash) ?{ (::String name, ::String value) -> void } -> void",
CGI, :new, { tag_maker: 'html5', max_multipart_length: 2048 } do |name, value| name + value end
end

def test_accept_charset
assert_send_type "() -> ::encoding",
CGI, :accept_charset
end

def test_accept_charset=
assert_send_type "(::String accept_charset) -> ::String",
CGI, :accept_charset=, 'utf-8'
assert_send_type "(::Encoding accept_charset) -> ::Encoding",
CGI, :accept_charset=, Encoding::UTF_8
end

def test_parse
assert_send_type "(::String query) -> ::Hash[::String, String | Array[String]]",
CGI, :parse, 'a=hoge&b=1&c[]=test1&c[]=test2'
end
end
end

class CGITest < Test::Unit::TestCase
Expand All @@ -77,51 +81,54 @@ def test_print
CGI.new, :print, ''
end

def test_http_header
assert_send_type "() -> ::String",
CGI.new, :http_header
assert_send_type "(::String options) -> ::String",
CGI.new, :http_header, 'text/csv'
assert_send_type "(::Hash[::String, untyped] header_hash) -> ::String",
CGI.new, :http_header, { 'type' => 'text/csv', 'nph' => false, 'length' => 1024 }
assert_send_type "(::Hash[::Symbol, untyped] header_hash) -> ::String",
CGI.new, :http_header, { type: 'text/csv', nph: false, length: 1024 }
end

def test_header
assert_send_type "() -> ::String",
CGI.new, :header
assert_send_type "(::String options) -> ::String",
CGI.new, :header, 'text/csv'
assert_send_type "(::Hash[::String, untyped] header_hash) -> ::String",
CGI.new, :header, { 'type' => 'text/csv', 'nph' => false, 'length' => 1024 }
assert_send_type "(::Hash[::Symbol, untyped] header_hash) -> ::String",
CGI.new, :header, { type: 'text/csv', nph: false, length: 1024 }
end

def test_nph?
assert_send_type "() -> ::boolish",
CGI.new, :nph?
end

def test_out
assert_send_type "() { () -> void } -> void",
CGI.new, :out do '' end
assert_send_type "(::String content_type_string) { () -> String } -> void",
CGI.new, :out, 'text/csv' do '' end
assert_send_type "(::Hash[::String, untyped] header_hash) { () -> String } -> void",
CGI.new, :out, { 'type' => 'text/csv', 'nph' => false, 'length' => 1024 } do '' end
assert_send_type "(::Hash[::String | ::Symbol, untyped] header_hash) { () -> String } -> void",
CGI.new, :out, { type: 'text/csv' } do '' end
end

def test_stdinput
assert_send_type "() -> ::IO",
CGI.new, :stdinput
end

def test_stdoutput
assert_send_type "() -> ::IO",
CGI.new, :stdoutput
# These methods are removed in Ruby 3.5.
unless RUBY_VERSION >= "3.5"
def test_http_header
assert_send_type "() -> ::String",
CGI.new, :http_header
assert_send_type "(::String options) -> ::String",
CGI.new, :http_header, 'text/csv'
assert_send_type "(::Hash[::String, untyped] header_hash) -> ::String",
CGI.new, :http_header, { 'type' => 'text/csv', 'nph' => false, 'length' => 1024 }
assert_send_type "(::Hash[::Symbol, untyped] header_hash) -> ::String",
CGI.new, :http_header, { type: 'text/csv', nph: false, length: 1024 }
end

def test_header
assert_send_type "() -> ::String",
CGI.new, :header
assert_send_type "(::String options) -> ::String",
CGI.new, :header, 'text/csv'
assert_send_type "(::Hash[::String, untyped] header_hash) -> ::String",
CGI.new, :header, { 'type' => 'text/csv', 'nph' => false, 'length' => 1024 }
assert_send_type "(::Hash[::Symbol, untyped] header_hash) -> ::String",
CGI.new, :header, { type: 'text/csv', nph: false, length: 1024 }
end

def test_nph?
assert_send_type "() -> ::boolish",
CGI.new, :nph?
end

def test_out
assert_send_type "() { () -> void } -> void",
CGI.new, :out do '' end
assert_send_type "(::String content_type_string) { () -> String } -> void",
CGI.new, :out, 'text/csv' do '' end
assert_send_type "(::Hash[::String, untyped] header_hash) { () -> String } -> void",
CGI.new, :out, { 'type' => 'text/csv', 'nph' => false, 'length' => 1024 } do '' end
assert_send_type "(::Hash[::String | ::Symbol, untyped] header_hash) { () -> String } -> void",
CGI.new, :out, { type: 'text/csv' } do '' end
end

def test_stdinput
assert_send_type "() -> ::IO",
CGI.new, :stdinput
end

def test_stdoutput
assert_send_type "() -> ::IO",
CGI.new, :stdoutput
end
end
end
12 changes: 12 additions & 0 deletions test/stdlib/Pathname_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ def test_pwd
end

def test_initialize
omit "Pathname is developing in head" if RUBY_VERSION >= '3.5'

assert_send_type '(String) -> Pathname',
Pathname, :new, 'foo'
assert_send_type '(ToStr) -> Pathname',
Expand All @@ -43,6 +45,8 @@ class PathnameInstanceTest < Test::Unit::TestCase
testing '::Pathname'

def test_plus
omit "Pathname is developing in head" if RUBY_VERSION >= '3.5'

assert_send_type '(Pathname) -> Pathname',
Pathname('foo'), :+, Pathname('bar')
assert_send_type '(String) -> Pathname',
Expand All @@ -52,6 +56,8 @@ def test_plus
end

def test_slash
omit "Pathname is developing in head" if RUBY_VERSION >= '3.5'

assert_send_type '(Pathname) -> Pathname',
Pathname('foo'), :/, Pathname('bar')
assert_send_type '(String) -> Pathname',
Expand Down Expand Up @@ -380,6 +386,8 @@ def test_inspect
end

def test_join
omit "Pathname is developing in head" if RUBY_VERSION >= '3.5'

assert_send_type '() -> Pathname',
Pathname('.'), :join
assert_send_type '(String) -> Pathname',
Expand Down Expand Up @@ -602,6 +610,8 @@ def test_relative?
end

def test_relative_path_from
omit "Pathname is developing in head" if RUBY_VERSION >= '3.5'

assert_send_type '(Pathname) -> Pathname',
Pathname('.'), :relative_path_from, Pathname('.')
assert_send_type '(String) -> Pathname',
Expand Down Expand Up @@ -824,6 +834,8 @@ class PathnameKernelTest < Test::Unit::TestCase
testing '::Kernel'

def test_Pathname
omit "Pathname is developing in head" if RUBY_VERSION >= '3.5'

with_string("Gemfile") do
assert_send_type(
"(::string) -> ::Pathname",
Expand Down
16 changes: 14 additions & 2 deletions test/stdlib/Ractor_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,18 @@ def test_recv
end

def test_receive_if
omit "Ractor.receive_if is not implemented" if RUBY_VERSION >= "3.5"

Ractor.current.send 42
assert_send_type "() { (Integer) -> bool } -> Integer",
Ractor, :receive_if do |n| n == 42 end
end

def test_select
r1 = Ractor.new { loop { Ractor.yield 42 } }
r2 = Ractor.new { loop { Ractor.yield 43 } }
omit "Ractor#yield is not implemented" if RUBY_VERSION >= "3.5"

r1 = Ractor.new {|r| loop { Ractor.yield 42 } }
r2 = Ractor.new {|r| loop { Ractor.yield 43 } }

assert_send_type "(Ractor) -> [Ractor, Integer]",
Ractor, :select, r1
Expand Down Expand Up @@ -115,6 +119,8 @@ def test_store_if_absent
end

def test_yield
omit "Ractor#yield is not implemented" if RUBY_VERSION >= "3.5"

Ractor.new(Ractor.current) { |r| loop { r.take } }

assert_send_type "(Integer) -> untyped",
Expand Down Expand Up @@ -153,12 +159,16 @@ def test_aset
end

def test_close_incoming
omit "Ractor#close_incoming is not implemented" if RUBY_VERSION >= "3.5"

r = Ractor.new {}
assert_send_type "() -> bool",
r, :close_incoming
end

def test_close_outgoing
omit "Ractor#close_outgoing is not implemented" if RUBY_VERSION >= "3.5"

r = Ractor.new {}
assert_send_type "() -> bool",
r, :close_outgoing
Expand Down Expand Up @@ -190,6 +200,8 @@ def test_send
end

def test_take
omit "Ractor#take is not implemented" if RUBY_VERSION >= "3.5"

r = Ractor.new { 42 }

assert_send_type "() -> Integer",
Expand Down
Loading