Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Should focus on String.new not String#initialize. #1789

Merged
merged 1 commit into from
Apr 6, 2024
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
2 changes: 1 addition & 1 deletion core/string.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,7 @@ class String
#
# String.new('hello', encoding: 'UTF-8', capacity: 25)
#
def initialize: (?string source, ?encoding: encoding?, ?capacity: int?) -> self
def initialize: (?string source, ?encoding: encoding, ?capacity: int) -> void

# <!--
# rdoc-file=string.c
Expand Down
40 changes: 20 additions & 20 deletions test/stdlib/String_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,26 @@ class StringSingletonTest < Test::Unit::TestCase

testing 'singleton(::String)'

def test_new
assert_send_type '() -> String',
String, :new

with_string do |source|
assert_send_type '(string) -> String',
String, :new, source
end

with_encoding do |encoding|
assert_send_type '(encoding: encoding) -> String',
String, :new, encoding: encoding
end

with_int do |capacity|
assert_send_type '(capacity: int) -> String',
String, :new, capacity: capacity
end
end

def test_try_convert
assert_send_type '(String) -> String',
String, :try_convert, 'foo'
Expand Down Expand Up @@ -73,26 +93,6 @@ def assert_case_method!(method, normal:, nochange:, include_fold: false)
nochange.dup, method, :turkic, :lithuanian
end

def test_initialize
assert_send_type '() -> String',
String.allocate, :initialize

with_string do |source|
assert_send_type '(string) -> String',
String.allocate, :initialize, source
end

with_encoding.and_nil do |encoding|
assert_send_type '(encoding: encoding?) -> String',
String.allocate, :initialize, encoding: encoding
end

with_int.and_nil do |capacity|
assert_send_type '(capacity: int?) -> String',
String.allocate, :initialize, capacity: capacity
end
end

def test_initialize_copy
test_replace(:initialize_copy)
end
Expand Down