File: test_eval.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 (51 lines) | stat: -rw-r--r-- 1,344 bytes parent folder | download | duplicates (9)
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
47
48
49
50
51
require 'test/unit'

class TestEval < Test::Unit::TestCase
  class ToStr; def to_str; ''; end; end
  class ToInt; def to_int; 1; end; end

  def test_args_coersion
    assert_raises(TypeError) { eval :foo }
    assert_raises(TypeError) { eval 1 }
    assert_nothing_raised { eval "" }
    assert_nothing_raised { eval ToStr.new }
    assert_raises(TypeError) { eval "", :foo }
    assert_raises(TypeError) { eval "", 1 }
    assert_nothing_raised { eval "", binding }
    assert_nothing_raised { eval "", proc{} }
    assert_raises(TypeError) { eval "", binding, :foo }
    assert_raises(TypeError) { eval "", binding, 1 }
    assert_nothing_raised { eval "", binding, 'foo' }
    assert_nothing_raised { eval "", binding, ToStr.new }
    assert_raises(TypeError) { eval "", binding, 'foo', 'foo' }
    assert_nothing_raised { eval "", binding, 'foo', 1 }
    assert_nothing_raised { eval "", binding, 'foo', :foo }
    assert_nothing_raised { eval "", binding, 'foo', ToInt.new }
  end

  module Mod
    def m1; @result << "M1"; end
  end
  
  CHANGE='
  alias_method :m1_orig, :m1
  
  def m1
   m1_orig
   @result << "M2"
  end
  '
  
  class Test
    include Mod  
    eval CHANGE

    def initialize; @result = []; end
    def t1; m1; end
  end

  def test_eval_alias_method
    o = Test.new
    assert_equal(["M1", "M2"], o.t1)
  end
end