unify grammar file
This commit is contained in:
@ -1,16 +1,8 @@
|
||||
require_relative "../setup"
|
||||
require_relative "../parser_helper"
|
||||
|
||||
class TestBasic < MiniTest::Test
|
||||
#test basics and keyword expressions. Keywords includes BasicTypes
|
||||
def setup
|
||||
@parser = BasicTypes
|
||||
end
|
||||
|
||||
def check rule = :root
|
||||
parse = @parser.parse(@input , :root => rule)
|
||||
assert_equal @input , parse
|
||||
assert_equal @output , parse.value
|
||||
end
|
||||
include ParserHelper
|
||||
|
||||
def test_true
|
||||
@input = 'true '
|
||||
|
@ -1,39 +1,31 @@
|
||||
require_relative "../parser_helper"
|
||||
|
||||
class TestCallSite < MiniTest::Test
|
||||
|
||||
def setup
|
||||
@parser = Expression
|
||||
end
|
||||
def check
|
||||
parse = @parser.parse(@input)
|
||||
assert_equal @input , parse
|
||||
assert_equal @output , parse.value
|
||||
end
|
||||
include ParserHelper
|
||||
|
||||
def test_single_self
|
||||
@input = 'self.foo(42)'
|
||||
@output = Ast::CallSiteExpression.new :foo, [Ast::IntegerExpression.new(42)]
|
||||
check
|
||||
check :call_site
|
||||
end
|
||||
|
||||
def test_single_name
|
||||
@input = 'my_my.foo(42)'
|
||||
@parse_output = {:receiver=>{:name=>"my_my"}, :call_site=>{:name=>"foo"}, :argument_list=>[{:argument=>{:integer=>"42"}}]}
|
||||
@output = Ast::CallSiteExpression.new(:foo, [Ast::IntegerExpression.new(42)] ,Ast::NameExpression.new("my_my"))
|
||||
check
|
||||
check :call_site
|
||||
end
|
||||
|
||||
def test_int_receiver
|
||||
@input = '42.put()'
|
||||
@output = Ast::CallSiteExpression.new(:put, [] ,Ast::IntegerExpression.new(42))
|
||||
check
|
||||
check :call_site
|
||||
end
|
||||
|
||||
def test_string_receiver
|
||||
@input = '"hello".puts()'
|
||||
@output = Ast::CallSiteExpression.new(:puts, [] ,Ast::StringExpression.new("hello"))
|
||||
check
|
||||
check :call_site
|
||||
end
|
||||
|
||||
def test_call_site_2
|
||||
@ -41,7 +33,7 @@ class TestCallSite < MiniTest::Test
|
||||
@output = Ast::CallSiteExpression.new :baz,
|
||||
[Ast::IntegerExpression.new(42), Ast::NameExpression.new("foo") ] ,
|
||||
Ast::NameExpression.new(:self)
|
||||
check
|
||||
check :call_site
|
||||
end
|
||||
|
||||
def test_call_site_3
|
||||
@ -51,7 +43,7 @@ class TestCallSite < MiniTest::Test
|
||||
Ast::NameExpression.new("foo") ,
|
||||
Ast::NameExpression.new("bar")] ,
|
||||
Ast::NameExpression.new(:self)
|
||||
check
|
||||
check :call_site
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -1,33 +1,24 @@
|
||||
require_relative "../parser_helper"
|
||||
|
||||
class TestConditional < MiniTest::Test
|
||||
|
||||
def setup
|
||||
@parser = Statement
|
||||
end
|
||||
|
||||
def check
|
||||
parse = @parser.parse(@input)
|
||||
assert_equal @input , parse
|
||||
assert_equal @output , parse.value
|
||||
end
|
||||
include ParserHelper
|
||||
|
||||
def test_assignment
|
||||
@input = "myvar = 42"
|
||||
@output = Ast::AssignmentExpression.new(:myvar,Ast::IntegerExpression.new(42))
|
||||
check
|
||||
check :assignment
|
||||
end
|
||||
|
||||
def test_variable_declaration
|
||||
@input = "int myvar"
|
||||
@output = Ast::VariableDefinition.new(:int,:myvar,nil)
|
||||
check
|
||||
check :variable_definition
|
||||
end
|
||||
|
||||
def test_variable_declaration_value
|
||||
@input = "int myvar = 42"
|
||||
@output = Ast::VariableDefinition.new(:int,:myvar,Ast::IntegerExpression.new(42))
|
||||
check
|
||||
check :variable_definition
|
||||
end
|
||||
|
||||
def test_if
|
||||
@ -37,7 +28,7 @@ if( 1 )
|
||||
end
|
||||
HERE
|
||||
@output = Ast::IfExpression.new(Ast::IntegerExpression.new(1), [Ast::VariableDefinition.new(:int,:num,Ast::IntegerExpression.new(42))],nil )
|
||||
check
|
||||
check :conditional
|
||||
end
|
||||
|
||||
def ttest_conditional_with_calls
|
||||
|
Reference in New Issue
Block a user