move old tests out of the way

This commit is contained in:
Torsten Ruger
2016-12-18 17:01:30 +02:00
parent 756cb52a98
commit b8cf72e729
8 changed files with 0 additions and 0 deletions

View File

@ -0,0 +1,96 @@
require_relative '../helper'
require "register/interpreter"
require "parser/ruby22"
require "yaml"
class Walker < AST::Processor
def initialize collector
@collector = collector
end
def on_send node
_ , method , file_node = *node
if method == :require
file = file_node.children[0]
@collector.load("#{file}.rb") unless file.include?("parslet")
end
if method == :require_relative
@collector.load File.dirname(@collector.current) + "/" + file_node.children[0] + ".rb"
end
if method.to_s.include?("eval")
@collector.evals << method
end
handler_missing(node)
end
def on_class node
@collector.class_defs << node.children[0].children[1]
handler_missing(node)
end
def on_const node
@collector.const_uses[node.children[1]] += 1
handler_missing(node)
end
def handler_missing node
type = node.type
@collector.types[type] += 1
node.children.each do |kid|
process(kid) if kid.is_a? AST::Node
end
end
end
class Collector
def initialize
@parser = Parser::Ruby22
@paths = Bundler.load.specs.collect { |s| s.gem_dir + "/lib/" }
@class_defs = []
@const_uses = Hash.new(0)
@types = Hash.new(0)
@not_found = []
@walker = Walker.new(self)
@files = []
@evals = []
@current = nil
end
attr_reader :class_defs , :const_uses , :types , :current , :evals
def file_content file_name
return nil if @files.include? file_name
@paths.each do |name|
next unless File.exist? name + file_name
@files << file_name
return File.open(name + file_name).read
end
nil
end
def run
load "salama.rb"
load "parser/ruby22.rb"
# load "../../../.rbenv/versions/2.2.3/lib/ruby/2.2.0/racc/parser.rb"
print
end
def load file
str = file_content(file)
return @not_found.push(file) unless str
ast = @parser.parse str
was = @current
@current = file
@walker.process ast
@current = was
end
def print
@class_defs.uniq!
@files.uniq!
puts "Types #{@types.to_yaml}"
puts "Class defs #{@class_defs.length}"
puts "Class defs #{@class_defs}"
puts "evals=#{@evals.length} #{@evals.uniq}"
puts "Not found #{@not_found.length} #{@not_found}"
end
end
Collector.new.run

View File

@ -0,0 +1,15 @@
require_relative '../helper'
require "register/interpreter"
require "parser/ruby22"
module MelonTests
def setup
@parser = Parser::Ruby22
end
def check
assert true
#puts @parser.parse @string_input
end
end

View File

@ -0,0 +1,51 @@
require_relative 'helper'
class TestRubyAdds < MiniTest::Test
include MelonTests
def test_ruby_adds
@string_input = <<HERE
def fibo( n)
a = 0
b = 1
i = 1
while( i < n ) do
result = a + b
a = b
b = result
i+= 1
end
return result
end
HERE
@stdout = "Hello there"
check
end
def pest_ruby_adds_looping
@string_input = <<HERE
def fibo( n)
a = 0
b = 1
i = 1
while( i < n ) do
result = a + b
a = b
b = result
i+= 1
end
return result
end
counter = 100000
while(counter > 0) do
fibo(40)
counter -= 1
end
HERE
@length = 37
@stdout = "Hello Raisa, I am salama"
check
end
end

View File

@ -0,0 +1,5 @@
require_relative "test_loop"
require_relative "test_itos"
require_relative "test_calls"
require_relative "test_adds"
require_relative "test_hello"

View File

@ -0,0 +1,45 @@
require_relative 'helper'
class TestRubyCalls < MiniTest::Test
include MelonTests
def test_ruby_calls
@string_input = <<HERE
def fibo_r( n )
if( n < 2 )
return n
else
return fibo_r(n - 1) + fibo_r(n - 2)
end
end
fibo 40
HERE
@stdout = "Hello there"
check
end
def pest_ruby_calls_looping
@string_input = <<HERE
def fibo_r( n )
if( n < 2 )
return n
else
return fibo_r(n - 1) + fibo_r(n - 2)
end
end
counter = 1000
while(counter > 0) do
fibo_r(20)
counter -= 1
end
HERE
@length = 37
@stdout = ""
check
end
end

View File

@ -0,0 +1,27 @@
require_relative 'helper'
class TestRubyHello < MiniTest::Test
include MelonTests
def test_ruby_hello
@string_input = <<HERE
puts "Hello there"
HERE
@stdout = "Hello there"
check
end
def pest_ruby_hello_looping
@string_input = <<HERE
counter = 100000;
while(counter > 0) do
puts "Hello there"
STDOUT.flush
counter = counter - 1
end
HERE
@length = 37
@stdout = "Hello Raisa, I am salama"
check
end
end

View File

@ -0,0 +1,28 @@
require_relative 'helper'
class TestRubyItos < MiniTest::Test
include MelonTests
def test_ruby_itos
@string_input = <<HERE
100000.to_s
HERE
@stdout = "Hello there"
check
end
def pest_ruby_itos_looping
@string_input = <<HERE
counter = 100000
while(counter > 0) do
str = counter.to_s
counter = counter - 1
end
str
HERE
@length = 37
@stdout = "Hello Raisa, I am salama"
check
end
end

View File

@ -0,0 +1,17 @@
require_relative 'helper'
class TestRubyLoop < MiniTest::Test
include MelonTests
def test_ruby_loop
@string_input = <<HERE
counter = 100000
while(counter > 0) do
counter -= 1
end
HERE
@stdout = "Hello there"
check
end
end