-
Notifications
You must be signed in to change notification settings - Fork 217
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7918e7e
commit 6e87c0f
Showing
2 changed files
with
57 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |