Skip to content

Commit b287e48

Browse files
committed
Add specs for incorrect jumps with break/next/etc
1 parent 0dc51d0 commit b287e48

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed

spec/ruby/language/break_spec.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,25 @@ def mid(&b)
252252
end
253253
end
254254

255+
describe "The break statement in a method" do
256+
it "is invalid and raises a SyntaxError" do
257+
-> {
258+
eval("def m; break; end")
259+
}.should raise_error(SyntaxError)
260+
end
261+
end
262+
263+
describe "The break statement in a module literal" do
264+
it "is invalid and raises a SyntaxError" do
265+
code = <<~RUBY
266+
module BreakSpecs:ModuleWithBreak
267+
break
268+
end
269+
RUBY
270+
271+
-> { eval(code) }.should raise_error(SyntaxError)
272+
end
273+
end
255274

256275
# TODO: Rewrite all the specs from here to the end of the file in the style
257276
# above.

spec/ruby/language/retry_spec.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,11 @@
3131
results.should == [1, 2, 3, 1, 2, 4, 5, 6, 4, 5]
3232
end
3333

34-
it "raises a SyntaxError when used outside of a begin statement" do
34+
it "raises a SyntaxError when used outside of a rescue statement" do
3535
-> { eval 'retry' }.should raise_error(SyntaxError)
36+
-> { eval 'begin; retry; end' }.should raise_error(SyntaxError)
37+
-> { eval 'def m; retry; end' }.should raise_error(SyntaxError)
38+
-> { eval 'module RetrySpecs; retry; end' }.should raise_error(SyntaxError)
3639
end
3740
end
3841

spec/ruby/language/yield_spec.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,3 +206,15 @@ class << Object.new
206206
-> { eval(code) }.should raise_error(SyntaxError, /Invalid yield/)
207207
end
208208
end
209+
210+
describe "Using yield in a module literal" do
211+
it 'raises a SyntaxError' do
212+
code = <<~RUBY
213+
module YieldSpecs::ModuleWithYield
214+
yield
215+
end
216+
RUBY
217+
218+
-> { eval(code) }.should raise_error(SyntaxError, /Invalid yield/)
219+
end
220+
end

0 commit comments

Comments
 (0)