fix class def tests and code
This commit is contained in:
@ -1,39 +1,40 @@
|
||||
require_relative 'helper'
|
||||
|
||||
module Register
|
||||
class TestClassStatements #< MiniTest::Test
|
||||
class TestClassStatements < MiniTest::Test
|
||||
include Statements
|
||||
|
||||
def class_def
|
||||
clean_compile s(:statements,
|
||||
s(:class, :Bar,
|
||||
s(:derives, nil),
|
||||
s(:statements,
|
||||
s(:function, :Integer,
|
||||
s(:name, :buh),
|
||||
s(:parameters),
|
||||
s(:statements,
|
||||
s(:return,
|
||||
s(:int, 1))),
|
||||
s(:receiver, :self)))))
|
||||
end
|
||||
|
||||
def test_class_defs
|
||||
@input = <<HERE
|
||||
class Bar
|
||||
int self.buh()
|
||||
return 1
|
||||
end
|
||||
end
|
||||
class Space
|
||||
int main()
|
||||
return 1
|
||||
end
|
||||
end
|
||||
HERE
|
||||
class_def
|
||||
@input = s(:statements, s(:return, s(:int, 1)))
|
||||
@expect = [Label, LoadConstant,SetSlot,Label,FunctionReturn]
|
||||
check
|
||||
end
|
||||
|
||||
def test_class_call
|
||||
@input = <<HERE
|
||||
class Bar
|
||||
int self.buh()
|
||||
return 1
|
||||
end
|
||||
end
|
||||
class Space
|
||||
int main()
|
||||
return Bar.buh()
|
||||
end
|
||||
end
|
||||
HERE
|
||||
class_def
|
||||
@input = s(:statements,
|
||||
s(:return,
|
||||
s(:call,
|
||||
s(:name, :buh),
|
||||
s(:arguments),
|
||||
s(:receiver,
|
||||
s(:class_name, :Bar)))))
|
||||
|
||||
@expect = [Label, GetSlot, LoadConstant, SetSlot, LoadConstant, SetSlot, LoadConstant ,
|
||||
SetSlot, LoadConstant, SetSlot, RegisterTransfer, FunctionCall, Label, RegisterTransfer ,
|
||||
GetSlot, GetSlot, SetSlot, Label, FunctionReturn]
|
||||
@ -41,14 +42,16 @@ HERE
|
||||
end
|
||||
|
||||
def test_class_field
|
||||
@input = <<HERE
|
||||
class Space
|
||||
field int boo2
|
||||
int main()
|
||||
return self.boo2
|
||||
end
|
||||
end
|
||||
HERE
|
||||
clean_compile s(:statements,
|
||||
s(:class, :Space,
|
||||
s(:derives, nil),
|
||||
s(:statements,
|
||||
s(:class_field, :Integer, :boo2))))
|
||||
|
||||
@input = s(:statements,
|
||||
s(:return,
|
||||
s(:field_access, s(:receiver, s(:name, :self)),
|
||||
s(:field, s(:name, :boo2)))))
|
||||
@expect = [Label, GetSlot,GetSlot,SetSlot,Label,FunctionReturn]
|
||||
check
|
||||
end
|
||||
|
Reference in New Issue
Block a user