2012-06-16 12:31:08 -05:00
|
|
|
require 'spec_helper'
|
2012-06-17 02:42:23 -05:00
|
|
|
require 'bigdecimal'
|
2012-06-16 12:31:08 -05:00
|
|
|
describe V8::Conversion do
|
2012-07-25 14:27:54 +07:00
|
|
|
|
|
|
|
let(:cxt) { V8::Context.new }
|
|
|
|
|
2012-06-16 12:31:08 -05:00
|
|
|
it "can embed BigDecimal values" do
|
|
|
|
cxt['big'] = BigDecimal.new('1.1')
|
|
|
|
cxt['big'].should eql BigDecimal.new('1.1')
|
|
|
|
end
|
2012-07-24 23:25:04 +03:00
|
|
|
|
|
|
|
it "doesn't try to use V8::Conversion::Class::* as root objects" do
|
|
|
|
klass = Class.new do
|
|
|
|
class << self
|
|
|
|
def test
|
|
|
|
Set.new
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
klass.test.should be_instance_of(::Set)
|
|
|
|
end
|
2012-07-25 14:27:54 +07:00
|
|
|
|
|
|
|
context "::Fixnum" do
|
|
|
|
context "for 32-bit numbers" do
|
|
|
|
it "should convert positive integer" do
|
|
|
|
cxt['fixnum_a'] = 123
|
|
|
|
cxt['fixnum_a'].should == 123
|
|
|
|
cxt['fixnum_a'].should be_instance_of(Fixnum)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should convert negative integer" do
|
|
|
|
cxt['fixnum_b'] = -123
|
|
|
|
cxt['fixnum_b'].should == -123
|
|
|
|
cxt['fixnum_b'].should be_instance_of(Fixnum)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "for 64-bit numbers" do
|
|
|
|
it "should convert positive integer" do
|
|
|
|
cxt['fixnum_c'] = 0x100000000
|
|
|
|
cxt['fixnum_c'].should == 0x100000000
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should convert negative integer" do
|
|
|
|
cxt['fixnum_d'] = -0x100000000
|
|
|
|
cxt['fixnum_d'].should == -0x100000000
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
2012-06-16 12:31:08 -05:00
|
|
|
end
|