2018-06-26 19:28:27 +02:00
|
|
|
require_relative "helper"
|
|
|
|
|
2018-07-19 13:46:51 +02:00
|
|
|
module Ruby
|
2018-07-19 15:22:44 +02:00
|
|
|
class TestBlockStatement < MiniTest::Test
|
2018-06-29 21:46:39 +02:00
|
|
|
include RubyTests
|
2018-07-07 16:57:46 +02:00
|
|
|
|
2018-06-26 19:28:27 +02:00
|
|
|
def setup()
|
|
|
|
input = "plus_one{|arg1| arg1 + 1 } "
|
2018-06-29 21:46:39 +02:00
|
|
|
@lst = compile( input )
|
2018-06-26 19:28:27 +02:00
|
|
|
end
|
|
|
|
def test_block
|
2018-07-19 15:22:44 +02:00
|
|
|
assert_equal BlockStatement , @lst.class
|
|
|
|
end
|
|
|
|
def test_send
|
|
|
|
assert_equal SendStatement , @lst.send.class
|
2018-06-26 19:28:27 +02:00
|
|
|
end
|
|
|
|
def test_method_name
|
2018-07-19 15:22:44 +02:00
|
|
|
assert_equal :plus_one , @lst.send.name
|
2018-06-26 19:28:27 +02:00
|
|
|
end
|
|
|
|
def test_block_args
|
2018-07-19 15:22:44 +02:00
|
|
|
assert_equal [:arg1] , @lst.args
|
2018-06-26 19:28:27 +02:00
|
|
|
end
|
|
|
|
def test_block_body
|
2018-07-19 15:22:44 +02:00
|
|
|
assert_equal SendStatement , @lst.body.class
|
|
|
|
assert_equal 1 , @lst.body.arguments.length
|
2018-06-26 19:28:27 +02:00
|
|
|
end
|
|
|
|
end
|
2018-07-20 19:07:15 +02:00
|
|
|
class TestBlockStatementVool < MiniTest::Test
|
|
|
|
include RubyTests
|
|
|
|
|
|
|
|
def setup()
|
|
|
|
input = "plus_one{|arg1| arg1 + 1 } "
|
|
|
|
@lst = compile( input ).to_vool
|
|
|
|
end
|
|
|
|
def test_block
|
|
|
|
assert_equal Vool::Statements , @lst.class
|
|
|
|
end
|
|
|
|
def test_first
|
|
|
|
assert_equal Vool::LocalAssignment , @lst.first.class
|
|
|
|
assert @lst.first.name.to_s.start_with?("implicit_block_")
|
|
|
|
assert_equal Vool::BlockStatement , @lst.first.value.class
|
|
|
|
end
|
|
|
|
def test_last_send
|
|
|
|
assert_equal 2 , @lst.length
|
|
|
|
assert_equal Vool::SendStatement , @lst.last.class
|
|
|
|
assert_equal :plus_one , @lst.last.name
|
|
|
|
end
|
|
|
|
def test_send_block_arg
|
|
|
|
assert_equal 1 , @lst.last.arguments.length
|
|
|
|
assert @lst.last.arguments.first.name.to_s.start_with?("implicit_block_")
|
|
|
|
end
|
|
|
|
def test_block_args
|
|
|
|
assert_equal [:arg1] , @lst.first.value.args
|
|
|
|
end
|
|
|
|
end
|
2018-06-26 19:28:27 +02:00
|
|
|
end
|