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:
parent
f4f703975b
commit
7b1e89effb
@ -1,3 +1,5 @@
|
|||||||
|
require 'parslet/convenience'
|
||||||
|
|
||||||
module Virtual
|
module Virtual
|
||||||
# The Virtual Machine is a object based virtual machine in which ruby is implemented.
|
# The Virtual Machine is a object based virtual machine in which ruby is implemented.
|
||||||
#
|
#
|
||||||
|
@ -1,34 +1,15 @@
|
|||||||
require_relative '../helper'
|
require_relative '../helper'
|
||||||
require 'parslet/convenience'
|
|
||||||
|
|
||||||
#test the generation of code fragments.
|
# simple tests to check parsing pworks and the first classes come out right.
|
||||||
# ie parse assumes @string_input
|
#
|
||||||
# compile
|
# build up from small to check larger expressions are correct
|
||||||
# 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)
|
|
||||||
|
|
||||||
module Fragments
|
module Fragments
|
||||||
# need a code generator, for arm
|
|
||||||
def setup
|
|
||||||
@object_machine = Virtual::Machin.new "Arm"
|
|
||||||
end
|
|
||||||
|
|
||||||
def parse
|
def check
|
||||||
parser = Parser::Salama.new
|
expressions = Virtual.machine.boot.compile_main @string_input
|
||||||
syntax = parser.parse_with_debug(@string_input)
|
@expect.each_with_index do | should , i |
|
||||||
parts = Parser::Transform.new.apply(syntax)
|
assert_equal should , expressions[i].class
|
||||||
# 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
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
|
|
||||||
require_relative "test_foo"
|
require_relative "test_foo"
|
||||||
require_relative "test_functions"
|
#require_relative "test_functions"
|
||||||
require_relative "test_hello"
|
#require_relative "test_hello"
|
||||||
require_relative "test_if"
|
#require_relative "test_if"
|
||||||
require_relative "test_putint"
|
#require_relative "test_putint"
|
||||||
require_relative "test_recursive_fibo"
|
#require_relative "test_recursive_fibo"
|
||||||
require_relative "test_while_fibo"
|
#require_relative "test_while_fibo"
|
||||||
|
@ -3,18 +3,23 @@ require_relative 'helper'
|
|||||||
class TestFoo < MiniTest::Test
|
class TestFoo < MiniTest::Test
|
||||||
include Fragments
|
include Fragments
|
||||||
|
|
||||||
def test_foo
|
def test_foo2
|
||||||
@string_input = <<HERE
|
@string_input = <<HERE
|
||||||
def foo(x)
|
def foo(x)
|
||||||
a = 5
|
a = 5
|
||||||
end
|
end
|
||||||
3.foo( 4 )
|
3.foo( 4 )
|
||||||
HERE
|
HERE
|
||||||
@should = [0x0,0x40,0x2d,0xe9,0x5,0x0,0xa0,0xe3,0x0,0x80,0xbd,0xe8]
|
@expect = [Parfait::Method , Virtual::Return ]
|
||||||
@output = ""
|
check
|
||||||
parse
|
|
||||||
@target = [:Object , :foo]
|
|
||||||
write "foo"
|
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
|
def test_foo
|
||||||
|
@string_input = <<HERE
|
||||||
|
3.foo( 4 )
|
||||||
|
HERE
|
||||||
|
@expect = [Virtual::Return ]
|
||||||
|
check
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
# All working tests (ahm), still working on the others, so no use to be constantly reminded
|
# All working tests (ahm), still working on the others, so no use to be constantly reminded
|
||||||
require_relative "parfait/test_all"
|
require_relative "parfait/test_all"
|
||||||
|
|
||||||
|
require_relative "fragments/test_all"
|
||||||
|
|
||||||
require_relative "virtual/test_all"
|
require_relative "virtual/test_all"
|
||||||
|
Loading…
Reference in New Issue
Block a user