From 9c16d81ad690476311ca8c10f7ce3774f1ef722d Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Mon, 28 Apr 2014 22:22:37 +0300 Subject: [PATCH] some explanation for the parser tests --- test/test_all.rb | 2 +- test/{test_nodes.rb => test_ast.rb} | 6 ++---- test/test_parser.rb | 22 +++++++++++++++++++++- test/test_transform.rb | 3 +++ 4 files changed, 27 insertions(+), 6 deletions(-) rename test/{test_nodes.rb => test_ast.rb} (93%) diff --git a/test/test_all.rb b/test/test_all.rb index 04175afc..368bbf21 100644 --- a/test/test_all.rb +++ b/test/test_all.rb @@ -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" diff --git a/test/test_nodes.rb b/test/test_ast.rb similarity index 93% rename from test/test_nodes.rb rename to test/test_ast.rb index f0e86947..1ec9488e 100644 --- a/test/test_nodes.rb +++ b/test/test_ast.rb @@ -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 diff --git a/test/test_parser.rb b/test/test_parser.rb index 3d1aeff5..314b060f 100644 --- a/test/test_parser.rb +++ b/test/test_parser.rb @@ -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 diff --git a/test/test_transform.rb b/test/test_transform.rb index bf5b943e..c174fc33 100644 --- a/test/test_transform.rb +++ b/test/test_transform.rb @@ -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