зеркало из https://github.com/github/ruby.git
Add tests for variables in `END` block shared with the toplevel
This commit is contained in:
Родитель
98081ac7cc
Коммит
5a73e131d7
|
@ -12,4 +12,8 @@ describe "The END keyword" do
|
|||
it "runs multiple ends in LIFO order" do
|
||||
ruby_exe("END { puts 'foo' }; END { puts 'bar' }").should == "bar\nfoo\n"
|
||||
end
|
||||
|
||||
it "is affected by the toplevel assignment" do
|
||||
ruby_exe("foo = 'foo'; END { puts foo }").should == "foo\n"
|
||||
end
|
||||
end
|
||||
|
|
|
@ -14,6 +14,11 @@ class TestBeginEndBlock < Test::Unit::TestCase
|
|||
assert_in_out_err(["-p", "-eBEGIN{p :begin}", "-eEND{p :end}"], "foo\nbar\n", %w(:begin foo bar :end))
|
||||
end
|
||||
|
||||
def test_endblock_variable
|
||||
assert_in_out_err(["-n", "-ea = :ok", "-eEND{p a}"], "foo\n", %w(:ok))
|
||||
assert_in_out_err(["-p", "-ea = :ok", "-eEND{p a}"], "foo\n", %w(foo :ok))
|
||||
end
|
||||
|
||||
def test_begininmethod
|
||||
assert_raise_with_message(SyntaxError, /BEGIN is permitted only at toplevel/) do
|
||||
eval("def foo; BEGIN {}; end")
|
||||
|
|
Загрузка…
Ссылка в новой задаче