Sha256: 4d268ffee4c9971ef90a30483f50464b857880a836da187c5de7c0be1894850b

Contents?: true

Size: 971 Bytes

Versions: 8

Compression:

Stored size: 971 Bytes

Contents

# frozen_string_literal: true
require 'gir_ffi_test_helper'

describe GirFFI::ObjectStore do
  let(:store) { GirFFI::ObjectStore.new }

  describe '#store' do
    it 'returns a non-null pointer when storing objects' do
      obj = Object.new
      ptr = store.store obj
      ptr.wont_be :null?
    end

    it 'returns a null pointer when storing nil' do
      ptr = store.store nil
      ptr.must_be :null?
    end
  end

  describe '#fetch' do
    it 'returns the stored object when passed the key pointer' do
      obj = Object.new
      ptr = store.store obj
      result = store.fetch ptr
      result.must_equal obj
    end

    it 'returns the nil object when passed a null pointer' do
      ptr = FFI::Pointer.new(0)
      result = store.fetch ptr
      result.must_be_nil
    end

    it 'returns the pointer itself when passed an unknown pointer' do
      ptr = FFI::Pointer.new(42)
      result = store.fetch ptr
      result.must_equal ptr
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
gir_ffi-0.11.1 test/gir_ffi/object_store_test.rb
gir_ffi-0.11.0 test/gir_ffi/object_store_test.rb
gir_ffi-0.10.2 test/gir_ffi/object_store_test.rb
gir_ffi-0.10.1 test/gir_ffi/object_store_test.rb
gir_ffi-0.10.0 test/gir_ffi/object_store_test.rb
gir_ffi-0.10.0.pre1 test/gir_ffi/object_store_test.rb
gir_ffi-0.9.5 test/gir_ffi/object_store_test.rb
gir_ffi-0.9.4 test/gir_ffi/object_store_test.rb