Skip to content

Commit 033ef08

Browse files
committed
update module
1 parent 86bbbe8 commit 033ef08

3 files changed

Lines changed: 36 additions & 7 deletions

File tree

core/module.rbs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ class Module
348348
#
349349
# Files that are currently being loaded must not be registered for autoload.
350350
#
351-
def autoload: (interned constant, String filename) -> NilClass
351+
def autoload: (interned constant, path filename) -> nil
352352

353353
# <!--
354354
# rdoc-file=load.c
@@ -829,7 +829,7 @@ class Module
829829

830830
# <!--
831831
# rdoc-file=object.c
832-
# - (othermod)
832+
# - extended(othermod)
833833
# -->
834834
# The equivalent of `included`, but for extended modules.
835835
#

lib/rbs/unit_test/type_assertions.rb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,8 +296,13 @@ def assert_const_type(type, constant_name)
296296
assert typecheck.value(constant, definition_type), "`#{constant_name}` (#{constant.inspect}) must be compatible with RBS type definition `#{definition_type}`"
297297
end
298298

299-
def assert_visibility(vis, receiver, method)
300-
puts 'TODO: visibility for types'
299+
def assert_visibility(visibility, receiver, method)
300+
_, definition = target
301+
method_entry = definition.methods[method]
302+
303+
assert method_entry, "Method `#{method}` not found in RBS definition"
304+
assert_equal visibility, method_entry.accessibility,
305+
"Expected `#{method}` to be #{visibility}, but was #{method_entry.accessibility}"
301306
end
302307

303308
def assert_type(type, value)

test/stdlib/Module_test.rb

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -511,11 +511,35 @@ def test_ancestors
511511
end
512512

513513
def test_autoload
514-
omit 'todo'
514+
with_interned :Constant do |constant|
515+
with_path do |path|
516+
assert_send_type '(interned, path) -> nil',
517+
Module.new, :autoload, constant, path
518+
end
519+
end
515520
end
516521

517522
def test_autoload?
518-
omit 'todo'
523+
autoloaded = Module.new
524+
autoloaded.autoload(:Constant, 'Bar')
525+
526+
with_interned :Constant do |constant|
527+
assert_send_type '(interned) -> nil',
528+
Module.new, :autoload?, constant
529+
assert_send_type '(interned) -> String',
530+
autoloaded, :autoload?, constant
531+
assert_send_type '(interned) -> String',
532+
Module.new.include(autoloaded), :autoload?, constant
533+
534+
with_boolish do |inherit|
535+
assert_send_type '(interned, boolish) -> nil',
536+
Module.new, :autoload?, constant, inherit
537+
assert_send_type '(interned, boolish) -> String',
538+
autoloaded, :autoload?, constant, inherit
539+
assert_send_type '(interned, boolish) -> String?',
540+
Module.new.include(autoloaded), :autoload?, constant, inherit
541+
end
542+
end
519543
end
520544

521545
def test_class_variable_defined?
@@ -1264,6 +1288,6 @@ def test_using
12641288
Module.new, :using
12651289

12661290
# Cant actually test `using` in modules, so this is the best we got
1267-
assert_type 'Module', UsingModule::UsingModule
1291+
assert_type 'Module', UsingModule::UsingReturnValue
12681292
end
12691293
end

0 commit comments

Comments
 (0)