Add tests for variables in END
block shared with the toplevel
This commit is contained in:
parent
98081ac7cc
commit
5a73e131d7
Notes:
git
2023-01-24 07:36:59 +00:00
@ -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")
|
||||
|
Loading…
x
Reference in New Issue
Block a user