folds all basic tests into new directory

This commit is contained in:
Torsten Ruger 2014-04-29 13:50:07 +03:00
parent 2507251f75
commit b6e08faa39
5 changed files with 50 additions and 68 deletions

View File

@ -10,20 +10,20 @@ module ParserTest
def check_parse def check_parse
is = @parser.parse(@input) is = @parser.parse(@input)
#puts is.inspect #puts is.inspect
assert_equal @expected , is assert_equal @parse_output , is
end end
def check_transform def check_transform
is = @transform.apply @input is = @transform.apply @parse_output
#puts is.transform #puts is.transform
assert_equal @expected , is assert_equal @transform_output , is
end end
def check_ast def check_ast
syntax = @parser.parse(@input) syntax = @parser.parse(@input)
tree = @transform.apply(syntax) tree = @transform.apply(syntax)
# puts tree.inspect # puts tree.inspect
assert_equal @expected , tree assert_equal @transform_output , tree
end end
end end

45
test/parser/test_basic.rb Normal file
View File

@ -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 = <<HERE
"hello"
HERE
@parse_output = {:string=>"hello"}
@transform_output = Parser::StringExpression.new('hello')
@parser = @parser.string
end
end

View File

@ -18,29 +18,6 @@ class TestAst < MiniTest::Test
assert_equal @transform_output , tree assert_equal @transform_output , tree
end 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 = <<HERE
"hello"
HERE
@transform_output = Parser::StringExpression.new('hello')
@parser = @parser.string
check
end
def test_one_argument def test_one_argument
@input = '(42)' @input = '(42)'
@transform_output = { :argument_list => Parser::IntegerExpression.new(42) } @transform_output = { :argument_list => Parser::IntegerExpression.new(42) }

View File

@ -31,28 +31,6 @@ class ParserTest < MiniTest::Test
#puts is.inspect #puts is.inspect
assert_equal @parse_output , is assert_equal @parse_output , is
end 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 = <<HERE
"hello"
HERE
@parse_output = {:string=>"hello"}
@parser = @parser.string
check
end
def test_one_argument def test_one_argument
@input = '(42)' @input = '(42)'

View File

@ -13,24 +13,6 @@ class TransformTest < MiniTest::Test
#puts is.transform #puts is.transform
assert_equal @transform_output , is assert_equal @transform_output , is
end 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 def test_argument_list
@input = {:argument_list => [{:argument => {:integer => '42'}}, @input = {:argument_list => [{:argument => {:integer => '42'}},