File: test_method.rb

package info (click to toggle)
jruby 1.7.26-1%2Bdeb9u1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 84,572 kB
  • sloc: ruby: 669,910; java: 253,056; xml: 35,152; ansic: 9,187; yacc: 7,267; cpp: 5,244; sh: 1,036; makefile: 345; jsp: 48; 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