improved the framework a bit
This commit is contained in:
parent
585c27c78d
commit
9e75a50315
@ -14,6 +14,25 @@ Each test must thus specify (as instance variables):
|
|||||||
- the parse output
|
- the parse output
|
||||||
- the transform output
|
- the transform output
|
||||||
|
|
||||||
Test are grouped by functionality into cases and define methods parse_*
|
Magic
|
||||||
|
-----
|
||||||
|
|
||||||
|
Test are grouped by functionality into cases (classes) and define methods test_*
|
||||||
Test cases must include ParserHelper, which includes the magic to write the 3 test methods for each
|
Test cases must include ParserHelper, which includes the magic to write the 3 test methods for each
|
||||||
parse method. See test_basic ofr easy example.
|
test method. See test_basic for easy example.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
def test_number
|
||||||
|
@string_input = '42 '
|
||||||
|
@test_output = {:integer => '42'}
|
||||||
|
@transform_output = Parser::IntegerExpression.new(42)
|
||||||
|
@parser = @parser.integer
|
||||||
|
end
|
||||||
|
|
||||||
|
The first three lines define the data as described above.
|
||||||
|
The last line tells the parser what to parse. This is off couse only needed when a non-root rule is tested
|
||||||
|
and should be left out if possible.
|
||||||
|
|
||||||
|
As can be seen, there are no asserts. All asserting is done by the created methods, which call
|
||||||
|
the check_* methods in helper.
|
@ -38,17 +38,17 @@ module ParserHelper
|
|||||||
end
|
end
|
||||||
|
|
||||||
module ClassMethods
|
module ClassMethods
|
||||||
# this creates test methods dynamically. For each parse_* method we create
|
# this creates test methods dynamically. For each test_* method we create
|
||||||
# three test_* methods that in turn check the three phases.
|
# 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 (ie normally test_*)
|
# runnable_methods is called by minitest to determine which tests to run
|
||||||
def runnable_methods
|
def runnable_methods
|
||||||
tests = []
|
tests = []
|
||||||
public_instance_methods(true).grep(/^parse_/).map(&:to_s).each do |parse|
|
public_instance_methods(true).grep(/^test_/).map(&:to_s).each do |test|
|
||||||
["ast" , "transform" , "parse"].each do |what|
|
["ast" , "transform" , "parse"].each do |what|
|
||||||
name = "parse_#{what}"
|
name = "#{test}_#{what}"
|
||||||
tests << name
|
tests << name
|
||||||
self.send(:define_method, name ) do
|
self.send(:define_method, name ) do
|
||||||
send(parse)
|
send(test)
|
||||||
send("check_#{what}")
|
send("check_#{what}")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user