2017-01-14 19:05:58 +01:00
|
|
|
require_relative "helper"
|
|
|
|
|
2017-01-17 23:05:36 +01:00
|
|
|
module Rubyx
|
2017-01-16 16:24:32 +01:00
|
|
|
module Passes
|
2017-08-31 15:18:59 +02:00
|
|
|
class TestMethodCollector #< MiniTest::Test
|
2017-01-14 19:05:58 +01:00
|
|
|
|
|
|
|
def setup
|
2017-01-19 08:02:29 +01:00
|
|
|
Risc.machine.boot unless Risc.machine.booted
|
2017-01-14 19:05:58 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def parse_collect( input )
|
|
|
|
ast = Parser::Ruby22.parse input
|
|
|
|
MethodCollector.new.collect(ast)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_no_args
|
|
|
|
methods = parse_collect "def meth; @ivar;end"
|
|
|
|
assert methods.find{|m| m.name == :meth }
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_one_arg
|
|
|
|
method = parse_collect("def meth2(arg1); 1;end").first
|
|
|
|
assert method.name == :meth2
|
|
|
|
assert_equal 2 , method.args_type.variable_index(:arg1) , method.args_type.inspect
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_three_args
|
|
|
|
method = parse_collect("def meth3(yksi,kaksi,kolme); 1;end").first
|
|
|
|
assert method.args_type.variable_index(:kolme) , method.args_type.inspect
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_one_local
|
|
|
|
method = parse_collect("def meth2(arg1); foo = 2 ;end").first
|
2018-03-14 15:54:47 +01:00
|
|
|
assert method.frame_type.variable_index(:foo) , method.frame_type.inspect
|
2017-01-14 19:05:58 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|