2018-07-19 13:46:51 +02:00
|
|
|
require_relative "../helper"
|
|
|
|
|
|
|
|
module Ruby
|
|
|
|
module RubyTests
|
2019-08-25 13:40:59 +02:00
|
|
|
include ScopeHelper
|
2018-07-19 13:46:51 +02:00
|
|
|
def setup
|
2019-02-08 22:03:23 +01:00
|
|
|
Parfait.boot!(Parfait.default_test_options)
|
2018-07-19 13:46:51 +02:00
|
|
|
end
|
|
|
|
def compile(input)
|
|
|
|
RubyCompiler.compile(input)
|
|
|
|
end
|
2019-08-25 13:40:59 +02:00
|
|
|
def compile_main(input)
|
|
|
|
RubyCompiler.compile(as_main(input))
|
|
|
|
end
|
2019-10-03 23:36:49 +02:00
|
|
|
def compile_main_sol(input)
|
2019-08-25 13:40:59 +02:00
|
|
|
xcompiler = RubyX::RubyXCompiler.new(RubyX.default_test_options)
|
2019-10-03 23:36:49 +02:00
|
|
|
xcompiler.ruby_to_sol(as_main(input))
|
2019-08-25 13:40:59 +02:00
|
|
|
end
|
2018-07-19 13:46:51 +02:00
|
|
|
|
2019-03-05 19:36:40 +01:00
|
|
|
def assert_raises_muted &block
|
|
|
|
orig_stdout = $stdout
|
|
|
|
$stdout = StringIO.new
|
|
|
|
assert_raises &block
|
|
|
|
$stdout = orig_stdout
|
|
|
|
end
|
2018-07-19 13:46:51 +02:00
|
|
|
end
|
2019-03-07 09:47:48 +01:00
|
|
|
module AttributeTests
|
|
|
|
include RubyTests
|
|
|
|
def setup
|
|
|
|
super
|
2019-10-03 23:36:49 +02:00
|
|
|
@sol = compile( "class Tryout < Base; #{attr_def};end" ).to_sol
|
2019-03-07 09:47:48 +01:00
|
|
|
end
|
|
|
|
def getter
|
2019-10-03 23:36:49 +02:00
|
|
|
@sol.body.statements.first
|
2019-03-07 09:47:48 +01:00
|
|
|
end
|
|
|
|
def setter
|
2019-10-03 23:36:49 +02:00
|
|
|
@sol.body.statements.last
|
2019-03-07 09:47:48 +01:00
|
|
|
end
|
2019-03-07 10:00:18 +01:00
|
|
|
def test_class
|
2019-10-03 23:36:49 +02:00
|
|
|
assert_equal Sol::ClassExpression , @sol.class
|
2019-03-07 10:00:18 +01:00
|
|
|
end
|
|
|
|
def test_body
|
2019-10-03 23:36:49 +02:00
|
|
|
assert_equal Sol::Statements , @sol.body.class
|
2019-03-07 10:00:18 +01:00
|
|
|
end
|
|
|
|
def test_getter
|
2019-10-03 23:36:49 +02:00
|
|
|
assert_equal Sol::MethodExpression , getter.class
|
2019-03-07 10:00:18 +01:00
|
|
|
end
|
|
|
|
def test_getter_return
|
2019-10-03 23:36:49 +02:00
|
|
|
assert_equal Sol::ReturnStatement , getter.body.class
|
2019-03-07 10:00:18 +01:00
|
|
|
end
|
|
|
|
def test_getter_name
|
|
|
|
assert_equal :page , getter.name
|
|
|
|
end
|
2019-03-07 09:47:48 +01:00
|
|
|
end
|
2018-07-19 13:46:51 +02:00
|
|
|
end
|