2018-07-25 10:06:42 +02:00
|
|
|
require_relative "helper"
|
|
|
|
|
|
|
|
module Ruby
|
|
|
|
class TestBlockReturn < MiniTest::Test
|
|
|
|
include RubyTests
|
|
|
|
|
|
|
|
def setup()
|
|
|
|
input = "a = plus_one{return 1 } ; return a "
|
|
|
|
@lst = compile( input )
|
|
|
|
end
|
|
|
|
def test_scope
|
|
|
|
assert_equal ScopeStatement , @lst.class
|
|
|
|
end
|
|
|
|
def test_assign
|
|
|
|
assert_equal LocalAssignment , @lst.first.class
|
|
|
|
end
|
|
|
|
def test_assign_right
|
2019-08-19 09:31:11 +02:00
|
|
|
assert_equal RubyBlockStatement , @lst.first.value.class
|
2018-07-25 10:06:42 +02:00
|
|
|
end
|
|
|
|
def test_method_name
|
|
|
|
assert_equal :plus_one , @lst.first.value.send.name
|
|
|
|
end
|
|
|
|
def test_ret
|
|
|
|
assert_equal ReturnStatement , @lst.last.class
|
|
|
|
end
|
|
|
|
end
|
2019-10-03 23:36:49 +02:00
|
|
|
class TestBlockReturnSol < MiniTest::Test
|
2018-07-25 10:06:42 +02:00
|
|
|
include RubyTests
|
|
|
|
def setup()
|
|
|
|
input = "a = plus_one{return 1 } ; return a "
|
2019-10-03 23:36:49 +02:00
|
|
|
@lst = compile( input ).to_sol
|
2018-07-25 10:06:42 +02:00
|
|
|
end
|
|
|
|
def test_scope
|
2019-10-03 23:36:49 +02:00
|
|
|
assert_equal Sol::ScopeStatement , @lst.class
|
2018-07-25 10:06:42 +02:00
|
|
|
end
|
2019-08-19 13:23:55 +02:00
|
|
|
def test_assign
|
2019-10-03 23:36:49 +02:00
|
|
|
assert_equal Sol::LocalAssignment , @lst.first.class
|
2019-08-19 13:23:55 +02:00
|
|
|
assert_equal :a , @lst.first.name
|
2018-07-25 10:06:42 +02:00
|
|
|
end
|
2019-08-19 13:23:55 +02:00
|
|
|
def test_send
|
2019-10-03 23:36:49 +02:00
|
|
|
assert_equal Sol::SendStatement , @lst.first.value.class
|
2019-08-19 13:23:55 +02:00
|
|
|
assert_equal :plus_one , @lst.first.value.name
|
2018-07-25 10:06:42 +02:00
|
|
|
end
|
2019-08-19 13:23:55 +02:00
|
|
|
def test_block_arg
|
2019-10-03 23:36:49 +02:00
|
|
|
assert_equal Sol::LambdaExpression , @lst.first.value.arguments.first.class
|
2018-07-25 10:06:42 +02:00
|
|
|
end
|
|
|
|
def test_ret
|
2019-10-03 23:36:49 +02:00
|
|
|
assert_equal Sol::ReturnStatement , @lst[1].class
|
2018-07-25 10:06:42 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|