1
0
Fork 0
mirror of https://github.com/rubyjs/therubyracer synced 2023-03-27 23:21:42 -04:00

Add tests for V8::C::Value

This commit is contained in:
Georgy Angelov 2015-03-21 10:54:39 +00:00
parent d0f568cf18
commit 143bbb1232
2 changed files with 48 additions and 0 deletions

View file

@ -3,6 +3,10 @@ require 'c_spec_helper'
describe V8::C::String do
requires_v8_context
it 'is a primitive' do
expect(V8::C::String.NewFromUtf8('test')).to be_a V8::C::Primitive
end
it 'can create new strings' do
expect(V8::C::String.NewFromUtf8('test')).to be
end

44
spec/c/value_spec.rb Normal file
View file

@ -0,0 +1,44 @@
require 'c_spec_helper'
describe V8::C::Value do
requires_v8_context
def to_value(value)
object = V8::C::Object.New
key = V8::C::String.NewFromUtf8('key')
object.Set(key, value)
object.Get(key)
end
it 'converts strings' do
expect(to_value(V8::C::String.NewFromUtf8('value')).Utf8Value).to eq 'value'
end
it 'converts nil' do
expect(to_value(nil)).to eq nil
end
it 'converts undefined to nil' do
object = V8::C::Object.New
key = V8::C::String.NewFromUtf8('key')
expect(object.Get(key)).to eq nil
end
it 'converts FixNums' do
expect(to_value(42)).to eq 42
end
it 'converts booleans' do
expect(to_value(true)).to eq true
expect(to_value(false)).to eq false
end
it 'converts objects' do
object = V8::C::Object.New
object.Set(V8::C::String.NewFromUtf8('test'), 1)
expect(to_value(object)).to eq object
end
end