Skip to content

Commit

Permalink
Merge pull request #1789 from ksss/string-new
Browse files Browse the repository at this point in the history
Should focus on `String.new` not `String#initialize`.
  • Loading branch information
soutaro authored Apr 6, 2024
2 parents 00bad8a + 57677db commit 7bae527
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 21 deletions.
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

0 comments on commit 7bae527

Please sign in to comment.