folds all basic tests into new directory
This commit is contained in:
parent
2507251f75
commit
b6e08faa39
@ -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
|
45
test/parser/test_basic.rb
Normal file
45
test/parser/test_basic.rb
Normal 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
|
@ -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 = <<HERE
|
||||
"hello"
|
||||
HERE
|
||||
@transform_output = Parser::StringExpression.new('hello')
|
||||
@parser = @parser.string
|
||||
check
|
||||
end
|
||||
|
||||
def test_one_argument
|
||||
@input = '(42)'
|
||||
@transform_output = { :argument_list => Parser::IntegerExpression.new(42) }
|
||||
|
@ -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 = <<HERE
|
||||
"hello"
|
||||
HERE
|
||||
@parse_output = {:string=>"hello"}
|
||||
@parser = @parser.string
|
||||
check
|
||||
end
|
||||
|
||||
def test_one_argument
|
||||
@input = '(42)'
|
||||
|
@ -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'}},
|
||||
|
Loading…
Reference in New Issue
Block a user