test collector for ivar assignment
This commit is contained in:
parent
aa5f48e3c6
commit
aa6685a0cb
@ -12,10 +12,18 @@ module Melon
|
||||
end
|
||||
|
||||
def on_ivar(statement)
|
||||
add_ivar(statement)
|
||||
end
|
||||
|
||||
def on_ivasgn( statement )
|
||||
add_ivar(statement)
|
||||
end
|
||||
|
||||
def add_ivar(statement)
|
||||
var = statement.children[0].to_s[1..-1].to_sym
|
||||
@ivars[var] = :Object #guess, can maybe guess better
|
||||
end
|
||||
|
||||
|
||||
def handler_missing(node)
|
||||
node.children.each do |kid |
|
||||
process(kid) if kid.is_a?(AST::Node)
|
||||
|
@ -1 +1,2 @@
|
||||
require_relative "test_class"
|
||||
require_relative "test_collector"
|
||||
|
@ -14,16 +14,10 @@ module Melon
|
||||
end
|
||||
|
||||
def test_creates_class_with_deriviation
|
||||
Compiler.compile "class Test2 < List ;end"
|
||||
Compiler.compile "class Test2 < List ;end"
|
||||
assert t = Parfait::Space.object_space.get_class_by_name(:Test2) , "No classes created"
|
||||
assert_equal :List , t.super_class_name
|
||||
end
|
||||
|
||||
def test_picks_up_an_ivar_name
|
||||
Compiler.compile "class TestIvar < Object ; def meth; return @ivar;end; end"
|
||||
itest = Parfait::Space.object_space.get_class_by_name(:TestIvar)
|
||||
assert itest.instance_type.instance_names.include?(:ivar) , itest.instance_type.instance_names.inspect
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
29
test/melon/compiler/test_clollector.rb
Normal file
29
test/melon/compiler/test_clollector.rb
Normal file
@ -0,0 +1,29 @@
|
||||
require_relative "helper"
|
||||
|
||||
module Melon
|
||||
class TestCollector < MiniTest::Test
|
||||
|
||||
def setup
|
||||
Register.machine.boot unless Register.machine.booted
|
||||
end
|
||||
|
||||
def test_ivar_name
|
||||
Compiler.compile "class TestIvar < Object ; def meth; @ivar;end; end"
|
||||
itest = Parfait::Space.object_space.get_class_by_name(:TestIvar)
|
||||
assert itest.instance_type.instance_names.include?(:ivar) , itest.instance_type.instance_names.inspect
|
||||
end
|
||||
|
||||
def test_ivar_assign
|
||||
Compiler.compile "class TestIvar2 < Object ; def meth; @ivar = 5 ;end; end"
|
||||
itest = Parfait::Space.object_space.get_class_by_name(:TestIvar2)
|
||||
assert itest.instance_type.instance_names.include?(:ivar) , itest.instance_type.instance_names.inspect
|
||||
end
|
||||
|
||||
def test_ivar_operator_assign
|
||||
Compiler.compile "class TestIvar3 < Object ; def meth; @ivar += 5 ;end; end"
|
||||
itest = Parfait::Space.object_space.get_class_by_name(:TestIvar3)
|
||||
assert itest.instance_type.instance_names.include?(:ivar) , itest.instance_type.instance_names.inspect
|
||||
end
|
||||
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue
Block a user