Skip to content

Commit

Permalink
Merge pull request #1507 from sampersand/swesterman/23-09-08/update-b…
Browse files Browse the repository at this point in the history
…inding

Updated binding to use modern kernel tests
  • Loading branch information
soutaro authored Sep 15, 2023
2 parents cd5ec54 + 611cb4f commit c9faa05
Showing 1 changed file with 42 additions and 23 deletions.
65 changes: 42 additions & 23 deletions test/stdlib/Binding_test.rb
Original file line number Diff line number Diff line change
@@ -1,53 +1,72 @@
require_relative "test_helper"

class BindingTest < StdlibTest
target Binding
class BindingInstanceTest < Test::Unit::TestCase
include TypeAssertions

testing 'Binding'

def test_clone
binding.clone
assert_send_type '() -> Binding',
binding, :clone
end

def test_dup
binding.dup
assert_send_type '() -> Binding',
binding, :dup
end

def test_eval
binding.eval('1', '(eval)', 1)
binding.eval(ToStr.new)
binding.eval(ToStr.new, ToStr.new)
binding.eval(ToStr.new, ToStr.new, ToInt.new)
with_string '123' do |src|
assert_send_type '(string) -> untyped',
binding, :eval, src

with_string 'my file' do |filename|
assert_send_type '(string, string) -> untyped',
binding, :eval, src, filename

with_int 3 do |lineno|
assert_send_type '(string, string, int) -> untyped',
binding, :eval, src, filename, lineno
end
end
end
end

def test_local_variable_defined?
binding.local_variable_defined?(:yes)
yes = true
binding.local_variable_defined?('yes')
binding.local_variable_defined?(ToStr.new('yes'))
with_interned :hello do |varname|
assert_send_type '(interned) -> bool',
binding, :local_variable_defined?, varname
end
end

def test_local_variable_get
foo = 1
binding.local_variable_get(:foo)
binding.local_variable_get('foo')
binding.local_variable_get(ToStr.new('foo'))
with_interned :varname do |varname|
assert_send_type '(interned) -> untyped',
binding, :local_variable_get, varname
end
end

def test_local_variable_set
binding.local_variable_set(:foo, 1)
binding.local_variable_set('foo', 1)
binding.local_variable_set(ToStr.new('foo'), 1)
with_interned :hello do |varname|
assert_send_type '(interned, Rational) -> Rational',
binding, :local_variable_set, varname, 1r
end
end

def test_local_variables
foo = 1
binding.local_variables
foo = bar = baz = 3 # make a few local variables

assert_send_type '() -> Array[Symbol]',
binding, :local_variables
end

def test_receiver
binding.receiver
assert_send_type '() -> untyped',
binding, :receiver
end

def test_source_location
binding.source_location
assert_send_type '() -> [String, Integer]',
binding, :source_location
end
end

0 comments on commit c9faa05

Please sign in to comment.