|
@@ -337,6 +337,34 @@ def self.extended(base) |
|
|
""") |
|
|
assert self.unwrap(space, w_res) == "extended in: A" |
|
|
|
|
|
def test_method(self, space): |
|
|
w_res = space.execute(""" |
|
|
class A; def a; end; end |
|
|
return A.new.method(:a).class, A.new.method(:to_s).class |
|
|
""") |
|
|
assert self.unwrap(space, w_res) == [ |
|
|
space.getclassfor(W_MethodObject), |
|
|
space.getclassfor(W_MethodObject) |
|
|
] |
|
|
with self.raises(space, "NameError"): |
|
|
space.execute("Object.new.method(:undefined_stuff)") |
|
|
w_res = space.execute(""" |
|
|
class A; def to_str; "to_s"; end; end |
|
|
return 'aaa'.method(A.new).class |
|
|
""") |
|
|
assert self.unwrap(space, w_res) == space.getclassfor(W_MethodObject) |
|
|
|
|
|
def test_tap(self, space): |
|
|
with self.raises(space, "LocalJumpError"): |
|
|
space.execute("1.tap") |
|
|
|
|
|
w_res = space.execute(""" |
|
|
x = nil |
|
|
res = 1.tap { |c| x = c + 1 } |
|
|
return res, x |
|
|
""") |
|
|
assert self.unwrap(space, w_res) == [1, 2] |
|
|
|
|
|
|
|
|
class TestMapDict(BaseTopazTest): |
|
|
def test_simple_attr(self, space): |
|
@@ -355,7 +383,7 @@ def attrs |
|
|
""") |
|
|
assert self.unwrap(space, w_res) == [3, 4, 5] |
|
|
|
|
|
def test_unitialized_att(self, space): |
|
|
def test_unitialized_attr(self, space): |
|
|
w_res = space.execute(""" |
|
|
class X |
|
|
attr_accessor :a |
|
@@ -367,30 +395,16 @@ def attrs |
|
|
""") |
|
|
assert space.listview(w_res) == [space.w_nil, space.w_nil] |
|
|
|
|
|
def test_method(self, space): |
|
|
w_res = space.execute(""" |
|
|
class A; def a; end; end |
|
|
return A.new.method(:a).class, A.new.method(:to_s).class |
|
|
""") |
|
|
assert self.unwrap(space, w_res) == [ |
|
|
space.getclassfor(W_MethodObject), |
|
|
space.getclassfor(W_MethodObject) |
|
|
] |
|
|
with self.raises(space, "NameError"): |
|
|
space.execute("Object.new.method(:undefined_stuff)") |
|
|
w_res = space.execute(""" |
|
|
class A; def to_str; "to_s"; end; end |
|
|
return 'aaa'.method(A.new).class |
|
|
""") |
|
|
assert self.unwrap(space, w_res) == space.getclassfor(W_MethodObject) |
|
|
|
|
|
def test_tap(self, space): |
|
|
with self.raises(space, "LocalJumpError"): |
|
|
space.execute("1.tap") |
|
|
|
|
|
def test_change_attr_type(self, space): |
|
|
w_res = space.execute(""" |
|
|
x = nil |
|
|
res = 1.tap { |c| x = c + 1 } |
|
|
return res, x |
|
|
class X |
|
|
attr_accessor :a, :b |
|
|
end |
|
|
x = X.new |
|
|
x.a = 3.2 |
|
|
x.b = 5 |
|
|
x.a = "abc" |
|
|
x.b = 3.8 |
|
|
return [x.a, x.b] |
|
|
""") |
|
|
assert self.unwrap(space, w_res) == [1, 2] |
|
|
assert self.unwrap(space, w_res) == ["abc", 3.8] |