rearranging tests a little

This commit is contained in:
Torsten Ruger
2015-07-19 10:54:36 +03:00
parent ac9d5eaf5a
commit 7451493193
11 changed files with 39 additions and 34 deletions

View File

@ -1,3 +1,4 @@
require_relative "test_basic"
require_relative "test_methods"
require_relative "test_compat"
require_relative "test_padding"
require_relative "test_positioning"

View File

@ -1,67 +0,0 @@
require_relative "virtual_helper"
class TestBasic < MiniTest::Test
def check
expressions = Virtual.machine.boot.compile_main @string_input
if( expressions.first.is_a? Virtual::Self )
expressions.first.type.instance_variable_set :@of_class , nil
end
is = Sof.write(expressions)
#puts is
assert_equal @output , is
end
def test_number
@string_input = '42 '
@output = "- Virtual::Return(:type => Virtual::Integer, :value => 42)"
check
end
def test_true
@string_input = 'true '
@output = "- Virtual::Return(:type => Virtual::Reference, :value => true)"
check
end
def test_false
@string_input = 'false '
@output = "- Virtual::Return(:type => Virtual::Reference, :value => false)"
check
end
def test_nil
@string_input = 'nil '
@output = "- Virtual::Return(:type => Virtual::Reference)"
check
end
def test_name
@string_input = 'foo '
@output = "- Virtual::Return(:type => Virtual::Unknown)"
check
end
def test_self
@string_input = 'self '
@output = "- Virtual::Self(:type => Virtual::Reference())"
check
end
def test_instance_variable
@string_input = '@foo_bar '
@output = "- Virtual::Return(:type => Virtual::Unknown)"
check
end
def pest_module_name
@string_input = 'FooBar '
@output = ""
check
end
def test_string
@string_input = "\"hello\""
@output = "- Virtual::Return(:type => Virtual::Reference, :value => :hello)"
check
end
end

View File

@ -1,40 +0,0 @@
require_relative "virtual_helper"
class HelloTest < MiniTest::Test
include VirtualHelper
def check
machine = Virtual::Machine.boot
expressions = machine.compile_main @string_input
output_at = "Register::CallImplementation"
#{}"Register::CallImplementation"
machine.run_before output_at
#puts Sof.write(machine.space)
machine.run_after output_at
writer = Elf::ObjectWriter.new(machine)
writer.save "hello.o"
end
def qtest_simplest_function
@string_input = <<HERE
def foo(x)
5
end
HERE
check
end
def ttest_puts_string
@string_input = <<HERE
putstring("Hello")
HERE
check
end
def test_string_put
@string_input = <<HERE
"Hello again\n".putstring()
HERE
check
end
end

View File

@ -1,7 +1,7 @@
require_relative "virtual_helper"
require_relative "compiler_helper"
class TestMethods < MiniTest::Test
include VirtualHelper
class TestMachine < MiniTest::Test
include CompilerHelper
def test_object
@string_input = <<HERE

View File

