2003-09-04 12:18:59 -04:00
|
|
|
require 'test/unit'
|
|
|
|
|
|
|
|
class TestAlias < Test::Unit::TestCase
|
|
|
|
class Alias0
|
2006-12-31 10:02:22 -05:00
|
|
|
def foo
|
|
|
|
"foo"
|
|
|
|
end
|
2003-09-04 12:18:59 -04:00
|
|
|
end
|
2006-12-31 10:02:22 -05:00
|
|
|
|
|
|
|
class Alias1 < Alias0
|
2003-09-04 12:18:59 -04:00
|
|
|
alias bar foo
|
2006-12-31 10:02:22 -05:00
|
|
|
|
|
|
|
def foo
|
|
|
|
"foo+#{super}"
|
|
|
|
end
|
2003-09-04 12:18:59 -04:00
|
|
|
end
|
2006-12-31 10:02:22 -05:00
|
|
|
|
|
|
|
class Alias2 < Alias1
|
2003-09-04 12:18:59 -04:00
|
|
|
alias baz foo
|
|
|
|
undef foo
|
|
|
|
end
|
2006-12-31 10:02:22 -05:00
|
|
|
|
|
|
|
class Alias3 < Alias2
|
2003-09-04 12:18:59 -04:00
|
|
|
def foo
|
2006-12-31 10:02:22 -05:00
|
|
|
super
|
2003-09-04 12:18:59 -04:00
|
|
|
end
|
2006-12-31 10:02:22 -05:00
|
|
|
|
2003-09-04 12:18:59 -04:00
|
|
|
def bar
|
2006-12-31 10:02:22 -05:00
|
|
|
super
|
2003-09-04 12:18:59 -04:00
|
|
|
end
|
2006-12-31 10:02:22 -05:00
|
|
|
|
2003-09-04 12:18:59 -04:00
|
|
|
def quux
|
2006-12-31 10:02:22 -05:00
|
|
|
super
|
2003-09-04 12:18:59 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_alias
|
|
|
|
x = Alias2.new
|
2006-12-31 10:02:22 -05:00
|
|
|
assert_equal "foo", x.bar
|
|
|
|
assert_equal "foo+foo", x.baz
|
|
|
|
assert_equal "foo+foo", x.baz # test_check for cache
|
2003-09-05 11:15:43 -04:00
|
|
|
|
2003-09-04 12:18:59 -04:00
|
|
|
x = Alias3.new
|
2006-12-31 10:02:22 -05:00
|
|
|
assert_raise(NoMethodError) { x.foo }
|
|
|
|
assert_equal "foo", x.bar
|
|
|
|
assert_raise(NoMethodError) { x.quux }
|
|
|
|
end
|
2009-03-05 22:56:38 -05:00
|
|
|
|
2006-12-31 10:02:22 -05:00
|
|
|
class C
|
|
|
|
def m
|
|
|
|
$SAFE
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_JVN_83768862
|
|
|
|
d = lambda {
|
|
|
|
$SAFE = 4
|
|
|
|
dclass = Class.new(C)
|
2007-11-04 15:36:20 -05:00
|
|
|
dclass.send(:alias_method, :mm, :m)
|
2006-12-31 10:02:22 -05:00
|
|
|
dclass.new
|
|
|
|
}.call
|
|
|
|
assert_raise(SecurityError) { d.mm }
|
2003-09-04 12:18:59 -04:00
|
|
|
end
|
|
|
|
end
|