diff options
author | Benoit Daloze <[email protected]> | 2019-12-27 16:46:08 +0100 |
---|---|---|
committer | Benoit Daloze <[email protected]> | 2019-12-27 16:46:08 +0100 |
commit | a2fac1d72c225192018f8f3f3dfcfcc46f66c08a (patch) | |
tree | dc2d44079962ce242d971a4d1c2a2b1333e64cec /spec/ruby/library | |
parent | 26a9f80c823a9f536a235d80d600aa9e03ed7a2f (diff) |
Update to ruby/spec@d419e74
Diffstat (limited to 'spec/ruby/library')
-rw-r--r-- | spec/ruby/library/bigdecimal/BigDecimal_spec.rb | 6 | ||||
-rw-r--r-- | spec/ruby/library/bigdecimal/to_s_spec.rb | 1 | ||||
-rw-r--r-- | spec/ruby/library/conditionvariable/wait_spec.rb | 44 |
3 files changed, 51 insertions, 0 deletions
diff --git a/spec/ruby/library/bigdecimal/BigDecimal_spec.rb b/spec/ruby/library/bigdecimal/BigDecimal_spec.rb index 179bde1aed..0c07e46f59 100644 --- a/spec/ruby/library/bigdecimal/BigDecimal_spec.rb +++ b/spec/ruby/library/bigdecimal/BigDecimal_spec.rb @@ -46,6 +46,12 @@ describe "Kernel#BigDecimal" do BigDecimal(" \t\n \r-Infinity \n").infinite?.should == -1 end + it "coerces the value argument with #to_str" do + initial = mock("value") + initial.should_receive(:to_str).and_return("123") + BigDecimal(initial).should == BigDecimal("123") + end + ruby_version_is ""..."2.6" do it "ignores trailing garbage" do BigDecimal("123E45ruby").should == BigDecimal("123E45") diff --git a/spec/ruby/library/bigdecimal/to_s_spec.rb b/spec/ruby/library/bigdecimal/to_s_spec.rb index b6154c680d..7f741ca8b6 100644 --- a/spec/ruby/library/bigdecimal/to_s_spec.rb +++ b/spec/ruby/library/bigdecimal/to_s_spec.rb @@ -41,6 +41,7 @@ describe "BigDecimal#to_s" do str1 = '-123.45678 90123 45678 9' BigDecimal("-123.45678901234567890").to_s('5F').should == str1 + BigDecimal('1000010').to_s('5F').should == "10000 10.0" # trailing zeroes removed BigDecimal("1.00000000000").to_s('1F').should == "1.0" # 0 is treated as no spaces diff --git a/spec/ruby/library/conditionvariable/wait_spec.rb b/spec/ruby/library/conditionvariable/wait_spec.rb index f57ab4c778..59d708d7e6 100644 --- a/spec/ruby/library/conditionvariable/wait_spec.rb +++ b/spec/ruby/library/conditionvariable/wait_spec.rb @@ -32,6 +32,50 @@ describe "ConditionVariable#wait" do th.join end + it "can be interrupted by Thread#run" do + m = Mutex.new + cv = ConditionVariable.new + in_synchronize = false + + th = Thread.new do + m.synchronize do + in_synchronize = true + cv.wait(m) + end + :success + end + + # wait for m to acquire the mutex + Thread.pass until in_synchronize + # wait until th is sleeping (ie waiting) + Thread.pass while th.status and th.status != "sleep" + + th.run + th.value.should == :success + end + + it "can be interrupted by Thread#wakeup" do + m = Mutex.new + cv = ConditionVariable.new + in_synchronize = false + + th = Thread.new do + m.synchronize do + in_synchronize = true + cv.wait(m) + end + :success + end + + # wait for m to acquire the mutex + Thread.pass until in_synchronize + # wait until th is sleeping (ie waiting) + Thread.pass while th.status and th.status != "sleep" + + th.wakeup + th.value.should == :success + end + it "reacquires the lock even if the thread is killed" do m = Mutex.new cv = ConditionVariable.new |