2017-04-02 18:13:14 +02:00
|
|
|
require_relative "helper"
|
2017-04-01 14:57:39 +02:00
|
|
|
|
2018-07-19 13:46:51 +02:00
|
|
|
module Ruby
|
2018-07-19 20:44:48 +02:00
|
|
|
class TestClassStatementVool < MiniTest::Test
|
|
|
|
include RubyTests
|
|
|
|
|
|
|
|
def setup
|
|
|
|
input = "class Tryout < Base;def meth; a = 5 ;end; end"
|
|
|
|
@vool = compile( input ).to_vool
|
|
|
|
end
|
|
|
|
def test_class
|
|
|
|
assert_equal Vool::ClassStatement , @vool.class
|
|
|
|
end
|
|
|
|
def test_body
|
|
|
|
assert_equal Vool::Statements , @vool.body.class
|
|
|
|
end
|
|
|
|
def test_compile_class_name
|
|
|
|
assert_equal :Tryout , @vool.name
|
|
|
|
end
|
|
|
|
def test_compile_class_super
|
|
|
|
assert_equal :Base , @vool.super_class_name
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
2018-07-19 15:30:36 +02:00
|
|
|
class TestEmptyClassStatement < MiniTest::Test
|
2018-06-29 21:46:39 +02:00
|
|
|
include RubyTests
|
2017-04-01 14:57:39 +02:00
|
|
|
|
|
|
|
def setup
|
|
|
|
input = "class Tryout < Base;end"
|
2018-06-29 21:46:39 +02:00
|
|
|
@lst = compile( input )
|
2017-04-01 14:57:39 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_compile_class
|
|
|
|
assert_equal ClassStatement , @lst.class
|
|
|
|
end
|
|
|
|
def test_compile_class_name
|
|
|
|
assert_equal :Tryout , @lst.name
|
|
|
|
end
|
|
|
|
def test_compile_class_super
|
|
|
|
assert_equal :Base , @lst.super_class_name
|
|
|
|
end
|
2017-04-01 15:27:32 +02:00
|
|
|
def test_compile_class_body
|
2018-06-29 22:29:10 +02:00
|
|
|
assert @lst.body.empty?
|
2017-04-09 08:59:21 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
2018-07-19 15:30:36 +02:00
|
|
|
class TestBasicClassStatement < MiniTest::Test
|
2018-06-29 22:04:50 +02:00
|
|
|
include ScopeHelper
|
2018-06-29 21:46:39 +02:00
|
|
|
include RubyTests
|
2017-04-09 08:59:21 +02:00
|
|
|
|
|
|
|
def test_compile_one_method
|
2018-06-29 22:29:10 +02:00
|
|
|
lst = compile( as_test_main("@ivar = 4") )
|
|
|
|
assert_equal IvarAssignment , lst.body.first.body.class
|
2017-04-09 08:59:21 +02:00
|
|
|
end
|
2018-06-29 22:29:10 +02:00
|
|
|
def test_compile_two_stats
|
|
|
|
lst = compile( as_test_main("false; true;") )
|
|
|
|
assert_equal ScopeStatement , lst.body.first.body.class
|
|
|
|
assert_equal TrueConstant , lst.body.first.body.statements[1].class
|
2017-04-01 15:27:32 +02:00
|
|
|
end
|
2019-03-05 19:36:40 +01:00
|
|
|
end
|
|
|
|
class TestClassStatementTransformFail < MiniTest::Test
|
|
|
|
include RubyTests
|
2017-04-01 15:27:32 +02:00
|
|
|
|
2019-03-05 19:36:40 +01:00
|
|
|
def test_if
|
|
|
|
input = "class Tryout < Base; false if(true) ; end"
|
|
|
|
assert_raises_muted { compile( input ).to_vool}
|
|
|
|
end
|
|
|
|
def test_instance
|
|
|
|
input = "class Tryout < Base; @var = 5 ; end"
|
|
|
|
assert_raises_muted { compile( input ).to_vool}
|
|
|
|
end
|
|
|
|
def test_wrong_send
|
|
|
|
input = "class Tryout < Base; hi() ; end"
|
|
|
|
assert_raises_muted { compile( input ).to_vool}
|
|
|
|
end
|
2017-04-01 14:57:39 +02:00
|
|
|
end
|
|
|
|
end
|