Fixing ruby send with arguments
When send has complex args, mostly more sends, we hoist those out and pass created temporary variables
This commit is contained in:
@ -9,10 +9,6 @@ module Ruby
|
||||
RubyCompiler.compile(input)
|
||||
end
|
||||
|
||||
def ruby_to_vool(input)
|
||||
FIXMERubyXCompiler.new(input).ruby_to_vool
|
||||
end
|
||||
|
||||
def assert_raises_muted &block
|
||||
orig_stdout = $stdout
|
||||
$stdout = StringIO.new
|
||||
|
@ -1,7 +1,7 @@
|
||||
require_relative "helper"
|
||||
|
||||
module Ruby
|
||||
class TestSendFoo < MiniTest::Test
|
||||
class TestSendNoArg < MiniTest::Test
|
||||
include RubyTests
|
||||
def setup
|
||||
@lst = compile( "foo")
|
||||
@ -22,7 +22,7 @@ module Ruby
|
||||
assert_equal "self.foo()" , @lst.to_s
|
||||
end
|
||||
end
|
||||
class TestSendBar < MiniTest::Test
|
||||
class TestSendSimpleArg < MiniTest::Test
|
||||
include RubyTests
|
||||
def setup
|
||||
@lst = compile( "bar(1)")
|
||||
@ -63,5 +63,30 @@ module Ruby
|
||||
lst = compile( "super(1)")
|
||||
assert_nil lst.name
|
||||
end
|
||||
class TestSendSendArgs < MiniTest::Test
|
||||
include RubyTests
|
||||
def setup
|
||||
@lst = compile( "call(arg1, arg2(more))")
|
||||
end
|
||||
def test_one_arg
|
||||
assert_equal SendStatement , @lst.class
|
||||
end
|
||||
def test_one_arg_name
|
||||
assert_equal :call , @lst.name
|
||||
end
|
||||
def test_one_arg_args
|
||||
assert_equal SendStatement , @lst.arguments.first.class
|
||||
end
|
||||
def test_one_arg_args_args
|
||||
assert_equal 0 , @lst.arguments.first.arguments.length
|
||||
end
|
||||
def test_two_arg_args
|
||||
assert_equal SendStatement , @lst.arguments[1].class
|
||||
end
|
||||
def test_two_arg_args_args
|
||||
assert_equal SendStatement , @lst.arguments[1].arguments.first.class
|
||||
assert_equal :more , @lst.arguments[1].arguments.first.name
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -1,7 +1,7 @@
|
||||
require_relative "helper"
|
||||
|
||||
module Ruby
|
||||
class TestSendFooVool < MiniTest::Test
|
||||
class TestSendNoArgVool < MiniTest::Test
|
||||
include RubyTests
|
||||
def setup
|
||||
@lst = compile( "foo").to_vool
|
||||
@ -19,7 +19,7 @@ module Ruby
|
||||
assert_equal [] , @lst.arguments
|
||||
end
|
||||
end
|
||||
class TestSendBarVool < MiniTest::Test
|
||||
class TestSendSimpleArgVool < MiniTest::Test
|
||||
include RubyTests
|
||||
def setup
|
||||
@lst = compile( "bar(1)").to_vool
|
||||
|
70
test/ruby/test_send_statement2.rb
Normal file
70
test/ruby/test_send_statement2.rb
Normal file
@ -0,0 +1,70 @@
|
||||
require_relative "helper"
|
||||
|
||||
module Ruby
|
||||
module LastBar
|
||||
include RubyTests
|
||||
def test_last_class
|
||||
assert_equal Vool::SendStatement , @lst.last.class
|
||||
end
|
||||
def test_last_name
|
||||
assert_equal :last , @lst.last.name
|
||||
end
|
||||
def test_last_arg
|
||||
assert_equal Vool::LocalVariable , @lst.last.arguments.first.class
|
||||
end
|
||||
def test_lst_class
|
||||
assert_equal Vool::Statements , @lst.class
|
||||
end
|
||||
def test_lst_no_statements
|
||||
@lst.statements.each{|st| assert( ! st.is_a?(Vool::Statements) , st.class)}
|
||||
end
|
||||
end
|
||||
class TestSendSendArgVool < MiniTest::Test
|
||||
include LastBar
|
||||
def setup
|
||||
@lst = compile( "last(foo(1))").to_vool
|
||||
end
|
||||
def test_classes
|
||||
assert_equal Vool::Statements , @lst.class
|
||||
assert_equal Vool::LocalAssignment , @lst.first.class
|
||||
assert_equal Vool::SendStatement , @lst.last.class
|
||||
end
|
||||
def test_foo1
|
||||
assert_equal Vool::SendStatement , @lst.first.value.class
|
||||
assert_equal :foo , @lst.first.value.name
|
||||
assert_equal Vool::IntegerConstant , @lst.first.value.arguments.first.class
|
||||
end
|
||||
end
|
||||
class Test3SendVool < MiniTest::Test
|
||||
include LastBar
|
||||
def setup
|
||||
@lst = compile( "last(foo(more(1)))").to_vool
|
||||
end
|
||||
def test_classes
|
||||
assert_equal Vool::Statements , @lst.class
|
||||
assert_equal Vool::LocalAssignment , @lst.first.class
|
||||
assert_equal Vool::SendStatement , @lst.last.class
|
||||
end
|
||||
def test_foo
|
||||
assert_equal Vool::SendStatement , @lst.first.value.class
|
||||
assert_equal :more , @lst.first.value.name
|
||||
assert_equal Vool::IntegerConstant , @lst.first.value.arguments.first.class
|
||||
end
|
||||
end
|
||||
class Test5SendVool < MiniTest::Test
|
||||
include LastBar
|
||||
def setup
|
||||
@lst = compile( "last(foo(more(even_more(1),and_more(with_more))))").to_vool
|
||||
end
|
||||
def test_classes
|
||||
assert_equal Vool::Statements , @lst.class
|
||||
assert_equal Vool::LocalAssignment , @lst.first.class
|
||||
assert_equal Vool::SendStatement , @lst.last.class
|
||||
end
|
||||
def test_foo
|
||||
assert_equal Vool::SendStatement , @lst.first.value.class
|
||||
assert_equal :even_more , @lst.first.value.name
|
||||
assert_equal Vool::IntegerConstant , @lst.first.value.arguments.first.class
|
||||
end
|
||||
end
|
||||
end
|
Reference in New Issue
Block a user