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:
parent
d0f568cf18
commit
143bbb1232
2 changed files with 48 additions and 0 deletions
|
@ -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
44
spec/c/value_spec.rb
Normal 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
|
Loading…
Add table
Reference in a new issue