Skip to content

Commit eb5d598

Browse files
committed
Add failing spec for flip-flop operator with Integer literals
1 parent 2c7fdb7 commit eb5d598

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

spec/ruby/language/if_spec.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,15 @@
305305
6.times(&b)
306306
ScratchPad.recorded.should == [4, 5, 4, 5]
307307
end
308+
309+
it "warns when Integer literals are used instead of predicates" do
310+
-> {
311+
eval <<~RUBY
312+
10.times { |i| ScratchPad << i if 4..5 }
313+
RUBY
314+
}.should complain(/warning: integer literal in flip-flop/, verbose: true)
315+
ScratchPad.recorded.should == []
316+
end
308317
end
309318

310319
describe "when a branch syntactically does not return a value" do

spec/tags/language/if_tags.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
fails:The if expression with a boolean range ('flip-flop' operator) warns when Integer literals are used instead of predicates

0 commit comments

Comments
 (0)