test collector for ivar assignment

This commit is contained in:
Torsten Ruger 2016-12-20 15:46:23 +02:00
parent aa5f48e3c6
commit aa6685a0cb
4 changed files with 40 additions and 8 deletions

View File

@ -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)

View File

@ -1 +1,2 @@
require_relative "test_class"
require_relative "test_collector"

View File

@ -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

View 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