File: test_method.rb

package info (click to toggle)
jruby 1.5.1-1
  • links: PTS, VCS
  • area: non-free
  • in suites: squeeze
  • size: 46,252 kB
  • ctags: 72,039
  • sloc: ruby: 398,155; java: 169,482; yacc: 3,782; xml: 2,469; ansic: 415; sh: 279; makefile: 78; tcl: 40
file content (46 lines) | stat: -rw-r--r-- 928 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
require 'test/unit'


class TestMethod < Test::Unit::TestCase

  def setup
    @m1 = 12.method("+")
  end

  def test_AREF # '[]'
    assert_equal(15, @m1[3])
    assert_equal(9,  @m1[-3])
  end

  def dummy1(a, b=0, c=1)
  end

  def test_arity
    assert_equal(1, @m1.arity)
    assert_equal(0, self.method("test_arity").arity)
    assert_equal(-2, self.method("dummy1").arity)
    assert_equal(-1, @m1.method("call").arity)
    assert_equal(-1, @m1.method("respond_to?").arity)
  end

  def test_call
    assert_equal(15, @m1.call(3))
    assert_equal(9,  @m1.call(-3))
  end

  def test_to_proc
    p = @m1.to_proc
    assert_instance_of(Proc, p)
    assert_equal(15, p.call(3))
  end
  
  def optarg_assigns_variable(a, b=(c=1; 0))
    [a, b, c]
  end
  
  def test_optarg_that_assigns_variable
    assert_equal([2, 0, 1], optarg_assigns_variable(2))
    assert_equal([2, 1, nil], optarg_assigns_variable(2, 1))
  end

end