summaryrefslogtreecommitdiff
path: root/test/ruby
diff options
context:
space:
mode:
authornahi <nahi@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-10-05 04:51:05 +0000
committernahi <nahi@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-10-05 04:51:05 +0000
commitd50d6d396ae47d78a9d8d07a754868f35492d7fc (patch)
tree0413a0edd9c375c5c962f846d8c7cabef3082141 /test/ruby
parentd77b17aa73110c289c354316bb9c600f53bb3684 (diff)
downloadruby-d50d6d396ae47d78a9d8d07a754868f35492d7fc.tar.gz
* test/ruby/test_beginendblock.rb, test/ruby/beginmainend.rb: add tests about
scope, order and allowd syntax. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@4692 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/ruby')
-rw-r--r--test/ruby/beginmainend.rb32
-rw-r--r--test/ruby/test_beginendblock.rb14
2 files changed, 43 insertions, 3 deletions
diff --git a/test/ruby/beginmainend.rb b/test/ruby/beginmainend.rb
index 4ee1d7899a..f89c09207e 100644
--- a/test/ruby/beginmainend.rb
+++ b/test/ruby/beginmainend.rb
@@ -1,9 +1,37 @@
BEGIN {
- puts "begin"
+ puts "begin1"
+ local_begin1 = "local_begin1"
+ $global_begin1 = "global_begin1"
+ ConstBegin1 = "ConstBegin1"
}
+BEGIN {
+ puts "begin2"
+}
+
+# for scope check
+raise if defined?(local_begin1)
+raise unless defined?($global_begin1)
+raise unless defined?(::ConstBegin1)
+local_for_end2 = "end2"
+$global_for_end1 = "end1"
+
puts "main"
END {
- puts "end"
+ puts local_for_end2
+}
+
+END {
+ raise
+ puts "should not be dumped"
+}
+
+END {
+ exit
+ puts "should not be dumped"
+}
+
+END {
+ puts $global_for_end1
}
diff --git a/test/ruby/test_beginendblock.rb b/test/ruby/test_beginendblock.rb
index 301d2c62f5..06b1519189 100644
--- a/test/ruby/test_beginendblock.rb
+++ b/test/ruby/test_beginendblock.rb
@@ -7,6 +7,18 @@ class TestBeginEndBlock < Test::Unit::TestCase
def test_beginendblock
ruby = EnvUtil.rubybin
io = IO.popen("\"#{ruby}\" \"#{DIR}/beginmainend.rb\"")
- assert_equal("begin\nmain\nend\n", io.read)
+ assert_equal(%w(begin1 begin2 main end1 end2).join("\n") << "\n", io.read)
+ end
+
+ def test_begininmethod
+ assert_raises(SyntaxError) do
+ eval("def foo; BEGIN {}; end")
+ end
+ end
+
+ def test_endinmethod
+ assert_raises(SyntaxError) do
+ eval("def foo; END {}; end")
+ end
end
end