From 418640593093379bc7ad610eaed542019ec4bf4f Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Sun, 27 Sep 2015 22:39:10 +0300 Subject: [PATCH] new i_to_s test --- lib/virtual/machine.rb | 2 +- test/interpreter/helper.rb | 11 ++++++++ test/interpreter/test_add.rb | 18 +++++-------- test/interpreter/test_puti.rb | 48 +++++++++++++++++++++++++++++++++++ test/interpreter/test_puts.rb | 11 ++------ 5 files changed, 68 insertions(+), 22 deletions(-) create mode 100644 test/interpreter/test_puti.rb diff --git a/lib/virtual/machine.rb b/lib/virtual/machine.rb index f6c7018c..2d9959c2 100644 --- a/lib/virtual/machine.rb +++ b/lib/virtual/machine.rb @@ -135,7 +135,7 @@ module Virtual def compile_main bytes syntax = @parser.parse_with_debug(bytes) parts = Parser::Transform.new.apply(syntax) - #puts parts.to_s + #puts parts.inspect Bosl::Compiler.compile( parts , @space.get_main ) end diff --git a/test/interpreter/helper.rb b/test/interpreter/helper.rb index a6946d19..e49e784a 100644 --- a/test/interpreter/helper.rb +++ b/test/interpreter/helper.rb @@ -1,2 +1,13 @@ require_relative "../helper" require "interpreter/interpreter" + +module Ticker + def ticks num + last = nil + num.times do + last = @interpreter.instruction + @interpreter.tick + end + return last + end +end diff --git a/test/interpreter/test_add.rb b/test/interpreter/test_add.rb index fea397bd..27bafdb7 100644 --- a/test/interpreter/test_add.rb +++ b/test/interpreter/test_add.rb @@ -2,6 +2,8 @@ require_relative "helper" class AddTest < MiniTest::Test include AST::Sexp + include Ticker + def setup Virtual.machine.boot code = s(:call, @@ -14,15 +16,6 @@ class AddTest < MiniTest::Test @interpreter.start Virtual.machine.init end - def ticks num - last = nil - num.times do - last = @interpreter.instruction - @interpreter.tick - end - return last - end - def test_branch was = @interpreter.block assert_equal Register::Branch , ticks(1).class @@ -47,7 +40,7 @@ class AddTest < MiniTest::Test assert_equal Register::FunctionCall , ticks(7).class assert @interpreter.link end - def ttest_adding + def test_adding done = ticks(23) assert_equal Register::OperatorInstruction , done.class left = @interpreter.get_register(done.left) @@ -55,11 +48,12 @@ class AddTest < MiniTest::Test right = @interpreter.get_register(rr) assert_equal Fixnum , left.class assert_equal Fixnum , right.class - assert_equal 5 , right + assert_equal 16 , right + assert_equal 8 , left done = ticks(1) assert_equal Register::RegisterTransfer , done.class result = @interpreter.get_register(rr) - assert_equal result , left + right + assert_equal result , 16 end def test_chain diff --git a/test/interpreter/test_puti.rb b/test/interpreter/test_puti.rb new file mode 100644 index 00000000..528f95c3 --- /dev/null +++ b/test/interpreter/test_puti.rb @@ -0,0 +1,48 @@ +require_relative "helper" + +class AddTest < MiniTest::Test + include Ticker + + def test_puti + @string_input = <