Skip to content

Commit

Permalink
[test] fixnum/float ops (JRuby specific) tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kares committed Oct 26, 2019
1 parent ed86ea3 commit 1399961
Show file tree
Hide file tree
Showing 2 changed files with 110 additions and 0 deletions.
56 changes: 56 additions & 0 deletions test/jruby/test_fixnum.rb
@@ -0,0 +1,56 @@
require 'test/unit'

class TestGH5939 < Test::Unit::TestCase

class Primitive

def _value
@__value ||= 0
end

def +(other)
_value + other
end

def ==(other)
other == _value
end

end

class Klass; end

def test_op_indy_regression
threads = []
30.times do
threads << Thread.start do
begin
i = Klass.new

def i.version; Primitive.new end

assert_equal 10, plus_10(i.version)
assert_false i.version == 5
assert_true 0 == i.version

true
rescue java.lang.Exception => ex
warn("#{__method__} FAILED WITH: #{ex}")
raise ex
end
end
end

threads.each &:join
threads.each do |thread|
assert thread.value # should not raise (if thread raised an exception)
end

end

def plus_10(version)
version + 10
end
private :plus_10

end
54 changes: 54 additions & 0 deletions test/jruby/test_float.rb
@@ -0,0 +1,54 @@
require 'test/unit'

class TestGH5939 < Test::Unit::TestCase

class Primitive

def _value
@__value ||= 0.0
end

def +(other)
_value + other
end

def ==(other)
other == _value
end

def to_f
_value.to_f
end

end

def test_op_indy_regression
threads = []
30.times do
threads << Thread.start do
begin
i = Object.new

def i.version; @version ||= Primitive.new end

assert_equal 11.0, i.version + 11.0

assert_false i.version == 5.0
assert_true 0.0 == i.version

true
rescue java.lang.Exception => ex
warn("#{__method__} FAILED WITH: #{ex}")
raise ex
end
end
end

threads.each &:join
threads.each do |thread|
assert thread.value # should not raise (if thread raised an exception)
end

end

end

0 comments on commit 1399961

Please sign in to comment.