2015-09-18 20:55:02 +02:00
|
|
|
require_relative "setup"
|
|
|
|
require "parslet/convenience"
|
|
|
|
require "ast/sexp"
|
|
|
|
|
|
|
|
class TestAll < MiniTest::Test
|
|
|
|
include AST::Sexp
|
|
|
|
|
|
|
|
def check_file file
|
|
|
|
inn , out = File.new(file).read.split("-- -- --")
|
|
|
|
sexp = eval(out)
|
|
|
|
syntax = Parser::Salama.new.parse_with_debug(inn)
|
|
|
|
result = Parser::Transform.new.apply(syntax)
|
2015-09-18 21:21:17 +02:00
|
|
|
equal = (sexp == result)
|
|
|
|
puts "\n" + result.inspect unless equal
|
2015-09-18 20:55:02 +02:00
|
|
|
assert_equal sexp , result
|
|
|
|
end
|
2015-09-18 21:21:17 +02:00
|
|
|
|
2015-09-18 20:55:02 +02:00
|
|
|
# this creates test methods dynamically. For each test_* method we create
|
|
|
|
# three test_*[ast/parse/transf] methods that in turn check the three phases.
|
|
|
|
# runnable_methods is called by minitest to determine which tests to run
|
|
|
|
def self.runnable_methods
|
|
|
|
all = Dir["test/cases/*/*.tst"]
|
|
|
|
tests =[]
|
|
|
|
all.each do |file|
|
|
|
|
name = file.sub("test/cases/","").sub("/","_").sub(".tst","")
|
|
|
|
tests << name
|
|
|
|
self.send(:define_method, name ) do
|
|
|
|
send("check_file" , file)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
tests
|
|
|
|
end
|
|
|
|
end
|