2017-01-14 20:05:58 +02:00
|
|
|
require_relative "helper"
|
|
|
|
|
2017-01-18 00:05:36 +02:00
|
|
|
module Rubyx
|
2017-01-16 17:24:32 +02:00
|
|
|
module Passes
|
2017-08-31 16:18:59 +03:00
|
|
|
class TestLocalsCollector #< MiniTest::Test
|
2017-01-14 20:05:58 +02:00
|
|
|
|
|
|
|
def setup
|
2017-01-19 09:02:29 +02:00
|
|
|
Risc.machine.boot unless Risc.machine.booted
|
2017-01-14 20:05:58 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def parse_collect( input )
|
|
|
|
ast = Parser::Ruby22.parse input
|
|
|
|
LocalsCollector.new.collect(ast)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_no_locals
|
|
|
|
locals = parse_collect "def meth; end"
|
|
|
|
assert locals.empty?
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_method_is_not_local
|
|
|
|
locals = parse_collect("def meth2(arg1); foo ;end")
|
|
|
|
assert locals.empty?
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_local_assign_one
|
|
|
|
locals = parse_collect("def meth2(arg1); foo = bar ;end")
|
|
|
|
assert locals[:foo] , locals.inspect
|
|
|
|
end
|
|
|
|
def test_local_assign_two
|
|
|
|
locals = parse_collect("def meth2(arg1); foo = bar ; groove = 1 + 2 ;end")
|
|
|
|
assert locals.length == 2 , locals.inspect
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|