mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Update to ruby/spec@6f38a82
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63293 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
b864bd05bf
commit
4fbb9aa3cb
145 changed files with 2847 additions and 2596 deletions
|
@ -0,0 +1,4 @@
|
|||
p TOPLEVEL_BINDING.local_variables.sort
|
||||
TOPLEVEL_BINDING.local_variable_set(:dynamic_set_main, 2)
|
||||
p TOPLEVEL_BINDING.local_variables.sort
|
||||
main_script = 3
|
|
@ -0,0 +1,2 @@
|
|||
TOPLEVEL_BINDING.local_variable_set(:dynamic_set_required, 1)
|
||||
p TOPLEVEL_BINDING.local_variables
|
|
@ -0,0 +1,4 @@
|
|||
a = TOPLEVEL_BINDING.object_id
|
||||
require_relative 'toplevel_binding_id_required'
|
||||
c = eval('TOPLEVEL_BINDING.object_id')
|
||||
p [a, $b, c].uniq.size
|
|
@ -0,0 +1 @@
|
|||
$b = TOPLEVEL_BINDING.object_id
|
|
@ -0,0 +1,2 @@
|
|||
required = true
|
||||
p [:required_before, TOPLEVEL_BINDING.local_variables]
|
|
@ -0,0 +1,9 @@
|
|||
p TOPLEVEL_BINDING.local_variable_get(:a)
|
||||
p TOPLEVEL_BINDING.local_variable_get(:b)
|
||||
a = 1
|
||||
p TOPLEVEL_BINDING.local_variable_get(:a)
|
||||
p TOPLEVEL_BINDING.local_variable_get(:b)
|
||||
b = 2
|
||||
a = 3
|
||||
p TOPLEVEL_BINDING.local_variable_get(:a)
|
||||
p TOPLEVEL_BINDING.local_variable_get(:b)
|
|
@ -0,0 +1,4 @@
|
|||
main_script = 1
|
||||
require_relative 'toplevel_binding_variables_required'
|
||||
eval('eval_var = 3')
|
||||
p TOPLEVEL_BINDING.local_variables
|
|
@ -0,0 +1,2 @@
|
|||
required = 2
|
||||
p [:required_after, TOPLEVEL_BINDING.local_variables]
|
34
spec/ruby/language/predefined/toplevel_binding_spec.rb
Normal file
34
spec/ruby/language/predefined/toplevel_binding_spec.rb
Normal file
|
@ -0,0 +1,34 @@
|
|||
require_relative '../../spec_helper'
|
||||
|
||||
describe "The TOPLEVEL_BINDING constant" do
|
||||
it "only includes local variables defined in the main script, not in required files or eval" do
|
||||
binding_toplevel_variables = ruby_exe(fixture(__FILE__, "toplevel_binding_variables.rb"))
|
||||
binding_toplevel_variables.should == "[:required_after, [:main_script]]\n[:main_script]\n"
|
||||
end
|
||||
|
||||
it "has no local variables in files required before the main script" do
|
||||
required = fixture(__FILE__, 'toplevel_binding_required_before.rb')
|
||||
out = ruby_exe("a=1; p TOPLEVEL_BINDING.local_variables.sort; b=2", options: "-r#{required}")
|
||||
out.should == "[:required_before, []]\n[:a, :b]\n"
|
||||
end
|
||||
|
||||
it "merges local variables of the main script with dynamically-defined Binding variables" do
|
||||
required = fixture(__FILE__, 'toplevel_binding_dynamic_required.rb')
|
||||
out = ruby_exe(fixture(__FILE__, 'toplevel_binding_dynamic.rb'), options: "-r#{required}")
|
||||
out.should == <<EOS
|
||||
[:dynamic_set_required]
|
||||
[:dynamic_set_required, :main_script]
|
||||
[:dynamic_set_main, :dynamic_set_required, :main_script]
|
||||
EOS
|
||||
end
|
||||
|
||||
it "gets updated variables values as they are defined and set" do
|
||||
out = ruby_exe(fixture(__FILE__, "toplevel_binding_values.rb"))
|
||||
out.should == "nil\nnil\n1\nnil\n3\n2\n"
|
||||
end
|
||||
|
||||
it "is always the same object for all top levels" do
|
||||
binding_toplevel_id = ruby_exe(fixture(__FILE__, "toplevel_binding_id.rb"))
|
||||
binding_toplevel_id.should == "1\n"
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue