Sha256: fe396af1d0d76ac636dd3e925ed2df439d6a0e03db828a1728fc1c8bfed46cb6

Contents?: true

Size: 949 Bytes

Versions: 2

Compression:

Stored size: 949 Bytes

Contents

require 'helper'

class Dummy
  def one_arg(foo); end
  def multiple_args(foo, bar, baz); end
  def optional_args(foo, bar = 1, baz = nil); end
  def star_args(*foo); end
end

class TestArgumentList < Test::Unit::TestCase
  def test_one_arg
    list = Dummy.instance_method(:one_arg).get_argument_list
    assert_equal 1, list.length
    assert_equal :foo, list.first.name
    assert !list.first.optional?
  end
  
  def test_multiple_args
    list = Dummy.instance_method(:multiple_args).get_argument_list
    assert_equal 3, list.length
  end
  
  def test_optional_args
    list = Dummy.instance_method(:optional_args).get_argument_list

    assert !list[0].optional?
    assert list[1].optional?
    assert_equal 1, list[1].default
    assert list[2].optional?
    assert_equal nil, list[2].default    
  end
  
  def test_star_args
    list = Dummy.instance_method(:star_args).get_argument_list
    
    assert list.first.multiple?
  end
  
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
get_args-1.1.1 test/test_argument_list.rb
get_args-1.1.0 test/test_argument_list.rb