soml-parser/test/parser_helper.rb

50 lines
1.3 KiB
Ruby
Raw Normal View History

2014-06-04 19:51:25 +02:00
require_relative "setup"
2014-06-04 18:56:50 +02:00
# Included in parser test will create tests methods
module ParserHelper
2015-08-27 20:02:00 +02:00
2014-06-04 18:56:50 +02:00
def self.included(base)
base.send :include, InstanceMethods #provides helpers and setup
base.send :extend, ClassMethods #gets the method creation going
end
2015-08-27 20:02:00 +02:00
2014-06-04 18:56:50 +02:00
module InstanceMethods
def setup
2015-08-27 20:02:00 +02:00
@parser = Keywords
2014-06-04 18:56:50 +02:00
end
2015-08-28 22:37:25 +02:00
# check that @input parses correctly to @input
2014-06-04 18:56:50 +02:00
def check_parse
2015-08-28 22:37:25 +02:00
is = @parser.parse(@input , :root => @root)
assert_equal @input , is
2014-06-04 18:56:50 +02:00
end
2015-08-28 22:37:25 +02:00
# check that @input parses and transforms to @output
2014-06-04 18:56:50 +02:00
def check_ast
2015-08-28 22:37:25 +02:00
syntax = @parser.parse(@input , :root => @root)
2014-06-04 18:56:50 +02:00
#puts is.inspect
2015-08-28 22:37:25 +02:00
assert_equal @output , syntax.value
2014-06-04 18:56:50 +02:00
end
end
module ClassMethods
2015-08-27 20:02:00 +02:00
# this creates test methods dynamically. For each test_* method we create
2014-06-04 18:56:50 +02:00
# 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 runnable_methods
tests = []
public_instance_methods(true).grep(/^test_/).map(&:to_s).each do |test|
2015-08-27 20:02:00 +02:00
["ast" , "parse"].each do |what|
2014-06-04 18:56:50 +02:00
name = "#{test}_#{what}"
tests << name
self.send(:define_method, name ) do
send(test)
send("check_#{what}")
end
end
end
tests
end
end
end