add some comment and tests (but small bugs still there)
This commit is contained in:
parent
c9ffb78e82
commit
054f94d68b
@ -21,8 +21,7 @@ class TestBasic < MiniTest::Test
|
||||
def test_comment
|
||||
out = "# i am a comment \n"
|
||||
@string_input = out.dup #NEEDS the return, which is what delimits the comment
|
||||
out = out[1..-2]
|
||||
@parse_output = {:comment => out}
|
||||
@parse_output = out
|
||||
@transform_output = @parse_output #dont transform
|
||||
@parser = @parser.comment
|
||||
end
|
||||
|
@ -22,7 +22,26 @@ HERE
|
||||
Ast::CallSiteExpression.new("foo", [Ast::IntegerExpression.new(3)] )]
|
||||
|
||||
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
|
||||
@string_input = <<HERE
|
||||
def fibonaccit(n)
|
||||
|
@ -1,13 +1,13 @@
|
||||
def fibonaccit(n)
|
||||
a = 0
|
||||
b = 1
|
||||
while( n > 1 ) do
|
||||
tmp = a
|
||||
a = b
|
||||
b = tmp + b
|
||||
putstring(b)
|
||||
n = n - 1
|
||||
end
|
||||
def fibonaccit(n) # n == r0
|
||||
a = 0 # a == r1
|
||||
b = 1 # b = r2
|
||||
while( n > 1 ) do #BUG comment lines + comments behind function calls
|
||||
tmp = a # r3 <- r1
|
||||
a = b # r1 <- r2
|
||||
b = tmp + b # r4 = r2 + r3 (r4 transient) r2 <- r4
|
||||
putstring(b)
|
||||
n = n - 1 # r2 <- 0 ???? #call ok
|
||||
end #r5 <- r0 - 1 # r0 <- r5
|
||||
end
|
||||
|
||||
fibonaccit( 10 )
|
||||
|
Loading…
Reference in New Issue
Block a user