rubyx/test/compiler/statements/test_class.rb

70 lines
1.3 KiB
Ruby
Raw Normal View History

2015-10-25 12:19:18 +01:00
require_relative 'helper'
module Register
2015-10-27 10:00:48 +01:00
class TestClassStatements < MiniTest::Test
2015-10-25 12:19:18 +01:00
include Statements
def test_class_defs
2015-10-25 12:19:18 +01:00
@string_input = <<HERE
class Bar
int self.buh()
2015-10-25 12:19:18 +01:00
return 1
end
end
class Object
int main()
return 1
end
end
HERE
2015-11-02 19:12:01 +01:00
@expect = [Label, LoadConstant,SetSlot,Label,RegisterTransfer,GetSlot,FunctionReturn]
2015-10-25 12:19:18 +01:00
check
end
2015-10-26 12:08:40 +01:00
2015-10-26 21:23:06 +01:00
def test_class_call
@string_input = <<HERE
class Bar
int self.buh()
return 1
end
end
class Object
int main()
return Bar.buh()
end
end
HERE
2015-11-02 19:12:01 +01:00
@expect = [Label, GetSlot, LoadConstant, SetSlot, LoadConstant, SetSlot, LoadConstant ,
SetSlot, LoadConstant, SetSlot, RegisterTransfer, FunctionCall, GetSlot, SetSlot ,
Label, RegisterTransfer, GetSlot, FunctionReturn]
2015-10-26 21:23:06 +01:00
check
end
2015-10-26 12:08:40 +01:00
def test_class_field_value
@string_input = <<HERE
class Object
2015-11-02 16:32:06 +01:00
field int boo1 = 1
2015-10-26 12:08:40 +01:00
int main()
return 1
end
end
HERE
2015-11-02 19:12:01 +01:00
@expect = [Label, LoadConstant,SetSlot,Label,RegisterTransfer,GetSlot,FunctionReturn]
2015-10-26 12:08:40 +01:00
assert_raises{check}
end
def test_class_field
@string_input = <<HERE
class Object
2015-11-02 16:32:06 +01:00
field int boo2
2015-10-26 12:08:40 +01:00
int main()
2015-11-02 16:32:06 +01:00
return self.boo2
2015-10-26 12:08:40 +01:00
end
end
HERE
2015-11-02 19:12:01 +01:00
@expect = [Label, GetSlot,GetSlot,SetSlot,Label,RegisterTransfer,GetSlot,FunctionReturn]
2015-10-26 12:08:40 +01:00
check
end
2015-10-25 12:19:18 +01:00
end
end