using sat gem

This commit is contained in:
Torsten Ruger
2015-09-15 12:27:54 +03:00
parent d5d26a3ac4
commit 0df098ef7d
8 changed files with 60 additions and 46 deletions

View File

@ -6,62 +6,62 @@ class TestBasic < MiniTest::Test
def test_true
@input = 'true '
@output = Ast::TrueExpression.new()
@output = s(:true)
check :keyword_true
end
def test_false
@input = 'false '
@output = Ast::FalseExpression.new()
@output = s(:false)
check :keyword_false
end
def test_nil
@input = 'nil '
@output = Ast::NilExpression.new()
@output = s(:nil)
check :keyword_nil
end
def test_integer
@input = '42 '
@output = Ast::IntegerExpression.new(42)
@output = s(:int , 42)
check :integer_expression
end
def test_name
@input = 'foo '
@output = Ast::NameExpression.new('foo')
@output = 'foo'
check :name_expression
end
def test_name_underscode_start
@input = '_bar '
@output = Ast::NameExpression.new('_bar')
@output = '_bar'
check :name_expression
end
def test_name_underscode_middle
@input = 'foo_bar '
@output = Ast::NameExpression.new('foo_bar')
@output = 'foo_bar'
check :name_expression
end
def test_module_name
@input = 'FooBar '
@output = Ast::ModuleName.new("FooBar")
check :module_name_expression
@output = s(:aspect , "FooBar")
check :aspect_name_expression
end
def test_string
@input = '"hello"'
@output = Ast::StringExpression.new('hello')
@output = s(:string , 'hello')
check :string_expression
end
def test_string_escapes
out = 'hello \nyou'
@input = '"' + out + '"'
@output = Ast::StringExpression.new(out)
@output = s(:string , out)
check :string_expression
end

View File

@ -5,38 +5,38 @@ class TestCallSite < MiniTest::Test
def test_single_self
@input = 'self.foo(42)'
@output = Ast::CallSiteExpression.new(Ast::FieldExpression.new(Ast::NameExpression.new(:self),:foo), [Ast::IntegerExpression.new(42)] )
@output = s(:call, s(:field , "self" , "foo") , [s(:int, 42)])
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(Ast::FieldExpression.new(Ast::NameExpression.new(:my_my),:foo), [Ast::IntegerExpression.new(42)] )
@output = s(:call, s(:field, "my_my", "foo"), [s(:int, 42)])
check :call_site
end
def test_int_receiver
@input = '42.put()'
@output = Ast::CallSiteExpression.new(Ast::FieldExpression.new(Ast::IntegerExpression.new(42),:put), [] )
@output = s(:call, s(:field, s(:int , 42) , "put") , [])
check :call_site
end
def test_string_receiver
@input = '"hello".puts()'
@output = Ast::CallSiteExpression.new(Ast::FieldExpression.new(Ast::StringExpression.new("hello"),:puts), [] )
@output = s(:call , s(:field , s(:string , "hello") , "puts") , [])
check :call_site
end
def test_call_site_2
@input = 'self.baz(42, foo)'
@output = Ast::CallSiteExpression.new(Ast::FieldExpression.new(Ast::NameExpression.new(:self),:baz), [Ast::IntegerExpression.new(42),Ast::NameExpression.new(:foo)] )
@output = s(:call ,s(:field , "self", "baz") , [s(:int, 42), "foo"])
check :call_site
end
def test_call_site_3
@input = 'self.baz(42, foo , bar)'
@output = Ast::CallSiteExpression.new(Ast::FieldExpression.new(Ast::NameExpression.new(:self),:baz), [Ast::IntegerExpression.new(42),Ast::NameExpression.new(:foo),Ast::NameExpression.new(:bar)] )
@output = s(:call, s(:field, "self", "baz"), [s(:int, 42), "foo", "bar"])
check :call_site
end

View File

@ -5,19 +5,19 @@ class TestConditional < MiniTest::Test
def test_assignment
@input = "myvar = 42"
@output = Ast::AssignmentExpression.new(:myvar,Ast::IntegerExpression.new(42))
@output = s(:assign, :myvar, s(:int, 42))
check :assignment
end
def test_variable_declaration
@input = "int myvar"
@output = Ast::VariableDefinition.new(:int,:myvar,nil)
@output = s(:variable,s(:type, "int", "myvar"), nil)
check :variable_definition
end
def test_variable_declaration_value
@input = "int myvar = 42"
@output = Ast::VariableDefinition.new(:int,:myvar,Ast::IntegerExpression.new(42))
@output = s(:variable, s(:type, "int", "myvar"), s(:int, 42))
check :variable_definition
end
@ -27,7 +27,9 @@ if( 1 )
int num = 42
end
HERE
@output = Ast::IfExpression.new(Ast::IntegerExpression.new(1), [Ast::VariableDefinition.new(:int,:num,Ast::IntegerExpression.new(42))],nil)
@output = s(:if, s(:cond, s(:int, 1)), s(:then, [s(:variable,
s(:type, "int", "num"),
s(:int, 42))]))
check :conditional
end
@ -37,7 +39,9 @@ if(var)
42.add(5)
end
HERE
@output = Ast::IfExpression.new(Ast::NameExpression.new(:var), [Ast::CallSiteExpression.new(Ast::FieldExpression.new(Ast::IntegerExpression.new(42),:add), [Ast::IntegerExpression.new(5)] )],nil)
@output = s(:if,
s(:cond, "var"),
s(:then, [s(:call, s(:field, s(:int, 42), "add"), [s(:int, 5)])]))
check :conditional
end
@ -51,7 +55,7 @@ end
HERE
@input.chop!
@parse_output = {:if=>"if", :conditional=>{:l=>{:integer=>"3"}, :o=>"== ", :r=>{:nil=>"nil"}}, :if_true=>{:expressions=>[{:integer=>"3"}], :else=>"else"}, :if_false=>{:expressions=>[{:integer=>"4"}], :end=>"end"}}
@output = Ast::IfExpression.new(Ast::OperatorExpression.new("==", Ast::IntegerExpression.new(3),Ast::NilExpression.new()), [Ast::IntegerExpression.new(3)],[Ast::IntegerExpression.new(4)] )
@output = nil
@root = :conditional
end
@ -63,7 +67,7 @@ end
HERE
@input.chop!
@parse_output = {:if=>"if", :conditional=>{:l=>{:integer=>"3"}, :o=>"== ", :r=>{:nil=>"nil"}}, :if_true=>{:expressions=>[{:integer=>"3"}], :else=>"else"}, :if_false=>{:expressions=>[{:integer=>"4"}], :end=>"end"}}
@output = Ast::IfExpression.new(Ast::OperatorExpression.new("==", Ast::IntegerExpression.new(3),Ast::NilExpression.new()), [Ast::IntegerExpression.new(3)],[Ast::IntegerExpression.new(4)] )
@output = nil
@root = :conditional
end