blob: fc62d93ae6d2b8258eccc4dc3e6b0a9c52e31fd9 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
require 'test/unit'
require_relative 'envutil'
class TestFlip < Test::Unit::TestCase
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
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
|