summaryrefslogtreecommitdiff
path: root/bootstraptest/test_syntax.rb
diff options
context:
space:
mode:
authorko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-08-16 13:12:24 +0000
committerko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-08-16 13:12:24 +0000
commit571f22f5fe3fd3e265512c0e9ee4720482443301 (patch)
treede246e154a39f173491d53dfed39b4ffe2615e18 /bootstraptest/test_syntax.rb
parent48442d46b39976ec9a3a17e357fd3be13cd8feaf (diff)
* compile.c (iseq_compile_each): fix next/redo stack consistency.
[ruby-dev:31373] * bootstraptest/test_syntax.rb: add tests for above. * sample/test.rb: fix to use __FILE__ instead of $0 to know basedir. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@13068 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'bootstraptest/test_syntax.rb')
-rw-r--r--bootstraptest/test_syntax.rb93
1 files changed, 78 insertions, 15 deletions
diff --git a/bootstraptest/test_syntax.rb b/bootstraptest/test_syntax.rb
index 1b6d0c8..9541d67 100644
--- a/bootstraptest/test_syntax.rb
+++ b/bootstraptest/test_syntax.rb
@@ -523,25 +523,88 @@ assert_equal %q{1}, %q{
end until true
i
}
-def assert_syntax_error expected, code
+def assert_syntax_error expected, code, message = ''
assert_equal "#{expected}",
- "begin eval(%q{#{code}}, nil, '', 0)"'; rescue SyntaxError => e; e.message[/\A:(?:\d+:)? (.*)/, 1] end'
+ "begin eval(%q{#{code}}, nil, '', 0)"'; rescue SyntaxError => e; e.message[/\A:(?:\d+:)? (.*)/, 1] end', message
end
-assert_syntax_error "unterminated string meets end of file", '().."' # [ruby-dev:29732]
-assert_equal %q{[]}, %q{$&;[]} # [ruby-dev:31068]
-assert_syntax_error "syntax error, unexpected tSTAR, expecting '}'", %q{{*0}} # [ruby-dev:31072]
-assert_syntax_error "empty symbol literal", %q{0..:""} # [ruby-dev:31085]
-assert_syntax_error "`@0' is not allowed as an instance variable name", %q{@0..0} # [ruby-dev:31095]
-assert_syntax_error "identifier $00 is not valid to get", %q{$00..0} # [ruby-dev:31100]
+assert_syntax_error "unterminated string meets end of file", '().."', '[ruby-dev:29732]'
+assert_equal %q{[]}, %q{$&;[]}, '[ruby-dev:31068]'
+assert_syntax_error "syntax error, unexpected tSTAR, expecting '}'", %q{{*0}}, '[ruby-dev:31072]'
+assert_syntax_error "empty symbol literal", %q{0..:""}, '[ruby-dev:31085]'
+assert_syntax_error "`@0' is not allowed as an instance variable name", %q{@0..0}, '[ruby-dev:31095]'
+assert_syntax_error "identifier $00 is not valid to get", %q{$00..0}, '[ruby-dev:31100]'
assert_syntax_error "identifier $00 is not valid to set", %q{0..$00=1}
-assert_equal %q{0}, %q{[*0];0} # [ruby-dev:31102]
-assert_syntax_error "syntax error, unexpected ')'", %q{v0,(*,v1,) = 0} # [ruby-dev:31104]
-assert_equal %q{1}, %q{class << (ary=[]); def []; 0; end; def []=(x); super(0,x);end;end; ary[]+=1} # [ruby-dev:31110]
-assert_syntax_error "Can't set variable $1", %q{0..$1=1} # [ruby-dev:31118]
-assert_syntax_error "void value expression", %q{1.times{1+(1&&next)}} # [ruby-dev:31119]
-assert_syntax_error "void value expression", %q{x=-1;loop{x+=1&&redo if (x+=1).zero?}} # [ruby-dev:31119]
-assert_syntax_error %q{syntax error, unexpected $end}, %q{!} # [ruby-dev:31243]
+assert_equal %q{0}, %q{[*0];0}, '[ruby-dev:31102]'
+assert_syntax_error "syntax error, unexpected ')'", %q{v0,(*,v1,) = 0}, '[ruby-dev:31104]'
+assert_equal %q{1}, %q{
+ class << (ary=[]); def []; 0; end; def []=(x); super(0,x);end;end; ary[]+=1
+}, '[ruby-dev:31110]'
+assert_syntax_error "Can't set variable $1", %q{0..$1=1}, '[ruby-dev:31118]'
+assert_syntax_error "void value expression", %q{1.times{1+(1&&next)}}, '[ruby-dev:31119]'
+assert_syntax_error "void value expression", %q{x=-1;loop{x+=1&&redo if (x+=1).zero?}}, '[ruby-dev:31119]'
+assert_syntax_error %q{syntax error, unexpected $end}, %q{!}, '[ruby-dev:31243]'
assert_equal %q{[nil]}, %q{[()]}, '[ruby-dev:31252]'
assert_equal %q{true}, %q{!_=()}, '[ruby-dev:31263]'
assert_equal 'ok', %q{while true; redo; end if 1 == 2; :ok}, '[ruby-dev:31360]'
+assert_equal 'ok', %q{
+ 1.times {
+ begin
+ ensure
+ next
+ end
+ }; :ok
+}, '[ruby-dev:31373]'
+assert_equal 'ok', %q{
+ flag = false
+ 1.times {
+ next if flag
+ flag = true
+ begin
+ ensure
+ redo
+ end
+ }; :ok
+}, '[ruby-dev:31373]'
+assert_equal 'ok', %q{
+ 1.times{
+ p(1, (next; 2))
+ }; :ok
+}
+assert_equal '3', %q{
+ i = 0
+ 1 + (while true
+ break 2 if (i+=1) > 1
+ next
+ end)
+}
+assert_equal '3', %q{
+ i = 0
+ 1 + (while true
+ break 2 if (i+=1) > 1
+ p(1, (next; 2))
+ end)
+}
+# redo
+assert_equal 'ok', %q{
+ i = 0
+ 1.times{
+ break if i>1
+ i+=1
+ p(1, (redo; 2))
+ }; :ok
+}
+assert_equal '3', %q{
+ i = 0
+ 1 + (while true
+ break 2 if (i+=1) > 1
+ redo
+ end)
+}
+assert_equal '3', %q{
+ i = 0
+ 1 + (while true
+ break 2 if (i+=1) > 1
+ p(1, (redo; 2))
+ end)
+}