From b6e08faa398bcc1fa5461a1a2e115cb2a6a796da Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Tue, 29 Apr 2014 13:50:07 +0300 Subject: [PATCH] folds all basic tests into new directory --- test/parser/helper.rb | 10 ++++----- test/parser/test_basic.rb | 45 +++++++++++++++++++++++++++++++++++++++ test/test_ast.rb | 23 -------------------- test/test_parser.rb | 22 ------------------- test/test_transform.rb | 18 ---------------- 5 files changed, 50 insertions(+), 68 deletions(-) create mode 100644 test/parser/test_basic.rb diff --git a/test/parser/helper.rb b/test/parser/helper.rb index 3cc8f1ca..67cad3f6 100644 --- a/test/parser/helper.rb +++ b/test/parser/helper.rb @@ -10,20 +10,20 @@ module ParserTest def check_parse is = @parser.parse(@input) #puts is.inspect - assert_equal @expected , is + assert_equal @parse_output , is end def check_transform - is = @transform.apply @input + is = @transform.apply @parse_output #puts is.transform - assert_equal @expected , is + assert_equal @transform_output , is end def check_ast syntax = @parser.parse(@input) tree = @transform.apply(syntax) # puts tree.inspect - assert_equal @expected , tree + assert_equal @transform_output , tree end - + end \ No newline at end of file diff --git a/test/parser/test_basic.rb b/test/parser/test_basic.rb new file mode 100644 index 00000000..c607cf30 --- /dev/null +++ b/test/parser/test_basic.rb @@ -0,0 +1,45 @@ +require_relative "helper" + +class TestBasic < MiniTest::Test + include ParserTest + + # this creates test methods dynamically , one for each file in runners directory + def self.runnable_methods + tests = [] + public_instance_methods(true).grep(/^parse_/).map(&:to_s).each do |parse| + ["ast" , "transform" , "parse"].each do |what| + name = "parse_#{what}" + tests << name + self.send(:define_method, name ) do + send(parse) + send("check_#{what}") + end + end + end + tests + end + + def parse_number + @input = '42 ' + @parse_output = {:integer => '42'} + @transform_output = Parser::IntegerExpression.new(42) + @parser = @parser.integer + end + + def parse_name + @input = 'foo ' + @parse_output = {:name => 'foo'} + @transform_output = Parser::NameExpression.new('foo') + @parser = @parser.name + end + + def parse_string + @input = <"hello"} + @transform_output = Parser::StringExpression.new('hello') + @parser = @parser.string + end + +end \ No newline at end of file diff --git a/test/test_ast.rb b/test/test_ast.rb index 5bfda4fd..e0505810 100644 --- a/test/test_ast.rb +++ b/test/test_ast.rb @@ -18,29 +18,6 @@ class TestAst < MiniTest::Test assert_equal @transform_output , tree end - def test_number - @input = '42 ' - @transform_output = Parser::IntegerExpression.new(42) - @parser = @parser.integer - check - end - - def test_name - @input = 'foo ' - @transform_output = Parser::NameExpression.new('foo') - @parser = @parser.name - check - end - - def test_string - @input = < Parser::IntegerExpression.new(42) } diff --git a/test/test_parser.rb b/test/test_parser.rb index ed4f51dc..7f97a3df 100644 --- a/test/test_parser.rb +++ b/test/test_parser.rb @@ -31,28 +31,6 @@ class ParserTest < MiniTest::Test #puts is.inspect assert_equal @parse_output , is end - def test_number - @input = '42 ' - @parse_output = {:integer => '42'} - @parser = @parser.integer - check - end - - def test_name - @input = 'foo ' - @parse_output = {:name => 'foo'} - @parser = @parser.name - check - end - - def test_string - @input = <"hello"} - @parser = @parser.string - check - end def test_one_argument @input = '(42)' diff --git a/test/test_transform.rb b/test/test_transform.rb index 2f5ec275..d8fefb73 100644 --- a/test/test_transform.rb +++ b/test/test_transform.rb @@ -13,24 +13,6 @@ class TransformTest < MiniTest::Test #puts is.transform assert_equal @transform_output , is end - def test_number - @input = {:integer => '42'} - @transform_output = Parser::IntegerExpression.new(42) - check - assert_equal 42 , @transform_output.value - end - - def test_name - @input = {:name => 'foo'} - @transform_output = Parser::NameExpression.new('foo') - check - end - - def test_string - @input = {:string=>"hello"} - @transform_output = Parser::StringExpression.new('hello') - check - end def test_argument_list @input = {:argument_list => [{:argument => {:integer => '42'}},