From 7b1e89effb607ca4ed86a0fee859495b6008053a Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Sat, 18 Jul 2015 14:33:09 +0300 Subject: [PATCH] get fragment tests back online MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit the 58% REALLY doesn’t look good and things have settle down, so no more excuses --- lib/virtual/machine.rb | 2 ++ test/fragments/helper.rb | 33 +++++++-------------------------- test/fragments/test_all.rb | 12 ++++++------ test/fragments/test_foo.rb | 21 +++++++++++++-------- test/test_all.rb | 2 ++ 5 files changed, 30 insertions(+), 40 deletions(-) diff --git a/lib/virtual/machine.rb b/lib/virtual/machine.rb index 0213a761..2835196f 100644 --- a/lib/virtual/machine.rb +++ b/lib/virtual/machine.rb @@ -1,3 +1,5 @@ +require 'parslet/convenience' + module Virtual # The Virtual Machine is a object based virtual machine in which ruby is implemented. # diff --git a/test/fragments/helper.rb b/test/fragments/helper.rb index 8f8467df..630688af 100644 --- a/test/fragments/helper.rb +++ b/test/fragments/helper.rb @@ -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 diff --git a/test/fragments/test_all.rb b/test/fragments/test_all.rb index 79f7679c..11e59993 100644 --- a/test/fragments/test_all.rb +++ b/test/fragments/test_all.rb @@ -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" diff --git a/test/fragments/test_foo.rb b/test/fragments/test_foo.rb index b9f542db..55a20368 100644 --- a/test/fragments/test_foo.rb +++ b/test/fragments/test_foo.rb @@ -3,18 +3,23 @@ require_relative 'helper' class TestFoo < MiniTest::Test include Fragments - def test_foo + def test_foo2 @string_input = <