move stashed tests

This commit is contained in:
Torsten Ruger 2016-12-10 18:06:57 +02:00
parent f688611416
commit efca5254f4
10 changed files with 117 additions and 149 deletions

View File

@ -1,75 +0,0 @@
require_relative 'helper'
module Register
class TestReturnStatement < MiniTest::Test
include Statements
def test_return_int
@string_input = <<HERE
class Space
int main()
return 5
end
end
HERE
@expect = [Label, LoadConstant ,SetSlot,Label,FunctionReturn]
check
end
def test_return_local
@string_input = <<HERE
class Space
int main()
int runner
return runner
end
end
HERE
@expect = [Label, GetSlot,GetSlot ,SetSlot,Label,FunctionReturn]
check
end
def test_return_local_assign
@string_input = <<HERE
class Space
int main()
int runner = 5
return runner
end
end
HERE
@expect = [Label, LoadConstant,GetSlot,SetSlot,GetSlot,GetSlot ,SetSlot,
Label,FunctionReturn]
check
end
def pest_return_space_length # need to add runtime first
@string_input = <<HERE
class Space
int main()
Type l = space.get_type()
return self.runner
end
end
HERE
@expect = [Label, GetSlot,GetSlot ,SetSlot,Label,FunctionReturn]
check
end
def test_return_call
@string_input = <<HERE
class Space
int main()
return main()
end
end
HERE
@expect = [Label, GetSlot, GetSlot, SetSlot, LoadConstant, SetSlot, LoadConstant ,
SetSlot, LoadConstant, SetSlot, RegisterTransfer, FunctionCall, Label, RegisterTransfer ,
GetSlot, GetSlot, SetSlot, Label, FunctionReturn]
check
end
end
end

View File

@ -1,19 +1,24 @@
require_relative '../../helper'
require_relative '../helper'
module Statements
include AST::Sexp
def check
machine = Register.machine
machine.boot unless machine.booted
machine.parse_and_compile @string_input
produced = Register.machine.space.get_main.instructions
assert @expect , "No output given"
#assert_equal @expect.length , produced.instructions.length , "instructions length #{produced.instructions.to_ac}"
Register.machine.boot # force boot to reset main
compiler = Typed::Compiler.new Register.machine.space.get_main
produced = compiler.process( Typed.ast_to_code( @input) )
assert_nil produced.first , "Statements should result in nil"
produced = Register.machine.space.get_main.instructions
compare_instructions produced , @expect
produced
end
def as_main(statements)
s(:statements, s(:class, :Space, s(:derives, nil), statements ))
end
def compare_instructions instruction , expect
index = 0
start = instruction

View File

@ -8,34 +8,25 @@ class TestAssignStatement < MiniTest::Test
Register.machine.boot
end
def test_assign_op
@string_input = <<HERE
class Space
int main()
int n = 10 + 1
end
end
HERE
def _test_assign_op
@input = s(:statements, s(:field_def, :Integer, s(:name, :n),
s(:operator_value, :+, s(:int, 10), s(:int, 1))))
@expect = [Label, LoadConstant, LoadConstant, OperatorInstruction, GetSlot, SetSlot, Label ,
FunctionReturn]
check
end
def test_assign_local
@string_input = <<HERE
class Space
int main()
int runner
runner = 5
end
end
HERE
@expect = [Label, LoadConstant, GetSlot, SetSlot, Label, FunctionReturn]
check
def _test_assign_local
@input = s(:statements, s(:field_def, :Integer, s(:name, :runner)),
s(:assignment, s(:name, :runner), s(:int, 5)))
@expect = [Label, LoadConstant, GetSlot, SetSlot, Label, FunctionReturn]
check
end
def test_assign_local_assign
@string_input = <<HERE
def _test_assign_local_assign
@input = <<HERE
class Space
int main()
int runner = 5
@ -46,8 +37,8 @@ HERE
check
end
def test_assign_call
@string_input = <<HERE
def _test_assign_call
@input = <<HERE
class Space
int main()
int r = main()
@ -60,8 +51,8 @@ HERE
check
end
def test_frame_get
@string_input = <<HERE
def _test_frame_get
@input = <<HERE
class Space
int main()
int r = 5
@ -77,24 +68,8 @@ HERE
assert_equal 4, get.index , "Get to frame index must be offset, not #{get.index}"
end
def test_assign_arg
Register.machine.space.get_main.arguments.push Parfait::Variable.new(:Integer , :blar)
@string_input = <<HERE
class Space
int main(int blar)
blar = 5
end
end
HERE
@expect = [Label, LoadConstant, SetSlot, Label, FunctionReturn]
was = check
set = was.next(2)
assert_equal SetSlot , set.class
assert_equal 10, set.index , "Set to args index must be offset, not #{set.index}"
end
def test_assign_int
@string_input = <<HERE
def _test_assign_int
@input = <<HERE
class Space
int main()
int r = 5
@ -108,10 +83,26 @@ HERE
assert_equal 4, set.index , "Set to frame index must be offset, not #{set.index}"
end
def test_arg_get
def _test_assign_arg
Register.machine.space.get_main.arguments.push Parfait::Variable.new(:Integer , :blar)
@input = <<HERE
class Space
int main(int blar)
blar = 5
end
end
HERE
@expect = [Label, LoadConstant, SetSlot, Label, FunctionReturn]
was = check
set = was.next(2)
assert_equal SetSlot , set.class
assert_equal 10, set.index , "Set to args index must be offset, not #{set.index}"
end
def _test_arg_get
# have to define bar externally, just because redefining main. Otherwise that would be automatic
Register.machine.space.get_main.arguments.push Parfait::Variable.new(:Integer , :balr)
@string_input = <<HERE
@input = <<HERE
class Space
int main(int balr)
return balr

