some explanation for the parser tests

This commit is contained in:
Torsten Ruger 2014-04-28 22:22:37 +03:00
parent 874f080ba2
commit 9c16d81ad6
4 changed files with 27 additions and 6 deletions

View File

@ -1,5 +1,5 @@
require_relative "test_crystal"
require_relative "test_nodes"
require_relative "test_ast"
require_relative "test_parser"
require_relative "test_small_program"
require_relative "test_transform"

View File

@ -1,12 +1,10 @@
require_relative "helper"
# testing that parsing strings that we know to be correct returns the nodes we expect
# in a way the combination of test_parser and test_transform
# Please read note in test_parser
require_relative 'helper'
class TestNodes < MiniTest::Test
class TestAst < MiniTest::Test
def setup
@parser = Parser::Composed.new

View File

@ -1,5 +1,25 @@
require_relative 'helper'
# Some sanity is emerging in the testing of parsers
# (Parsers are fiddly in respect to space and order, small changes may and do have unexpected effects)
# For any functionality that we want to work (ie test), there are actually three tests, with the _same_ name
# One in each of the parser/transform/ast classes
# Parser test that the parser parses and thet the output is correct. Rules are named and and boil down to
# hashes and arrays with lots of symbols for the names the rules (actually the reults) were given
# Transform test really just test the tranformation. They basically take the output of the parse
# and check that correct Ast classes are produced
# Ast tests both steps in one. Ie string input to ast classes output
# All threee classes are layed out quite similarly in that they use a check method and
# each test assigns @input and @expected which the check methods then checks
# The check methods have a pust in it (to be left) which is very handy for checking
# also the output of parser.check can actually be used as the input of transform
# Repeat: For every test in parser, there should beone in transform and ast
# The test in transform should use the output of parser as input
# The test in ast should expect the same result as transform
class ParserTest < MiniTest::Test
def setup
@ -8,7 +28,7 @@ class ParserTest < MiniTest::Test
def check
is = @parser.parse(@input)
assert is
#puts is.inspect
assert_equal @expected , is
end
def test_number

View File

@ -1,5 +1,7 @@
require_relative 'helper'
# Please read note in test_parser
class TransformTest < MiniTest::Test
def setup
@ -8,6 +10,7 @@ class TransformTest < MiniTest::Test
def check
is = @transform.apply @input
#puts is.transform
assert_equal @expected , is
end
def test_number