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