add some comment and tests (but small bugs still there)

This commit is contained in:
Torsten Ruger 2014-05-14 22:34:53 +03:00
parent c9ffb78e82
commit 054f94d68b
3 changed files with 31 additions and 13 deletions

View File

@ -21,8 +21,7 @@ class TestBasic < MiniTest::Test
def test_comment def test_comment
out = "# i am a comment \n" out = "# i am a comment \n"
@string_input = out.dup #NEEDS the return, which is what delimits the comment @string_input = out.dup #NEEDS the return, which is what delimits the comment
out = out[1..-2] @parse_output = out
@parse_output = {:comment => out}
@transform_output = @parse_output #dont transform @transform_output = @parse_output #dont transform
@parser = @parser.comment @parser = @parser.comment
end end

View File

@ -23,6 +23,25 @@ HERE
end end
def test_comments
@string_input = <<HERE
def foo(x) #here
a = 0 # a == r1
b = 1 # b = r2
while(n<1) do #comment
tmp = a # r3 <- r1
a = b # r1 <- r2
b = tmp + b # r4 = r2 + r3 (r4 transient) r2 <- r4
putstring(b)
n = n - 1 #me
end #no
end #anywhere
foo( 3 ) #and more
HERE
@parse_output =[{:function_name=>{:name=>"foo"}, :parmeter_list=>[{:parmeter=>{:name=>"x"}}], :expressions=>[{:l=>{:name=>"a"}, :o=>"= ", :r=>{:integer=>"5"}}], :end=>"end"}, {:call_site=>{:name=>"foo"}, :argument_list=>[{:argument=>{:integer=>"3"}}]}]
@transform_output = [Ast::FunctionExpression.new(:foo, [Ast::NameExpression.new("x")] , [Ast::OperatorExpression.new("=", Ast::NameExpression.new("a"),Ast::IntegerExpression.new(5))] ), Ast::CallSiteExpression.new(:foo, [Ast::IntegerExpression.new(3)] )]
end
def test_fibo1 def test_fibo1
@string_input = <<HERE @string_input = <<HERE
def fibonaccit(n) def fibonaccit(n)

View File

@ -1,13 +1,13 @@
def fibonaccit(n) def fibonaccit(n) # n == r0
a = 0 a = 0 # a == r1
b = 1 b = 1 # b = r2
while( n > 1 ) do while( n > 1 ) do #BUG comment lines + comments behind function calls
tmp = a tmp = a # r3 <- r1
a = b a = b # r1 <- r2
b = tmp + b b = tmp + b # r4 = r2 + r3 (r4 transient) r2 <- r4
putstring(b) putstring(b)
n = n - 1 n = n - 1 # r2 <- 0 ???? #call ok
end end #r5 <- r0 - 1 # r0 <- r5
end end
fibonaccit( 10 ) fibonaccit( 10 )