Sha256: 0a318ff5e35ee859f2b1f8e887b77d06db2a2051a18edb5011c9386e3347c071

Contents?: true

Size: 1.11 KB

Versions: 4

Compression:

Stored size: 1.11 KB

Contents

require File.expand_path('../gir_ffi_test_helper.rb', File.dirname(__FILE__))

describe GLib::HashTable do
  it "knows its key and value types" do
    hsh = GLib::HashTable.new :gint32, :utf8
    assert_equal :gint32, hsh.key_type
    assert_equal :utf8, hsh.value_type
  end

  describe "::from" do
    it "creates a GHashTable from a Ruby array" do
      hsh = GLib::HashTable.from [:utf8, :gint32],
        {"foo" => 23, "bar" => 32}
      assert_equal({"foo" => 23, "bar" => 32}, hsh.to_hash)
    end

    it "return its argument if given a GHashTable" do
      hsh = GLib::HashTable.from [:utf8, :gint32], {"foo" => 23, "bar" => 32}
      hsh2 = GLib::HashTable.from [:utf8, :gint32], hsh
      assert_equal hsh, hsh2
    end

    it "wraps its argument if given a pointer" do
      hsh = GLib::HashTable.from [:utf8, :gint32], {"foo" => 23, "bar" => 32}
      pointer = hsh.to_ptr
      assert_instance_of FFI::Pointer, pointer
      hsh2 = GLib::HashTable.from [:utf8, :gint32], pointer
      assert_instance_of GLib::HashTable, hsh2
      refute_equal hsh, hsh2
      assert_equal hsh.to_hash, hsh2.to_hash
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
gir_ffi-0.4.0 test/ffi-glib/hash_table_test.rb
gir_ffi-0.3.2 test/ffi-glib/hash_table_test.rb
gir_ffi-0.3.1 test/ffi-glib/hash_table_test.rb
gir_ffi-0.3.0 test/ffi-glib/hash_table_test.rb