Skip to content

Commit

Permalink
Updated the basic object type
Browse files Browse the repository at this point in the history
  • Loading branch information
sampersand committed Sep 8, 2023
1 parent 7918e7e commit 6e87c0f
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 21 deletions.
14 changes: 7 additions & 7 deletions core/basic_object.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ class BasicObject
# k = Klass.new
# k.send :hello, "gentle", "readers" #=> "Hello gentle readers"
#
def __send__: (String | Symbol arg0, *untyped args) -> untyped
def __send__: (interned name, *untyped, **untyped) ?{ (*untyped, **untyped) -> untyped } -> untyped

# <!-- rdoc-file=object.c -->
# Equality --- At the Object level, #== returns `true` only if `obj` and `other`
Expand Down Expand Up @@ -195,7 +195,7 @@ class BasicObject
# 1 == 1.0 #=> true
# 1.eql? 1.0 #=> false
#
def equal?: (untyped other) -> bool
alias equal? ==

# <!--
# rdoc-file=vm_eval.c
Expand Down Expand Up @@ -228,7 +228,7 @@ class BasicObject
# k.instance_eval { the_secret } #=> "Ssssh! The secret is 99."
# k.instance_eval {|obj| obj == self } #=> true
#
def instance_eval: (String, ?String filename, ?Integer lineno) -> untyped
def instance_eval: (string code, ?string filename, ?int lineno) -> untyped
| [U] () { (self) [self: self] -> U } -> U

# <!--
Expand Down Expand Up @@ -256,7 +256,7 @@ class BasicObject
# -->
# Returns a new BasicObject.
#
def initialize: () -> void
def initialize: () -> nil

private

Expand Down Expand Up @@ -318,7 +318,7 @@ class BasicObject
# Adding one
# Adding three
#
def singleton_method_added: (Symbol) -> void
def singleton_method_added: (Symbol name) -> nil

# <!--
# rdoc-file=object.c
Expand All @@ -345,7 +345,7 @@ class BasicObject
# Removing three
# Removing one
#
def singleton_method_removed: (Symbol) -> void
def singleton_method_removed: (Symbol) -> nil

# <!--
# rdoc-file=object.c
Expand All @@ -368,5 +368,5 @@ class BasicObject
#
# Undefining one
#
def singleton_method_undefined: (Symbol) -> void
def singleton_method_undefined: (Symbol) -> nil
end
64 changes: 50 additions & 14 deletions test/stdlib/BasicObject_test.rb
Original file line number Diff line number Diff line change
@@ -1,37 +1,73 @@
require_relative "test_helper"

class BasicObjectTest < StdlibTest
target BasicObject

class BasicObjectSingletonTest < Test::Unit::TestCase
include TypeAssertions

testing 'BasicObject'

BOBJ = BasicObject.new

# Satisfy the testing harness framework.
def BOBJ.class = BasicObject
def BOBJ.inspect = ::Kernel.instance_method(:inspect).bind_call(self)
def BOBJ.raise(...) = ::Kernel.raise(...)

def test_not
BasicObject.new.!
assert_send_type '() -> bool',
BOBJ, :!
end

def test_not_equal
BasicObject.new.!=(1)
assert_send_type '(untyped) -> bool',
BOBJ, :!=, 34
end

def test_equal
BasicObject.new.==(1)
BasicObject.new.equal?(1)
def test_eq
assert_send_type '(untyped) -> bool',
BOBJ, :==, 34
end

def test___id__
BasicObject.new.__id__
assert_send_type '() -> Integer',
BOBJ, :__id__
end

def test___send__
BasicObject.new.__send__(:__id__)
BasicObject.new.__send__('__send__', :__id__)
with_interned :__send__ do |name|
assert_send_type '(interned, *untyped, **untyped) -> untyped',
BOBJ, :__send__, name, :__id__
assert_send_type '(interned, *untyped, **untyped) { (*untyped, **untyped) -> untyped} -> untyped',
BOBJ, :__send__, name, :instance_exec do _1 end
end
end

def test_equal?
assert_send_type '(untyped) -> bool',
BOBJ, :equal?, 34
end


def test_instance_eval
BasicObject.new.instance_eval('__id__', 'filename', 1)
BasicObject.new.instance_eval { |x| x }
with_string '__id__' do |code|
assert_send_type '(string) -> untyped',
BOBJ, :instance_eval, code
with_string 'some file' do |filename|
assert_send_type '(string, string) -> untyped',
BOBJ, :instance_eval, code, filename
with_int 123 do |lineno|
assert_send_type '(string, string, int) -> untyped',
BOBJ, :instance_eval, code, filename, lineno
end
end
end

assert_send_type '() { (self) [self: self] -> Integer } -> Integer',
BOBJ, :instance_eval do _1.__id__ end
end

def test_instance_exec
BasicObject.new.instance_exec(1) { 10 }
BasicObject.new.instance_exec(1,2,3) { 10 }
assert_send_type '(*String) { (*String) [self: self] -> Integer } -> Integer',
BOBJ, :instance_exec, '1', '2' do |*x| x.join.to_i end
end
end

0 comments on commit 6e87c0f

Please sign in to comment.