rename layout to type
this one goes to caleb for pointing it out. Much better word
This commit is contained in:
@ -1,7 +1,7 @@
|
||||
require_relative "test_attributes"
|
||||
require_relative "test_class"
|
||||
require_relative "test_dictionary"
|
||||
require_relative "test_layout"
|
||||
require_relative "test_type"
|
||||
require_relative "test_list"
|
||||
require_relative "test_message"
|
||||
require_relative "test_meta"
|
||||
|
@ -4,19 +4,19 @@ class TestAttributes < MiniTest::Test
|
||||
|
||||
def setup
|
||||
@mess = Register.machine.boot.space.first_message
|
||||
@layout = @mess.get_layout
|
||||
@type = @mess.get_type
|
||||
end
|
||||
|
||||
def test_message_get_layout
|
||||
assert_equal Parfait::Layout , @layout.class
|
||||
def test_message_get_type
|
||||
assert_equal Parfait::Type , @type.class
|
||||
end
|
||||
def test_message_layout_first
|
||||
@layout.object_class = :next_message
|
||||
assert_equal :layout , @layout.instance_names.first
|
||||
assert_equal :next_message , @layout.object_class
|
||||
def test_message_type_first
|
||||
@type.object_class = :next_message
|
||||
assert_equal :type , @type.instance_names.first
|
||||
assert_equal :next_message , @type.object_class
|
||||
end
|
||||
def test_message_name_nil
|
||||
last = @layout.instance_names.last
|
||||
last = @type.instance_names.last
|
||||
assert_equal :indexed_length , last
|
||||
assert_equal nil , @mess.name
|
||||
end
|
||||
@ -24,26 +24,26 @@ class TestAttributes < MiniTest::Test
|
||||
@mess.next_message = :next_message
|
||||
assert_equal :next_message , @mess.next_message
|
||||
end
|
||||
def test_message_layout_set
|
||||
@mess.set_layout :layout
|
||||
assert_equal :layout , @mess.get_layout
|
||||
def test_message_type_set
|
||||
@mess.set_type :type
|
||||
assert_equal :type , @mess.get_type
|
||||
end
|
||||
def test_attribute_index
|
||||
@mess.next_message = :message
|
||||
assert_equal Parfait::Layout , @mess.get_layout.class
|
||||
assert_equal Parfait::Type , @mess.get_type.class
|
||||
end
|
||||
def test_layout_attribute
|
||||
@layout.object_class = :message
|
||||
assert_equal :message , @layout.object_class
|
||||
def test_type_attribute
|
||||
@type.object_class = :message
|
||||
assert_equal :message , @type.object_class
|
||||
end
|
||||
def test_layout_attribute_check
|
||||
@layout.object_class = :message
|
||||
assert_equal Parfait::Layout , @layout.get_layout.class
|
||||
def test_type_attribute_check
|
||||
@type.object_class = :message
|
||||
assert_equal Parfait::Type , @type.get_type.class
|
||||
end
|
||||
def test_layout_layout
|
||||
assert_equal Parfait::Layout , @layout.get_layout.get_layout.class
|
||||
def test_type_type
|
||||
assert_equal Parfait::Type , @type.get_type.get_type.class
|
||||
end
|
||||
def test_layout_layout_layout
|
||||
assert_equal Parfait::Layout , @layout.get_layout.get_layout.get_layout.class
|
||||
def test_type_type_type
|
||||
assert_equal Parfait::Type , @type.get_type.get_type.get_type.class
|
||||
end
|
||||
end
|
||||
|
@ -12,9 +12,9 @@ class TestClass < MiniTest::Test
|
||||
::Parfait::Method.new @space.get_class_by_name(for_class) , :foo , args
|
||||
end
|
||||
|
||||
def test_layout_forclass
|
||||
assert_equal "Class(Space)" , @space.get_layout.object_class.inspect
|
||||
assert_equal :Space , @space.get_layout.object_class.name
|
||||
def test_type_forclass
|
||||
assert_equal "Class(Space)" , @space.get_type.object_class.inspect
|
||||
assert_equal :Space , @space.get_type.object_class.name
|
||||
end
|
||||
def test_new_superclass_name
|
||||
assert_equal :Object , @try.super_class_name
|
||||
|
@ -1,7 +1,7 @@
|
||||
require_relative "../helper"
|
||||
|
||||
class TestDictionary < MiniTest::Test
|
||||
Register.machine.boot #have to book, otherwise layouts etc not set
|
||||
Register.machine.boot #have to book, otherwise types etc not set
|
||||
|
||||
def setup
|
||||
@lookup = ::Parfait::Dictionary.new
|
||||
|
@ -1,130 +0,0 @@
|
||||
require_relative "../helper"
|
||||
|
||||
class TestLayout < MiniTest::Test
|
||||
|
||||
def setup
|
||||
@mess = Register.machine.boot.space.first_message
|
||||
end
|
||||
|
||||
def test_message_layout
|
||||
layout = @mess.get_layout
|
||||
assert layout
|
||||
assert @mess.instance_variable_defined :next_message
|
||||
assert_equal @mess.next_message , @mess.get_instance_variable(:next_message)
|
||||
end
|
||||
|
||||
def test_message_by_index
|
||||
assert_equal @mess.next_message , @mess.get_instance_variable(:next_message)
|
||||
index = @mess.get_layout.variable_index :next_message
|
||||
assert_equal 2 , index
|
||||
assert_equal @mess.next_message , @mess.get_internal_word(index)
|
||||
end
|
||||
|
||||
def test_layout_index
|
||||
assert_equal @mess.get_layout , @mess.get_internal_word(Parfait::LAYOUT_INDEX) , "mess"
|
||||
end
|
||||
|
||||
def test_inspect
|
||||
assert @mess.get_layout.inspect.start_with?("Layout")
|
||||
end
|
||||
def test_layout_is_first
|
||||
layout = @mess.get_layout
|
||||
assert_equal 1 , layout.variable_index(:layout)
|
||||
end
|
||||
|
||||
def test_length
|
||||
assert_equal 9 , @mess.get_layout.instance_length , @mess.get_layout.inspect
|
||||
end
|
||||
|
||||
def test_layout_length
|
||||
assert_equal 9 , @mess.get_layout.instance_length , @mess.get_layout.inspect
|
||||
assert_equal 18 , @mess.get_layout.get_internal_word(4)
|
||||
end
|
||||
|
||||
def test_layout_length_index
|
||||
assert_equal 4 , @mess.get_layout.get_layout.variable_index(:indexed_length)
|
||||
assert_equal 4 , @mess.get_layout.get_layout.get_offset
|
||||
assert_equal 4 , @mess.get_layout.get_offset
|
||||
assert_equal 8 , @mess.get_layout.get_layout.indexed_length
|
||||
assert_equal 8 , @mess.get_layout.get_layout.get_internal_word(4)
|
||||
end
|
||||
|
||||
def test_layout_methods
|
||||
assert_equal 3 , @mess.get_layout.get_layout.variable_index(:instance_methods)
|
||||
end
|
||||
|
||||
def test_no_index_below_1
|
||||
layout = @mess.get_layout
|
||||
names = layout.instance_names
|
||||
assert_equal 9 , names.get_length , names.inspect
|
||||
names.each do |n|
|
||||
assert layout.variable_index(n) >= 1
|
||||
end
|
||||
end
|
||||
|
||||
def test_class_layout
|
||||
oc = Register.machine.boot.space.get_class_by_name( :Object )
|
||||
assert_equal Parfait::Class , oc.class
|
||||
layout = oc.object_layout
|
||||
assert_equal Parfait::Layout , layout.class
|
||||
assert_equal 1 , layout.instance_names.get_length
|
||||
assert_equal layout.first , :layout
|
||||
end
|
||||
|
||||
|
||||
def test_class_space
|
||||
space = Register.machine.space
|
||||
assert_equal Parfait::Space , space.class
|
||||
layout = space.get_layout
|
||||
assert_equal Parfait::Layout , layout.class
|
||||
assert_equal 3 , layout.instance_names.get_length
|
||||
assert_equal layout.object_class.class , Parfait::Class
|
||||
assert_equal layout.object_class.name , :Space
|
||||
end
|
||||
def test_attribute_set
|
||||
@mess.receiver = 55
|
||||
assert_equal 55 , @mess.receiver
|
||||
end
|
||||
|
||||
def test_add_name
|
||||
layout = Parfait::Layout.new Register.machine.space.get_class_by_name(:Layout)
|
||||
layout.add_instance_variable :boo , :Object
|
||||
assert_equal 2 , layout.variable_index(:boo)
|
||||
assert_equal 4 , layout.get_length
|
||||
assert_equal :layout , layout.get(1)
|
||||
assert_equal :boo , layout.get(3)
|
||||
layout
|
||||
end
|
||||
|
||||
def test_inspect
|
||||
layout = test_add_name
|
||||
assert layout.inspect.include?("boo") , layout.inspect
|
||||
end
|
||||
|
||||
def test_each
|
||||
layout = test_add_name
|
||||
assert_equal 4 , layout.get_length
|
||||
counter = [:boo , :Object, :layout , :Layout]
|
||||
layout.each do |item|
|
||||
assert_equal item , counter.delete(item)
|
||||
end
|
||||
assert counter.empty?
|
||||
end
|
||||
|
||||
# not really parfait test, but related and no other place currently
|
||||
def test_reg_index
|
||||
message_ind = Register.resolve_index( :message , :receiver )
|
||||
assert_equal 3 , message_ind
|
||||
@mess.receiver = 55
|
||||
assert_equal 55 , @mess.get_internal_word(message_ind)
|
||||
end
|
||||
|
||||
def test_object_layout
|
||||
assert_equal 2 , @mess.get_layout.variable_index(:next_message)
|
||||
end
|
||||
|
||||
def test_remove_me
|
||||
layout = @mess.get_layout
|
||||
assert_equal layout , @mess.get_internal_word(1)
|
||||
end
|
||||
end
|
@ -10,27 +10,27 @@ class TestList < MiniTest::Test
|
||||
assert @list.is_a? Parfait::List
|
||||
assert @list.is_a? Parfait::Indexed
|
||||
end
|
||||
def test_old_layout
|
||||
assert_equal Parfait::Layout , Register.machine.space.classes.keys.get_layout.class
|
||||
def test_old_type
|
||||
assert_equal Parfait::Type , Register.machine.space.classes.keys.get_type.class
|
||||
end
|
||||
def test_old_layout_push
|
||||
def test_old_type_push
|
||||
list = Register.machine.space.classes.keys
|
||||
assert_equal Parfait::Layout , list.get_layout.class
|
||||
assert_equal Parfait::Type , list.get_type.class
|
||||
end
|
||||
def test_new_layout
|
||||
assert_equal Parfait::Layout , @list.get_layout.class
|
||||
def test_new_type
|
||||
assert_equal Parfait::Type , @list.get_type.class
|
||||
end
|
||||
def test_new_layout_push
|
||||
def test_new_type_push
|
||||
@list.push(1)
|
||||
assert_equal Parfait::Layout , @list.get_layout.class
|
||||
assert_equal Parfait::Type , @list.get_type.class
|
||||
end
|
||||
def notest_layout_is_first
|
||||
layout = @list.get_layout
|
||||
assert_equal 1 , layout.variable_index(:layout)
|
||||
def notest_type_is_first
|
||||
type = @list.get_type
|
||||
assert_equal 1 , type.variable_index(:type)
|
||||
end
|
||||
def notest_layout_is_first_old
|
||||
layout = Register.machine.space.classes.keys.get_layout
|
||||
assert_equal 1 , layout.variable_index(:layout)
|
||||
def notest_type_is_first_old
|
||||
type = Register.machine.space.classes.keys.get_type
|
||||
assert_equal 1 , type.variable_index(:type)
|
||||
end
|
||||
|
||||
def test_length0
|
||||
@ -41,8 +41,8 @@ class TestList < MiniTest::Test
|
||||
assert_equal 2 , @list.get_offset
|
||||
end
|
||||
def test_indexed_index
|
||||
# 1 layout , 2 indexed_length
|
||||
assert_equal 2 , @list.get_layout.variable_index(:indexed_length)
|
||||
# 1 type , 2 indexed_length
|
||||
assert_equal 2 , @list.get_type.variable_index(:indexed_length)
|
||||
end
|
||||
def test_length1
|
||||
@list.push :one
|
||||
|
@ -7,7 +7,7 @@ class TestMessage < MiniTest::Test
|
||||
end
|
||||
|
||||
def test_length
|
||||
assert_equal 9 , @mess.get_layout.instance_length , @mess.get_layout.inspect
|
||||
assert_equal 9 , @mess.get_type.instance_length , @mess.get_type.inspect
|
||||
assert_equal 9 , Parfait::Message.get_length_index
|
||||
end
|
||||
|
||||
@ -17,7 +17,7 @@ class TestMessage < MiniTest::Test
|
||||
end
|
||||
|
||||
def test_indexed
|
||||
assert_equal 9 , @mess.get_layout.variable_index(:indexed_length)
|
||||
assert_equal 9 , @mess.get_type.variable_index(:indexed_length)
|
||||
end
|
||||
def test_push1
|
||||
@mess.push :name
|
||||
|
@ -9,8 +9,8 @@ class TestObject < MiniTest::Test
|
||||
def test_object_create
|
||||
# another test sometime adds a field variable. Maybe should reboot ?
|
||||
res = 1
|
||||
[:boo1 , :boo2 , :bro , :runner].each { |v| res += 1 if @object.get_layout.variable_index(v) }
|
||||
assert_equal res , @object.get_layout.instance_length , @object.get_layout.inspect
|
||||
[:boo1 , :boo2 , :bro , :runner].each { |v| res += 1 if @object.get_type.variable_index(v) }
|
||||
assert_equal res , @object.get_type.instance_length , @object.get_type.inspect
|
||||
end
|
||||
|
||||
def test_empty_object_doesnt_return
|
||||
|
@ -6,7 +6,7 @@ class TestSpace < MiniTest::Test
|
||||
@machine = Register.machine.boot
|
||||
end
|
||||
def classes
|
||||
[:Kernel,:Word,:List,:Message,:Frame,:Layout,:Object,:Class,:Dictionary,:Method , :Integer]
|
||||
[:Kernel,:Word,:List,:Message,:Frame,:Type,:Object,:Class,:Dictionary,:Method , :Integer]
|
||||
end
|
||||
def test_booted
|
||||
assert_equal true , @machine.booted
|
||||
@ -29,9 +29,9 @@ class TestSpace < MiniTest::Test
|
||||
end
|
||||
end
|
||||
|
||||
def test_classes_layout
|
||||
def test_classes_type
|
||||
classes.each do |name|
|
||||
assert_equal Parfait::Layout , @machine.space.classes[name].get_layout.class
|
||||
assert_equal Parfait::Type , @machine.space.classes[name].get_type.class
|
||||
end
|
||||
end
|
||||
|
||||
|
130
test/register/parfait/test_type.rb
Normal file
130
test/register/parfait/test_type.rb
Normal file
@ -0,0 +1,130 @@
|
||||
require_relative "../helper"
|
||||
|
||||
class TestType < MiniTest::Test
|
||||
|
||||
def setup
|
||||
@mess = Register.machine.boot.space.first_message
|
||||
end
|
||||
|
||||
def test_message_type
|
||||
type = @mess.get_type
|
||||
assert type
|
||||
assert @mess.instance_variable_defined :next_message
|
||||
assert_equal @mess.next_message , @mess.get_instance_variable(:next_message)
|
||||
end
|
||||
|
||||
def test_message_by_index
|
||||
assert_equal @mess.next_message , @mess.get_instance_variable(:next_message)
|
||||
index = @mess.get_type.variable_index :next_message
|
||||
assert_equal 2 , index
|
||||
assert_equal @mess.next_message , @mess.get_internal_word(index)
|
||||
end
|
||||
|
||||
def test_type_index
|
||||
assert_equal @mess.get_type , @mess.get_internal_word(Parfait::LAYOUT_INDEX) , "mess"
|
||||
end
|
||||
|
||||
def test_inspect
|
||||
assert @mess.get_type.inspect.start_with?("Type")
|
||||
end
|
||||
def test_type_is_first
|
||||
type = @mess.get_type
|
||||
assert_equal 1 , type.variable_index(:type)
|
||||
end
|
||||
|
||||
def test_length
|
||||
assert_equal 9 , @mess.get_type.instance_length , @mess.get_type.inspect
|
||||
end
|
||||
|
||||
def test_type_length
|
||||
assert_equal 9 , @mess.get_type.instance_length , @mess.get_type.inspect
|
||||
assert_equal 18 , @mess.get_type.get_internal_word(4)
|
||||
end
|
||||
|
||||
def test_type_length_index
|
||||
assert_equal 4 , @mess.get_type.get_type.variable_index(:indexed_length)
|
||||
assert_equal 4 , @mess.get_type.get_type.get_offset
|
||||
assert_equal 4 , @mess.get_type.get_offset
|
||||
assert_equal 8 , @mess.get_type.get_type.indexed_length
|
||||
assert_equal 8 , @mess.get_type.get_type.get_internal_word(4)
|
||||
end
|
||||
|
||||
def test_type_methods
|
||||
assert_equal 3 , @mess.get_type.get_type.variable_index(:instance_methods)
|
||||
end
|
||||
|
||||
def test_no_index_below_1
|
||||
type = @mess.get_type
|
||||
names = type.instance_names
|
||||
assert_equal 9 , names.get_length , names.inspect
|
||||
names.each do |n|
|
||||
assert type.variable_index(n) >= 1
|
||||
end
|
||||
end
|
||||
|
||||
def test_class_type
|
||||
oc = Register.machine.boot.space.get_class_by_name( :Object )
|
||||
assert_equal Parfait::Class , oc.class
|
||||
type = oc.object_type
|
||||
assert_equal Parfait::Type , type.class
|
||||
assert_equal 1 , type.instance_names.get_length
|
||||
assert_equal type.first , :type
|
||||
end
|
||||
|
||||
|
||||
def test_class_space
|
||||
space = Register.machine.space
|
||||
assert_equal Parfait::Space , space.class
|
||||
type = space.get_type
|
||||
assert_equal Parfait::Type , type.class
|
||||
assert_equal 3 , type.instance_names.get_length
|
||||
assert_equal type.object_class.class , Parfait::Class
|
||||
assert_equal type.object_class.name , :Space
|
||||
end
|
||||
def test_attribute_set
|
||||
@mess.receiver = 55
|
||||
assert_equal 55 , @mess.receiver
|
||||
end
|
||||
|
||||
def test_add_name
|
||||
type = Parfait::Type.new Register.machine.space.get_class_by_name(:Type)
|
||||
type.add_instance_variable :boo , :Object
|
||||
assert_equal 2 , type.variable_index(:boo)
|
||||
assert_equal 4 , type.get_length
|
||||
assert_equal :type , type.get(1)
|
||||
assert_equal :boo , type.get(3)
|
||||
type
|
||||
end
|
||||
|
||||
def test_inspect
|
||||
type = test_add_name
|
||||
assert type.inspect.include?("boo") , type.inspect
|
||||
end
|
||||
|
||||
def test_each
|
||||
type = test_add_name
|
||||
assert_equal 4 , type.get_length
|
||||
counter = [:boo , :Object, :type , :Type]
|
||||
type.each do |item|
|
||||
assert_equal item , counter.delete(item)
|
||||
end
|
||||
assert counter.empty?
|
||||
end
|
||||
|
||||
# not really parfait test, but related and no other place currently
|
||||
def test_reg_index
|
||||
message_ind = Register.resolve_index( :message , :receiver )
|
||||
assert_equal 3 , message_ind
|
||||
@mess.receiver = 55
|
||||
assert_equal 55 , @mess.get_internal_word(message_ind)
|
||||
end
|
||||
|
||||
def test_object_type
|
||||
assert_equal 2 , @mess.get_type.variable_index(:next_message)
|
||||
end
|
||||
|
||||
def test_remove_me
|
||||
type = @mess.get_type
|
||||
assert_equal type , @mess.get_internal_word(1)
|
||||
end
|
||||
end
|
@ -6,19 +6,19 @@ class TestPositioning < MiniTest::Test
|
||||
end
|
||||
def test_list1
|
||||
list = Parfait.new_list([1])
|
||||
list.set_layout( Parfait::Layout.new Object)
|
||||
list.set_type( Parfait::Type.new Object)
|
||||
assert_equal 32 , list.padded_length
|
||||
end
|
||||
def test_list5
|
||||
list = Parfait.new_list([1,2,3,4,5])
|
||||
list.set_layout( Parfait::Layout.new Object)
|
||||
list.set_type( Parfait::Type.new Object)
|
||||
assert_equal 32 , list.padded_length
|
||||
end
|
||||
def test_layout
|
||||
layout = Parfait::Layout.new Object
|
||||
layout.set_layout( Parfait::Layout.new Object)
|
||||
layout.push 5
|
||||
assert_equal 32 , layout.padded_length
|
||||
def test_type
|
||||
type = Parfait::Type.new Object
|
||||
type.set_type( Parfait::Type.new Object)
|
||||
type.push 5
|
||||
assert_equal 32 , type.padded_length
|
||||
end
|
||||
def test_word
|
||||
word = Parfait::Word.new(12)
|
||||
|
@ -25,7 +25,7 @@ HERE
|
||||
end
|
||||
|
||||
def test_field
|
||||
Register.machine.space.get_class_by_name(:Object).object_layout.add_instance_variable(:bro,:Object)
|
||||
Register.machine.space.get_class_by_name(:Object).object_type.add_instance_variable(:bro,:Object)
|
||||
@root = :field_access
|
||||
@string_input = <<HERE
|
||||
self.bro
|
||||
|
@ -31,13 +31,13 @@ module Register
|
||||
end
|
||||
|
||||
def test_field_int
|
||||
Register.machine.space.get_class_by_name(:Object).object_layout.add_instance_variable(:bro,:int)
|
||||
Register.machine.space.get_class_by_name(:Object).object_type.add_instance_variable(:bro,:int)
|
||||
@string_input = "self.bro + 3"
|
||||
check
|
||||
end
|
||||
|
||||
def test_int_field
|
||||
Register.machine.space.get_class_by_name(:Object).object_layout.add_instance_variable(:bro,:int)
|
||||
Register.machine.space.get_class_by_name(:Object).object_type.add_instance_variable(:bro,:int)
|
||||
@string_input = "3 + self.bro"
|
||||
check
|
||||
end
|
||||
|
@ -1,3 +1,3 @@
|
||||
require_relative "test_integer"
|
||||
require_relative "test_layout"
|
||||
require_relative "test_type"
|
||||
require_relative "test_word"
|
||||
|
@ -1,6 +1,6 @@
|
||||
require_relative 'helper'
|
||||
|
||||
class TestLayoutRT < MiniTest::Test
|
||||
class TestTypeRT < MiniTest::Test
|
||||
include ParfaitTests
|
||||
|
||||
def test_main
|
||||
@ -11,10 +11,10 @@ class TestLayoutRT < MiniTest::Test
|
||||
def check_return_class val
|
||||
end
|
||||
|
||||
def test_get_layout
|
||||
@main = "return get_layout()"
|
||||
def test_get_type
|
||||
@main = "return get_type()"
|
||||
interpreter = check
|
||||
assert_equal Parfait::Layout , interpreter.get_register(:r0).return_value.class
|
||||
assert_equal Parfait::Type , interpreter.get_register(:r0).return_value.class
|
||||
end
|
||||
|
||||
def test_get_class
|
||||
@ -32,18 +32,18 @@ HERE
|
||||
check
|
||||
end
|
||||
|
||||
def test_puts_layout_space
|
||||
def test_puts_type_space
|
||||
@main = <<HERE
|
||||
Layout l = get_layout()
|
||||
Type l = get_type()
|
||||
Word w = l.get_class_name()
|
||||
w.putstring()
|
||||
HERE
|
||||
@stdout = "Layout"
|
||||
@stdout = "Type"
|
||||
check
|
||||
end
|
||||
|
||||
# copy of register parfait tests, in order
|
||||
def test_message_layout
|
||||
def test_message_type
|
||||
@main = <<HERE
|
||||
Message m = self.first_message
|
||||
m = m.next_message
|
@ -41,7 +41,7 @@ HERE
|
||||
@string_input = <<HERE
|
||||
class Space
|
||||
int main()
|
||||
Layout l = self.layout
|
||||
Type l = self.type
|
||||
return 1
|
||||
end
|
||||
end
|
||||
|
@ -49,7 +49,7 @@ HERE
|
||||
class Space
|
||||
|
||||
int main()
|
||||
Layout l = space.get_layout()
|
||||
Type l = space.get_type()
|
||||
return self.runner
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user