mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
af1b9db40b
* compile.c (iseq_compile_each): turn flip-flop in a not-operator into a boolean value. fix up r56315 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56521 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
53 lines
1.5 KiB
Ruby
53 lines
1.5 KiB
Ruby
# frozen_string_literal: false
|
|
require 'test/unit'
|
|
|
|
class TestFlip < Test::Unit::TestCase
|
|
def test_flip_flop
|
|
assert_equal [4,5], (1..9).select {|n| true if (n==4)..(n==5)}
|
|
assert_equal [4,5], (1..9).select {|n| true if (n==4)...(n==5)}
|
|
assert_equal [2], (1..9).select {|n| true if (n==2)..(n%2).zero?}
|
|
assert_equal [2,3,4], (1..9).select {|n| true if (n==2)...(n%2).zero?}
|
|
assert_equal [4,5,7,8], (1..9).select {|n| true if (n==4)...(n==5) or (n==7)...(n==8)}
|
|
assert_equal [nil, 2, 3, 4, nil], (1..5).map {|x| x if (x==2..x==4)}
|
|
assert_equal [1, nil, nil, nil, 5], (1..5).map {|x| x if !(x==2..x==4)}
|
|
end
|
|
|
|
def test_hidden_key
|
|
bug6899 = '[ruby-core:47253]'
|
|
foo = "foor"
|
|
bar = "bar"
|
|
assert_nothing_raised(NotImplementedError, bug6899) do
|
|
2000.times {eval %[(foo..bar) ? 1 : 2]}
|
|
end
|
|
foo = bar
|
|
end
|
|
|
|
def test_shared_eval
|
|
bug7671 = '[ruby-core:51296]'
|
|
vs = (1..9).to_a
|
|
vs.select {|n| if n==2..n==16 then 1 end}
|
|
v = eval("vs.select {|n| if n==3..n==6 then 1 end}")
|
|
assert_equal([*3..6], v, bug7671)
|
|
end
|
|
|
|
def test_shared_thread
|
|
ff = proc {|n| true if n==3..n==5}
|
|
v = 1..9
|
|
a = true
|
|
th = Thread.new {
|
|
v.select {|i|
|
|
Thread.pass while a
|
|
ff[i].tap {a = true}
|
|
}
|
|
}
|
|
v1 = v.select {|i|
|
|
Thread.pass until a
|
|
ff[i].tap {a = false}
|
|
}
|
|
v2 = th.value
|
|
expected = [3, 4, 5]
|
|
mesg = 'flip-flop should be separated per threads'
|
|
assert_equal(expected, v1, mesg)
|
|
assert_equal(expected, v2, mesg)
|
|
end
|
|
end
|