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
|
|
|
|
|
2015-10-27 20:04:46 +01:00
|
|
|
def test_class_defs
|
2015-10-25 12:19:18 +01:00
|
|
|
@string_input = <<HERE
|
|
|
|
class Bar
|
2015-10-25 14:40:12 +01:00
|
|
|
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-10-27 20:04:46 +01:00
|
|
|
@expect = [Label, SaveReturn,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-10-27 15:21:11 +01:00
|
|
|
@expect = [Label, SaveReturn,GetSlot,LoadConstant,SetSlot,LoadConstant,SetSlot,LoadConstant,SetSlot,
|
2015-10-27 20:04:46 +01:00
|
|
|
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-10-27 20:04:46 +01:00
|
|
|
@expect = [Label, SaveReturn,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-10-27 20:04:46 +01:00
|
|
|
@expect = [Label, SaveReturn,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
|