@ -1,188 +0,0 @@
require_relative "virtual_helper"
module Virtual
class TestMethods < MiniTest::Test
def check
Virtual.machine.boot.compile_main @string_input
produced = Virtual.machine.space.get_main.source
assert @output , "No output given"
assert_equal @output.length , produced.blocks.length , "Block length"
produced.blocks.each_with_index do |b,i|
codes = @output[i]
assert codes , "No codes for block #{i}"
assert_equal b.codes.length , codes.length , "Code length for block #{i}"
b.codes.each_with_index do |c , ii |
assert_equal codes[ii] , c.class , "Block #{i} , code #{ii}"
end
end
end
def test_module
@string_input = <<HERE
class Some
def foo()
5
end
end
HERE
@output = [[MethodEnter] ,[MethodReturn]]
check
end
def test_simplest_function
@string_input = <<HERE
def foo(x)
5
end
HERE
@output = [[MethodEnter] ,[MethodReturn]]
check
end
def ttest_second_simplest_function
@string_input = <<HERE
def foo(x)
x
end
HERE
@output = [[1,2,3,4],[],[],[]]
check
end
def ttest_puts_string
@string_input = <<HERE
def foo()
puts("Hello")
end
foo()
HERE
@output = nil
check
end
def ttest_class_function
@string_input = <<HERE
def String.length(x)
@length
end
HERE
@output = nil
check
end
def ttest_function_ops
@string_input = <<HERE
def foo(x)
abba = 5
2 + 5
end
HERE
@output = nil
check
end
def ttest_function_ops_simple
@string_input = <<HERE
def foo()
2 + 5
end
HERE
@output = nil
check
end
def ttest_function_if
@string_input = <<HERE
def ofthen(n)
if(0)
isit = 42
else
maybenot = 667
end
end
HERE
@output = nil
check
end
def test_while
@string_input = <<HERE
while(1) do
3
end
HERE
@output = [[MethodEnter],[Set,IsTrueBranch,Set,UnconditionalBranch],[],[MethodReturn]]
check
end
def ttest_function_while
@string_input = <<HERE
def fibonaccit(n)
a = 0
while (n) do
some = 43
other = some * 4
end
end
HERE
@output = nil
check
end
def pest_function_return
@string_input = <<HERE
def retvar(n)
i = 5
return i
end
HERE
@output = ""
check
end
def pest_function_return_if
@string_input = <<HERE
def retvar(n)
if( n > 5)
return 10
else
return 20
end
end
HERE
@output = ""
check
end
def est_function_return_while
@string_input = <<HERE
def retvar(n)
while( n > 5) do
n = n + 1
return n
end
end
HERE
@output = ""
check
end
def pest_function_big_while
@string_input = <<HERE
def fibonaccit(n)
a = 0
b = 1
while( n > 1 ) do
tmp = a
a = b
b = tmp + b
puts(b)
n = n - 1
end
end
HERE
@output = ""
check
end
end
end

View File

@ -19,28 +19,9 @@ class TestPadding < MiniTest::Test
assert_equal 64 , @pad.padded(p) , "Expecting 64 for #{p}"
end
end
def test_large
[58,88].each do |p|
assert_equal 96 , @pad.padded(p) , "Expecting 96 for #{p}"
end
end
end
class TestPositioning < MiniTest::Test
def test_list1
list = Virtual.new_list([1])
list.set_layout( Parfait::Layout.new Object)
assert_equal 32 , list.word_length
end
def test_list5
list = Virtual.new_list([1,2,3,4,5])
list.set_layout( Parfait::Layout.new Object)
assert_equal 32 , list.word_length
end
def test_layout
layout = Parfait::Layout.new Object
layout.set_layout( Parfait::Layout.new Object)
layout.push 5
assert_equal 32 , layout.word_length
def test_large
[58,88].each do |p|
assert_equal 96 , @pad.padded(p) , "Expecting 96 for #{p}"
end
end
end

View File

@ -0,0 +1,20 @@
require_relative "../helper"
class TestPositioning < MiniTest::Test
def test_list1
list = Virtual.new_list([1])
list.set_layout( Parfait::Layout.new Object)
assert_equal 32 , list.word_length
end
def test_list5
list = Virtual.new_list([1,2,3,4,5])
list.set_layout( Parfait::Layout.new Object)
assert_equal 32 , list.word_length
end
def test_layout
layout = Parfait::Layout.new Object
layout.set_layout( Parfait::Layout.new Object)
layout.push 5
assert_equal 32 , layout.word_length
end
end

View File

@ -1,39 +0,0 @@
require_relative '../helper'
require 'parslet/convenience'
module VirtualHelper
def check
Virtual.machine.boot.compile_main @string_input
produced = Virtual.machine.space.get_main.source
assert_equal @output , produced
end
end
class UnusedSofEquality
# simple thought: don't recurse for Blocks, just check their names
def == other
return false unless other.class == self.class
Sof::Util.attributes(self).each do |a|
begin
left = send(a)
rescue NoMethodError
next # not using instance variables that are not defined as attr_readers for equality
end
begin
right = other.send(a)
rescue NoMethodError
return false
end
return false unless left.class == right.class
if( left.is_a? Block)
return false unless left.name == right.name
else
return false unless left == right
end
end
return true
end
end