get fragment tests back online

the 58%  REALLY doesn’t look good
and things have settle down, so no more excuses
This commit is contained in:
Torsten Ruger 2015-07-18 14:33:09 +03:00
parent f4f703975b
commit 7b1e89effb
5 changed files with 30 additions and 40 deletions

View File

@ -1,3 +1,5 @@
require 'parslet/convenience'
module Virtual
# The Virtual Machine is a object based virtual machine in which ruby is implemented.
#

View File

@ -1,34 +1,15 @@
require_relative '../helper'
require 'parslet/convenience'
#test the generation of code fragments.
# ie parse assumes @string_input
# compile
# assemble/write assume a @should array with the bytes in it
# since the bytes are store, the test can be run on any machine.
# but to get the bytes, one needs to link and run the object file to confirm correctness (to be automated)
# simple tests to check parsing pworks and the first classes come out right.
#
# build up from small to check larger expressions are correct
module Fragments
# need a code generator, for arm
def setup
@object_machine = Virtual::Machin.new "Arm"
end
def parse
parser = Parser::Salama.new
syntax = parser.parse_with_debug(@string_input)
parts = Parser::Transform.new.apply(syntax)
# file is a list of expressions, all but the last must be a function
# and the last is wrapped as a main
parts.each_with_index do |part,index|
if part.is_a? Ast::FunctionExpression
expr = part.compile( @object_machine.context )
else
puts part.inspect if part.is_a? Hash
expr = part.compile( @object_machine.context )
end
def check
expressions = Virtual.machine.boot.compile_main @string_input
@expect.each_with_index do | should , i |
assert_equal should , expressions[i].class
end
end

View File

@ -1,8 +1,8 @@
require_relative "test_foo"
require_relative "test_functions"
require_relative "test_hello"
require_relative "test_if"
require_relative "test_putint"
require_relative "test_recursive_fibo"
require_relative "test_while_fibo"
#require_relative "test_functions"
#require_relative "test_hello"
#require_relative "test_if"
#require_relative "test_putint"
#require_relative "test_recursive_fibo"
#require_relative "test_while_fibo"

View File

@ -3,18 +3,23 @@ require_relative 'helper'
class TestFoo < MiniTest::Test
include Fragments
def test_foo
def test_foo2
@string_input = <<HERE
def foo(x)
def foo(x)
a = 5
end
3.foo( 4 )
HERE
@should = [0x0,0x40,0x2d,0xe9,0x5,0x0,0xa0,0xe3,0x0,0x80,0xbd,0xe8]
@output = ""
parse
@target = [:Object , :foo]
write "foo"
@expect = [Parfait::Method , Virtual::Return ]
check
end
end
def test_foo
@string_input = <<HERE
3.foo( 4 )
HERE
@expect = [Virtual::Return ]
check
end
end

View File

@ -1,4 +1,6 @@
# All working tests (ahm), still working on the others, so no use to be constantly reminded
require_relative "parfait/test_all"
require_relative "fragments/test_all"
require_relative "virtual/test_all"