Sha256: 7bbaca6aae17b018929f02ae5cf7272754f5078e219fd387384aefcfe2ae4d14

Contents?: true

Size: 1.53 KB

Versions: 2

Compression:

Stored size: 1.53 KB

Contents

require 'helper'
require 'dub/lua'

class FunctionGroupTest < Test::Unit::TestCase

  context 'A FunctionGroup' do
    should 'keep its members sorted by overloaded_index' do
      @group = namespacecv_xml[:cv][:divide]
      assert_equal [1, 2, 3, 4], @group.map {|f| f.overloaded_index}
      
      assert_match %r{lua_type\(L, 1\)}, Dub::Lua.function_generator.chooser_body(@group)
    end

    should 'start getting type on first argument' do
      @group = namespacecv_xml[:cv][:divide]
      assert_match %r{lua_type\(L, 1\)}, Dub::Lua.function_generator.chooser_body(@group)
    end
    
    should 'not use top__ in chooser if all methods have same arg count' do
      @method = namespacecv_xml[:cv][:Mat][:diag]
      Dub::Lua.bind(@method)
      assert_no_match %r{top__}, Dub::Lua.function_generator.chooser_body(@method)
    end

    should 'use top__ in chooser if some methods have different arg count' do
      @method = namespacecv_xml[:cv][:Mat][:Mat]
      Dub::Lua.bind(@method)
      assert_match %r{top__}, Dub::Lua.function_generator.chooser_body(@method)
    end
    
    context 'from overloaded members' do
      subject do
        namespacedub_xml[:dub][:Matrix][:do_something]
      end

      should 'start getting type on second argument' do
        # Function selector should not be fooled by the first arg == self
        assert_no_match %r{lua_type\(L, 1\)}, Dub::Lua.function_generator.chooser_body(subject)
        assert_match %r{lua_type\(L, 2\)}, Dub::Lua.function_generator.chooser_body(subject)
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
dub-1.0.0 test/function_group_test.rb
dub-0.7.0 test/function_group_test.rb