Sha256: f12f4f7226285ef0d8a60004732ad68994cc3e5ea8bcd6b0ae32195610b0cf39

Contents?: true

Size: 1.84 KB

Versions: 13

Compression:

Stored size: 1.84 KB

Contents

require 'gir_ffi_test_helper'

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' do
    it 'creates a GSList from a Ruby array' do
      lst = GLib::SList.from :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 :gint32, [3, 2, 1]
      lst2 = GLib::SList.from :gint32, lst
      assert_equal lst, lst2
    end
  end

  describe '#==' do
    it 'returns true when comparing to an array with the same elements' do
      list = GLib::SList.from :gint32, [1, 2, 3]

      list.must_be :==, [1, 2, 3]
    end

    it 'returns false when comparing to an array with different elements' do
      list = GLib::SList.from :gint32, [1, 2, 3]

      list.wont_be :==, [1, 2]
    end

    it 'returns true when comparing to a list with the same elements' do
      list = GLib::SList.from :gint32, [1, 2, 3]
      other = GLib::SList.from :gint32, [1, 2, 3]

      list.must_be :==, other
    end

    it 'returns false when comparing to a list with different elements' do
      list = GLib::SList.from :gint32, [1, 2, 3]
      other = GLib::SList.from :gint32, [1, 2]

      list.wont_be :==, other
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
gir_ffi-0.9.2 test/ffi-glib/s_list_test.rb
gir_ffi-0.9.1 test/ffi-glib/s_list_test.rb
gir_ffi-0.9.0 test/ffi-glib/s_list_test.rb
gir_ffi-0.8.6 test/ffi-glib/s_list_test.rb
gir_ffi-0.8.5 test/ffi-glib/s_list_test.rb
gir_ffi-0.8.4 test/ffi-glib/s_list_test.rb
gir_ffi-0.8.3 test/ffi-glib/s_list_test.rb
gir_ffi-0.8.2 test/ffi-glib/s_list_test.rb
gir_ffi-0.8.1 test/ffi-glib/s_list_test.rb
gir_ffi-0.8.0 test/ffi-glib/s_list_test.rb
gir_ffi-0.7.10 test/ffi-glib/s_list_test.rb
gir_ffi-0.7.9 test/ffi-glib/s_list_test.rb
gir_ffi-0.7.8 test/ffi-glib/s_list_test.rb