View File

@ -1,11 +1,11 @@
require_relative 'helper'
module Register
class TestCallStatement < MiniTest::Test
class TestCallStatement #< MiniTest::Test
include Statements
def test_call_constant_int
@string_input = <<HERE
@input = <<HERE
class Integer
int putint()
return 1
@ -25,7 +25,7 @@ HERE
def test_call_constant_string
@string_input = <<HERE
@input = <<HERE
class Word
int putstring()
return 1
@ -44,7 +44,7 @@ HERE
end
def test_call_local_int
@string_input = <<HERE
@input = <<HERE
class Integer
int putint()
return 1
@ -65,7 +65,7 @@ HERE
end
def test_call_local_class
@string_input = <<HERE
@input = <<HERE
class List < Object
int add()
return 1
@ -85,7 +85,7 @@ HERE
end
def test_call_puts
@string_input = <<HERE
@input = <<HERE
class Space
int puts(Word str)
return str

View File

@ -1,11 +1,11 @@
require_relative 'helper'
module Register
class TestClassStatements < MiniTest::Test
class TestClassStatements #< MiniTest::Test
include Statements
def test_class_defs
@string_input = <<HERE
@input = <<HERE
class Bar
int self.buh()
return 1
@ -22,7 +22,7 @@ HERE
end
def test_class_call
@string_input = <<HERE
@input = <<HERE
class Bar
int self.buh()
return 1
@ -41,7 +41,7 @@ HERE
end
def test_class_field
@string_input = <<HERE
@input = <<HERE
class Space
field int boo2
int main()

View File

@ -2,11 +2,11 @@ require_relative 'helper'
module Register
class TestFieldStatement < MiniTest::Test
class TestFieldStatement #< MiniTest::Test
include Statements
def test_field_frame
@string_input = <<HERE
@input = <<HERE
class Space
int main()
Message m
@ -19,7 +19,7 @@ HERE
end
def test_field_arg
@string_input = <<HERE
@input = <<HERE
class Space
int get_name(Message main)
return main.name
@ -38,7 +38,7 @@ HERE
end
def test_self_field
@string_input = <<HERE
@input = <<HERE
class Space
int main()
Type l = self.type
@ -52,7 +52,7 @@ HERE
end
def test_message_field
@string_input = <<HERE
@input = <<HERE
class Space
int main()
Word name = message.name

View File

@ -1,11 +1,11 @@
require_relative 'helper'
module Register
class TestIfStatement < MiniTest::Test
class TestIfStatement #< MiniTest::Test
include Statements
def test_if_basicr
@string_input = <<HERE
@input = <<HERE
class Space
int main()
if_plus( 10 - 12)
@ -24,7 +24,7 @@ HERE
def test_if_small_minus
@string_input = <<HERE
@input = <<HERE
class Space
int main()
if_minus( 10 - 12)
@ -40,7 +40,7 @@ HERE
def test_if_small_zero
@string_input = <<HERE
@input = <<HERE
class Space
int main()
if_zero( 10 - 12)

View File

@ -0,0 +1,47 @@
require_relative 'helper'
module Register
class TestReturnStatement < MiniTest::Test
include Statements
def test_return_int
@input = s(:statements, s(:return, s(:int, 5)))
@expect = [Label, LoadConstant ,SetSlot,Label,FunctionReturn]
check
end
def test_return_local
@input = s(:statements,s(:field_def, :Integer, s(:name, :runner)),
s(:return, s(:name, :runner)))
@expect = [Label, GetSlot,GetSlot ,SetSlot,Label,FunctionReturn]
check
end
def test_return_local_assign
@input = s(:statements, s(:field_def, :Integer, s(:name, :runner), s(:int, 5)),
s(:return, s(:name, :runner)))
@expect = [Label, LoadConstant,GetSlot,SetSlot,GetSlot,GetSlot ,SetSlot,
Label,FunctionReturn]
check
end
def test_return_call
@input = s(:statements, s(:return, s(:call, s(:name, :main), s(:arguments))))
@expect = [Label, GetSlot, GetSlot, SetSlot, LoadConstant, SetSlot, LoadConstant ,
SetSlot, LoadConstant, SetSlot, RegisterTransfer, FunctionCall, Label, RegisterTransfer ,
GetSlot, GetSlot, SetSlot, Label, FunctionReturn]
check
end
def pest_return_space_length # need to add runtime first
@input = s(:statements, s(:field_def, :Type, s(:name, :l),
s(:call, s(:name, :get_type), s(:arguments), s(:receiver, s(:name, :space)))),
s(:return, s(:field_access,
s(:receiver, s(:name, :self)),
s(:field, s(:name, :runner)))))
@expect = [Label, GetSlot,GetSlot ,SetSlot,Label,FunctionReturn]
check
end
end
end

View File

@ -1,12 +1,12 @@
require_relative 'helper'
module Register
class TestWhile < MiniTest::Test
class TestWhile #< MiniTest::Test
include Statements
def test_while_mini
@string_input = <<HERE
@input = <<HERE
class Space
int main()
while_plus(1)
@ -21,7 +21,7 @@ HERE
end
def test_while_assign
@string_input = <<HERE
@input = <<HERE
class Space
int main()
int n = 5
@ -40,7 +40,7 @@ HERE
def test_while_return
@string_input = <<HERE
@input = <<HERE
class Space
int main()
int n = 10