Sha256: 455f5b25817f3230b8c025fbcdd9aa9589fefd6061c82cf18b53d36e30cd7227

Contents?: true

Size: 1.15 KB

Versions: 4

Compression:

Stored size: 1.15 KB

Contents

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

describe GLib::SList do
  it "knows its element type" do
    arr = GLib::SList.new :gint32
    assert_equal :gint32, arr.element_type
  end

  describe "#prepend" do
    it "prepends integer values" do
      lst = GLib::SList.new :gint32
      res = lst.prepend 1
      assert_equal 1, res.data
    end

    it "prepends string values" do
      lst = GLib::SList.new :utf8
      res = lst.prepend "bla"
      assert_equal "bla", res.data
    end

    it "prepends multiple values into a single list" do
      lst = GLib::SList.new :gint32

      res = lst.prepend 1
      res2 = res.prepend 2

      assert_equal 2, res2.data
      assert_equal 1, res.data
      assert_equal res.to_ptr, res2.next.to_ptr
    end
  end

  describe "::from_array" do
    it "creates a GSList from a Ruby array" do
      lst = GLib::SList.from_array :gint32, [3, 2, 1]
      assert_equal [3, 2, 1], lst.to_a
    end

    it "return its argument if given a GSList" do
      lst = GLib::SList.from_array :gint32, [3, 2, 1]
      lst2 = GLib::SList.from_array :gint32, lst
      assert_equal lst, lst2
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
gir_ffi-0.2.3 test/ffi-glib/s_list_test.rb
gir_ffi-0.2.2 test/ffi-glib/s_list_test.rb
gir_ffi-0.2.1 test/ffi-glib/s_list_test.rb
gir_ffi-0.2.0 test/ffi-glib/s_list_test.rb