move parfait up one, as per its module structure
This commit is contained in:
10
test/parfait/test_all.rb
Normal file
10
test/parfait/test_all.rb
Normal file
@ -0,0 +1,10 @@
|
||||
require_relative "test_attributes"
|
||||
require_relative "test_class"
|
||||
require_relative "test_dictionary"
|
||||
require_relative "test_named_list"
|
||||
require_relative "test_list"
|
||||
require_relative "test_message"
|
||||
require_relative "test_typed_method"
|
||||
require_relative "test_object"
|
||||
require_relative "test_space"
|
||||
require_relative "test_word"
|
40
test/parfait/test_attributes.rb
Normal file
40
test/parfait/test_attributes.rb
Normal file
@ -0,0 +1,40 @@
|
||||
require_relative "../helper"
|
||||
|
||||
class TestAttributes < MiniTest::Test
|
||||
|
||||
def setup
|
||||
Register.machine.boot
|
||||
@space = Parfait.object_space
|
||||
@mess = @space.first_message
|
||||
@type = @mess.get_type
|
||||
end
|
||||
|
||||
def test_message_get_type
|
||||
assert_equal Parfait::Type , @type.class
|
||||
end
|
||||
|
||||
def test_message_name_nil
|
||||
last = @type.names.last
|
||||
assert_equal :arguments , last , @type.names.inspect
|
||||
assert_nil @mess.name
|
||||
end
|
||||
def test_message_next_set
|
||||
@mess.next_message = :next_message
|
||||
assert_equal :next_message , @mess.next_message
|
||||
end
|
||||
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::Type , @mess.get_type.class
|
||||
end
|
||||
|
||||
def test_type_type
|
||||
assert_equal Parfait::Type , @type.get_type.get_type.class
|
||||
end
|
||||
def test_type_type_type
|
||||
assert_equal Parfait::Type , @type.get_type.get_type.get_type.class
|
||||
end
|
||||
end
|
48
test/parfait/test_class.rb
Normal file
48
test/parfait/test_class.rb
Normal file
@ -0,0 +1,48 @@
|
||||
require_relative "../helper"
|
||||
|
||||
class TestClass < MiniTest::Test
|
||||
|
||||
def setup
|
||||
Register.machine.boot
|
||||
@space = Parfait.object_space
|
||||
@try = @space.create_class :Try , :Object
|
||||
end
|
||||
|
||||
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
|
||||
end
|
||||
def test_new_superclass
|
||||
assert_equal "Class(Object)" , @try.super_class.inspect
|
||||
end
|
||||
def test_new_methods
|
||||
assert_equal @try.method_names.class, @try.instance_methods.class
|
||||
assert_equal @try.method_names.get_length , @try.instance_methods.get_length
|
||||
end
|
||||
def test_remove_nothere
|
||||
assert !@try.remove_instance_method(:foo)
|
||||
end
|
||||
def test_resolve
|
||||
assert_nil @try.resolve_method :foo
|
||||
end
|
||||
def test_remove_method
|
||||
assert_equal false , @try.remove_instance_method( :foo)
|
||||
end
|
||||
def test_add_method
|
||||
assert_raises{ @try.add_instance_method(nil)}
|
||||
end
|
||||
def test_add_instance_variable_changes_type
|
||||
before = @space.get_class.instance_type
|
||||
@space.get_class.add_instance_variable(:counter , :Integer)
|
||||
assert before != @space.get_class.instance_type
|
||||
end
|
||||
def test_add_instance_variable_changes_type_hash
|
||||
before = @space.get_class.instance_type.hash
|
||||
@space.get_class.add_instance_variable(:counter , :Integer)
|
||||
assert before != @space.get_class.instance_type.hash
|
||||
end
|
||||
|
||||
end
|
76
test/parfait/test_dictionary.rb
Normal file
76
test/parfait/test_dictionary.rb
Normal file
@ -0,0 +1,76 @@
|
||||
require_relative "../helper"
|
||||
|
||||
class TestDictionary < MiniTest::Test
|
||||
|
||||
def setup
|
||||
@lookup = ::Parfait::Dictionary.new
|
||||
end
|
||||
def test_dict_create
|
||||
assert_equal 0 , @lookup.length
|
||||
assert @lookup.empty?
|
||||
end
|
||||
def test_empty_dict_doesnt_return
|
||||
assert_nil @lookup.get(3)
|
||||
assert_nil @lookup.get(:any)
|
||||
end
|
||||
def test_one_set1
|
||||
assert_equal 1 , @lookup.set(1,1)
|
||||
assert_equal 1 , @lookup.length
|
||||
end
|
||||
def test_one_double
|
||||
assert_equal 1 , @lookup.set(1,1)
|
||||
assert_equal 3 , @lookup.set(1,3)
|
||||
assert_equal 1 , @lookup.length
|
||||
end
|
||||
def test_one_double2
|
||||
assert_equal 1 , @lookup.set(:one,1)
|
||||
assert_equal 3 , @lookup.set(:one,3)
|
||||
assert_equal 1 , @lookup.length
|
||||
end
|
||||
def test_one_set2
|
||||
assert_equal :some , @lookup.set(1,:some)
|
||||
end
|
||||
def test_two_sets
|
||||
assert_equal 1 , @lookup.set(1,1)
|
||||
assert_equal :some , @lookup.set(1,:some)
|
||||
end
|
||||
def test_one_get1
|
||||
test_one_set1
|
||||
assert_equal 1 , @lookup.get(1)
|
||||
end
|
||||
def test_one_get2
|
||||
test_one_set2
|
||||
assert_equal :some , @lookup.get(1)
|
||||
end
|
||||
def test_inspect1
|
||||
@lookup[:key] = :value
|
||||
assert_equal "Dictionary{key => value ,}" , @lookup.inspect
|
||||
end
|
||||
def test_inspect2
|
||||
@lookup[:key1] = :value1
|
||||
@lookup[:key2] = :value2
|
||||
assert_equal "Dictionary{key1 => value1 ,key2 => value2 ,}" , @lookup.inspect
|
||||
end
|
||||
def test_many_get
|
||||
shouldda = { :one => 1 , :two => 2 , :three => 3}
|
||||
shouldda.each do |k,v|
|
||||
@lookup.set(k,v)
|
||||
end
|
||||
@lookup.each do |k,v|
|
||||
assert_equal v , shouldda[k]
|
||||
end
|
||||
end
|
||||
def test_values
|
||||
@lookup[2] = 2
|
||||
assert @lookup.values.get_length == 1
|
||||
end
|
||||
def test_keys
|
||||
@lookup[2] = 2
|
||||
assert @lookup.keys.get_length == 1
|
||||
end
|
||||
def test_override_exising
|
||||
@lookup[2] = 2
|
||||
@lookup[2] = :two
|
||||
assert @lookup[2] == :two
|
||||
end
|
||||
end
|
198
test/parfait/test_list.rb
Normal file
198
test/parfait/test_list.rb
Normal file
@ -0,0 +1,198 @@
|
||||
require_relative "../helper"
|
||||
|
||||
class TestList < MiniTest::Test
|
||||
|
||||
def setup
|
||||
@list = ::Parfait::List.new
|
||||
end
|
||||
def test_isa
|
||||
assert @list.is_a? Parfait::List
|
||||
end
|
||||
def test_old_type
|
||||
assert_equal Parfait::Type , Parfait.object_space.classes.keys.get_type.class
|
||||
end
|
||||
def test_old_type_push
|
||||
list = Parfait.object_space.classes.keys
|
||||
assert_equal Parfait::Type , list.get_type.class
|
||||
end
|
||||
def test_new_type
|
||||
assert_equal Parfait::Type , @list.get_type.class
|
||||
end
|
||||
def test_new_type_push
|
||||
@list.push(1)
|
||||
assert_equal Parfait::Type , @list.get_type.class
|
||||
end
|
||||
def notest_type_is_first
|
||||
type = @list.get_type
|
||||
assert_equal 1 , type.variable_index(:type)
|
||||
end
|
||||
def notest_type_is_first_old
|
||||
type = Parfait.object_space.classes.keys.get_type
|
||||
assert_equal 1 , type.variable_index(:type)
|
||||
end
|
||||
|
||||
def test_length0
|
||||
assert_equal 0 , @list.get_length
|
||||
assert_equal 0, @list.indexed_length
|
||||
end
|
||||
def test_offset
|
||||
assert_equal 2 , @list.get_offset
|
||||
end
|
||||
def test_indexed_index
|
||||
# 1 type , 2 indexed_length
|
||||
assert_equal 2 , @list.get_type.variable_index(:indexed_length)
|
||||
end
|
||||
def test_length1
|
||||
@list.push :one
|
||||
assert_equal 1 , @list.get_length
|
||||
assert_equal 1 , @list.indexed_length
|
||||
assert_equal 1 , @list.get_internal_word(Parfait::TYPE_INDEX + 1)
|
||||
end
|
||||
def test_list_inspect
|
||||
@list.set(1,1)
|
||||
assert_equal "1" , @list.inspect
|
||||
end
|
||||
def test_list_equal
|
||||
@list.set(1,1)
|
||||
list = ::Parfait::List.new
|
||||
list.set(1,1)
|
||||
assert @list.equal? list
|
||||
end
|
||||
def test_list_create
|
||||
assert @list.empty?
|
||||
end
|
||||
def test_list_len
|
||||
assert_equal 0 , @list.get_length
|
||||
end
|
||||
def test_empty_list_doesnt_return
|
||||
assert_nil @list.get(3)
|
||||
end
|
||||
def test_one_set1
|
||||
assert_equal 2 , @list.set(1,2)
|
||||
assert_equal 1 , @list.get_internal_word(2)
|
||||
end
|
||||
def test_set1_len
|
||||
@list.set(1,1)
|
||||
assert_equal 1 , @list.get_length
|
||||
end
|
||||
def test_one_set2
|
||||
assert_equal :some , @list.set(2,:some)
|
||||
end
|
||||
def test_set2_len
|
||||
@list.set(2,:some)
|
||||
assert_equal 2 , @list.get_length
|
||||
end
|
||||
def test_two_sets
|
||||
assert_equal 1 , @list.set(1,1)
|
||||
assert_equal :some , @list.set(1,:some)
|
||||
end
|
||||
def test_one_get1
|
||||
test_one_set1
|
||||
assert_equal 2 , @list.get(1)
|
||||
end
|
||||
def test_one_get2
|
||||
test_one_set2
|
||||
assert_equal :some , @list.get(2)
|
||||
end
|
||||
def set_shouldda
|
||||
shouldda = { 1 => :one , 2 => :two , 3 => :three}
|
||||
shouldda.each do |k,v|
|
||||
@list.set(k,v)
|
||||
end
|
||||
shouldda
|
||||
end
|
||||
def test_many_get
|
||||
shouldda = set_shouldda
|
||||
shouldda.each do |k,v|
|
||||
assert_equal v , @list.get(k)
|
||||
end
|
||||
end
|
||||
def test_each
|
||||
shouldda_values = set_shouldda.values
|
||||
@list.each do |val|
|
||||
shouldda_values.delete val
|
||||
end
|
||||
assert_equal 0 , shouldda_values.length
|
||||
end
|
||||
def test_each_index
|
||||
set_shouldda
|
||||
@list.each_with_index do |val , index|
|
||||
assert_equal @list[index] , val
|
||||
end
|
||||
end
|
||||
def test_each_pair_length
|
||||
shouldda_values = set_shouldda.values
|
||||
@list.each_pair do |key,val|
|
||||
shouldda_values.delete key
|
||||
shouldda_values.delete val
|
||||
end
|
||||
assert_equal 0 , shouldda_values.length
|
||||
end
|
||||
def test_each_pair_count
|
||||
set_shouldda.values
|
||||
counter = 0
|
||||
@list.each_pair do |key,val|
|
||||
counter += 1
|
||||
end
|
||||
assert_equal 2 , counter
|
||||
end
|
||||
def test_find
|
||||
@list.set(1,1)
|
||||
@list.set(2,2)
|
||||
assert_equal 2, @list.find{|i| i == 2}
|
||||
end
|
||||
def test_not_find
|
||||
@list.set(1,1)
|
||||
assert_nil @list.find{|i| i == 3}
|
||||
end
|
||||
def test_delete_at
|
||||
test_many_get
|
||||
assert @list.delete_at 2
|
||||
assert_equal 2 , @list.get_length
|
||||
assert_equal 2 , @list.index_of( :three )
|
||||
end
|
||||
|
||||
def test_delete
|
||||
test_many_get
|
||||
assert @list.delete :two
|
||||
assert_equal 2 , @list.get_length
|
||||
assert_equal 2 , @list.index_of( :three )
|
||||
end
|
||||
def test_index_of
|
||||
test_many_get
|
||||
assert_equal 2 , @list.index_of( :two )
|
||||
assert_equal 3 , @list.index_of( :three )
|
||||
assert_nil @list.index_of( :four )
|
||||
end
|
||||
def test_inspect
|
||||
test_many_get
|
||||
assert @list.inspect.include?("one") , @list.inspect
|
||||
assert @list.inspect.include?("three") , @list.inspect
|
||||
end
|
||||
def test_inlcude
|
||||
test_many_get
|
||||
assert_equal true , @list.include?( :two )
|
||||
assert_equal false , @list.include?( :four )
|
||||
end
|
||||
def test_empty_empty
|
||||
assert_equal true , @list.empty?
|
||||
end
|
||||
def test_empty_notempty
|
||||
assert_equal 1 , @list.set(1,1)
|
||||
assert_equal false , @list.empty?
|
||||
end
|
||||
def test_first
|
||||
test_many_get
|
||||
assert_equal :one , @list.first
|
||||
end
|
||||
def test_first_empty
|
||||
assert_nil @list.first
|
||||
end
|
||||
def test_last
|
||||
test_many_get
|
||||
assert_equal :three , @list.last
|
||||
end
|
||||
def test_last_empty
|
||||
assert_nil @list.last
|
||||
end
|
||||
end
|
27
test/parfait/test_message.rb
Normal file
27
test/parfait/test_message.rb
Normal file
@ -0,0 +1,27 @@
|
||||
require_relative "../helper"
|
||||
|
||||
class TestMessage < MiniTest::Test
|
||||
|
||||
def setup
|
||||
Register.machine.boot
|
||||
@space = Parfait.object_space
|
||||
@mess = @space.first_message
|
||||
end
|
||||
|
||||
def test_length
|
||||
assert_equal 9 , @mess.get_type.instance_length , @mess.get_type.inspect
|
||||
end
|
||||
|
||||
def test_attribute_set
|
||||
@mess.set_receiver( 55)
|
||||
assert_equal 55 , @mess.receiver
|
||||
end
|
||||
|
||||
def test_indexed
|
||||
assert_equal 9 , @mess.get_type.variable_index(:arguments)
|
||||
end
|
||||
|
||||
def test_next
|
||||
assert @mess.next_message
|
||||
end
|
||||
end
|
27
test/parfait/test_named_list.rb
Normal file
27
test/parfait/test_named_list.rb
Normal file
@ -0,0 +1,27 @@
|
||||
require_relative "../helper"
|
||||
|
||||
class TestNamedLists < MiniTest::Test
|
||||
|
||||
def setup
|
||||
Register.machine.boot
|
||||
@space = Parfait.object_space
|
||||
@named_list = @space.first_message.locals
|
||||
@type = @named_list.get_type
|
||||
end
|
||||
|
||||
def test_named_list_get_type
|
||||
assert_equal Parfait::Type , @type.class
|
||||
assert @type.names
|
||||
assert @named_list.get_instance_variables
|
||||
end
|
||||
|
||||
def test_new
|
||||
list = Parfait::NamedList.new
|
||||
assert list.get_type
|
||||
end
|
||||
|
||||
def test_var_names
|
||||
list = Parfait::NamedList.new
|
||||
assert list.get_instance_variables
|
||||
end
|
||||
end
|
17
test/parfait/test_object.rb
Normal file
17
test/parfait/test_object.rb
Normal file
@ -0,0 +1,17 @@
|
||||
require_relative "../helper"
|
||||
|
||||
class TestObject < MiniTest::Test
|
||||
|
||||
def setup
|
||||
@object = ::Parfait::Object.new
|
||||
end
|
||||
|
||||
def test_empty_object_doesnt_return
|
||||
assert_nil @object.get_internal_word(3)
|
||||
end
|
||||
|
||||
def test_one_set1
|
||||
assert_equal @object.get_type , @object.set_internal_word(1, @object.get_type)
|
||||
end
|
||||
|
||||
end
|
155
test/parfait/test_space.rb
Normal file
155
test/parfait/test_space.rb
Normal file
@ -0,0 +1,155 @@
|
||||
require_relative "../helper"
|
||||
|
||||
class TestSpace < MiniTest::Test
|
||||
|
||||
def setup
|
||||
@machine = Register.machine.boot
|
||||
@space = Parfait.object_space
|
||||
end
|
||||
|
||||
def classes
|
||||
[:Kernel,:Word,:List,:Message,:NamedList,:Type,:Object,:Class,:Dictionary,:TypedMethod , :Integer]
|
||||
end
|
||||
|
||||
def test_booted
|
||||
assert_equal true , @machine.booted
|
||||
end
|
||||
|
||||
def test_methods_booted
|
||||
word = @space.get_class_by_name(:Word).instance_type
|
||||
assert_equal 3 , word.method_names.get_length
|
||||
assert word.get_method(:putstring) , "no putstring"
|
||||
end
|
||||
|
||||
def test_global_space
|
||||
assert_equal Parfait::Space , Parfait.object_space.class
|
||||
end
|
||||
|
||||
def test_integer
|
||||
int = Parfait.object_space.get_class_by_name :Integer
|
||||
assert_equal 3, int.instance_type.method_names.get_length
|
||||
end
|
||||
|
||||
def test_classes_class
|
||||
classes.each do |name|
|
||||
assert_equal :Class , @space.classes[name].get_class.name
|
||||
assert_equal Parfait::Class , @space.classes[name].class
|
||||
end
|
||||
end
|
||||
|
||||
def test_types
|
||||
assert @space.instance_variable_get("@types").is_a? Parfait::Dictionary
|
||||
end
|
||||
|
||||
def test_types_each
|
||||
@space.each_type do |type|
|
||||
assert type.is_a?(Parfait::Type)
|
||||
end
|
||||
end
|
||||
|
||||
def test_types_hashes
|
||||
types = @space.instance_variable_get("@types")
|
||||
types.each do |has , type|
|
||||
assert has.is_a?(Fixnum) , has.inspect
|
||||
end
|
||||
end
|
||||
|
||||
def test_classes_types_in_space_types
|
||||
@space.classes do |name , clazz|
|
||||
assert_equal clazz.instance_type , @space.get_type_for(clazz.instance_type.hash) , clazz.name
|
||||
end
|
||||
end
|
||||
|
||||
def test_word_class
|
||||
word = @space.classes[:Word]
|
||||
assert word.instance_type
|
||||
t_word = @space.get_type_for(word.instance_type.hash)
|
||||
assert_equal word.instance_type.hash , t_word.hash
|
||||
assert_equal word.instance_type.object_id , t_word.object_id
|
||||
end
|
||||
|
||||
def test_classes_type
|
||||
classes.each do |name|
|
||||
assert_equal Parfait::Type , @space.classes[name].get_type.class
|
||||
end
|
||||
end
|
||||
|
||||
def test_classes_name
|
||||
classes.each do |name|
|
||||
assert_equal name , @space.classes[name].name
|
||||
end
|
||||
end
|
||||
|
||||
def test_method_name
|
||||
classes.each do |name|
|
||||
cl = @space.classes[name]
|
||||
cl.method_names.each do |mname|
|
||||
method = cl.get_instance_method(mname)
|
||||
assert_equal mname , method.name
|
||||
assert_equal name , method.for_class.name
|
||||
end
|
||||
end
|
||||
end
|
||||
def test_messages
|
||||
mess = @space.first_message
|
||||
all = []
|
||||
while mess
|
||||
all << mess
|
||||
assert mess.locals
|
||||
mess = mess.next_message
|
||||
end
|
||||
assert_equal all.length , all.uniq.length
|
||||
# there is a 5.times in space, but one Message gets created before
|
||||
assert_equal 50 + 1 , all.length
|
||||
end
|
||||
def test_message_vars
|
||||
mess = @space.first_message
|
||||
all = mess.get_instance_variables
|
||||
assert all
|
||||
assert all.include?(:next_message)
|
||||
end
|
||||
|
||||
def test_create_class
|
||||
assert @space.create_class( :NewClass )
|
||||
end
|
||||
|
||||
def test_created_class_is_stored
|
||||
@space.create_class( :NewerClass )
|
||||
assert @space.get_class_by_name(:NewerClass)
|
||||
end
|
||||
|
||||
def test_class_types_are_stored
|
||||
@space.classes.each do |name,clazz|
|
||||
assert @space.get_type_for(clazz.instance_type.hash)
|
||||
end
|
||||
end
|
||||
|
||||
def test_class_types_are_identical
|
||||
@space.classes.each do |name , clazz|
|
||||
cl_type = @space.get_type_for(clazz.instance_type.hash)
|
||||
assert_equal cl_type.object_id , clazz.instance_type.object_id
|
||||
end
|
||||
end
|
||||
|
||||
def test_remove_methods
|
||||
@space.each_type do | type |
|
||||
type.method_names.each do |method|
|
||||
type.remove_method(method)
|
||||
end
|
||||
end
|
||||
assert_equal 0 , @space.collect_methods.length
|
||||
end
|
||||
def test_no_methods_in_types
|
||||
test_remove_methods
|
||||
@space.each_type do |type|
|
||||
assert_equal 0 , type.methods.get_length , "name #{type.name}"
|
||||
end
|
||||
end
|
||||
def ttest_no_methods_in_classes
|
||||
test_remove_methods
|
||||
@space.classes.each do |name , cl|
|
||||
assert_equal 0 , cl.instance_type.methods.get_length , "name #{cl.name}"
|
||||
end
|
||||
end
|
||||
|
||||
end
|
95
test/parfait/test_typed_method.rb
Normal file
95
test/parfait/test_typed_method.rb
Normal file
@ -0,0 +1,95 @@
|
||||
require_relative "../helper"
|
||||
|
||||
class TestMethod < MiniTest::Test
|
||||
|
||||
def setup
|
||||
obj = Parfait.object_space.get_class_by_name(:Object).instance_type
|
||||
args = Parfait::Type.for_hash( obj.object_class , { bar: :Integer , foo: :Type})
|
||||
@method = ::Parfait::TypedMethod.new obj , :meth , args
|
||||
@method.add_local :local_bar , :Integer
|
||||
@method.add_local :local_foo , :Type
|
||||
end
|
||||
|
||||
def test_method_name
|
||||
assert_equal :meth , @method.name
|
||||
end
|
||||
|
||||
def test_class_for
|
||||
assert_equal :Object , @method.for_type.object_class.name
|
||||
end
|
||||
|
||||
def test_arg1
|
||||
assert_equal 2 , @method.arguments_length , @method.arguments.inspect
|
||||
assert_equal Symbol , @method.arguments.names.first.class
|
||||
assert_equal :bar , @method.argument_name(1)
|
||||
end
|
||||
|
||||
def test_has_argument
|
||||
assert_equal 1 , @method.has_argument(:bar)
|
||||
assert_equal 2 , @method.has_argument(:foo)
|
||||
end
|
||||
|
||||
def test_add_arg
|
||||
@method.add_argument(:foo2 , :Object)
|
||||
assert_equal 3 , @method.arguments_length
|
||||
assert_equal :foo2 , @method.argument_name(3)
|
||||
assert_equal :Object , @method.arguments_type(3)
|
||||
end
|
||||
|
||||
def test_get_arg_name1
|
||||
index = @method.has_argument(:bar)
|
||||
assert_equal 1 , index
|
||||
assert_equal :bar , @method.argument_name(index)
|
||||
end
|
||||
def test_get_arg_type1
|
||||
index = @method.has_argument(:bar)
|
||||
assert_equal :Integer , @method.arguments_type(index)
|
||||
end
|
||||
def test_get_arg_name2
|
||||
index = @method.has_argument(:foo)
|
||||
assert_equal 2 , index
|
||||
assert_equal :foo , @method.argument_name(index)
|
||||
end
|
||||
def test_get_arg_type2
|
||||
index = @method.has_argument(:foo)
|
||||
assert_equal :Type , @method.arguments_type(index)
|
||||
end
|
||||
|
||||
def test_local1
|
||||
assert_equal 2 , @method.locals_length , @method.locals.inspect
|
||||
assert_equal Symbol , @method.locals.names.first.class
|
||||
assert_equal :local_bar , @method.locals_name(1)
|
||||
end
|
||||
|
||||
def test_has_local
|
||||
assert_equal 1 , @method.has_local(:local_bar)
|
||||
assert_equal 2 , @method.has_local(:local_foo)
|
||||
end
|
||||
|
||||
def test_add_local
|
||||
@method.add_local(:foo2 , :Object)
|
||||
assert_equal 3 , @method.locals_length
|
||||
assert_equal :foo2 , @method.locals_name(3)
|
||||
assert_equal :Object , @method.locals_type(3)
|
||||
end
|
||||
|
||||
def test_get_locals_name1
|
||||
index = @method.has_local(:local_bar)
|
||||
assert_equal 1 , index
|
||||
assert_equal :local_bar , @method.locals_name(index)
|
||||
end
|
||||
def test_get_locals_type1
|
||||
index = @method.has_local(:local_bar)
|
||||
assert_equal :Integer , @method.locals_type(index)
|
||||
end
|
||||
def test_get_locals_name2
|
||||
index = @method.has_local(:local_foo)
|
||||
assert_equal 2 , index
|
||||
assert_equal :local_foo , @method.locals_name(index)
|
||||
end
|
||||
def test_get_locals_type2
|
||||
index = @method.has_local(:local_bar)
|
||||
assert_equal :Integer , @method.locals_type(index)
|
||||
end
|
||||
|
||||
end
|
113
test/parfait/test_word.rb
Normal file
113
test/parfait/test_word.rb
Normal file
@ -0,0 +1,113 @@
|
||||
require_relative "../helper"
|
||||
module Parfait
|
||||
class TestEmptyWord < MiniTest::Test
|
||||
|
||||
def setup
|
||||
Register.machine.boot
|
||||
@word = Parfait::Word.new(0)
|
||||
end
|
||||
def test_word_create
|
||||
assert @word.empty?
|
||||
end
|
||||
def test_empty_is_zero
|
||||
assert_equal 0 , @word.length
|
||||
end
|
||||
def test_empty_is_zero_internal
|
||||
assert_equal 0 , @word.char_length
|
||||
end
|
||||
def test_index_check_get
|
||||
assert_raises RuntimeError do
|
||||
@word.get_char(0)
|
||||
end
|
||||
end
|
||||
def test_index_check_set
|
||||
assert_raises RuntimeError do
|
||||
@word.set_char(1 , 32)
|
||||
end
|
||||
end
|
||||
end
|
||||
class TestWord < MiniTest::Test
|
||||
|
||||
def setup
|
||||
Register.machine.boot
|
||||
@word = Parfait::Word.new(5)
|
||||
end
|
||||
def test_len
|
||||
assert_equal 5 , @word.length
|
||||
end
|
||||
def test_len_internal
|
||||
assert_equal 5 , @word.char_length
|
||||
end
|
||||
def test_first_char
|
||||
assert_equal 32 , @word.get_char(1)
|
||||
end
|
||||
def test_equals_copy
|
||||
assert_equal @word.copy , @word
|
||||
end
|
||||
def test_equals_copy2
|
||||
@word.set_char(1 , 2)
|
||||
@word.set_char(5 , 6)
|
||||
assert_equal @word.copy , @word
|
||||
end
|
||||
def test_equals_same
|
||||
assert_equal ::Parfait::Word.new(5) , @word
|
||||
end
|
||||
def test_index_check_get
|
||||
assert_raises RuntimeError do
|
||||
@word.get_char(-6)
|
||||
end
|
||||
end
|
||||
def test_index_check_set
|
||||
assert_raises RuntimeError do
|
||||
@word.set_char(6 , 32)
|
||||
end
|
||||
end
|
||||
def test_index_check_get
|
||||
assert_raises RuntimeError do
|
||||
@word.get_char(6)
|
||||
end
|
||||
end
|
||||
def test_index_check_set
|
||||
assert_raises RuntimeError do
|
||||
@word.set_char(-6 , 32)
|
||||
end
|
||||
end
|
||||
def test_one_char
|
||||
assert_equal 32 , @word.set_char(1 , 32)
|
||||
end
|
||||
def test_one_char_doesnt_cause_problems
|
||||
@word.set_char(1 , 32)
|
||||
assert_equal 32 , @word.get_char(1)
|
||||
end
|
||||
def test_one_set1
|
||||
assert_equal 44 , @word.set_char(1, 44 )
|
||||
end
|
||||
def test_two_sets
|
||||
assert_equal 1 , @word.set_char(1,1)
|
||||
assert_equal 44 , @word.set_char(1,44)
|
||||
end
|
||||
def test_one_get1
|
||||
test_one_set1
|
||||
assert_equal 44 , @word.get_char(1)
|
||||
end
|
||||
def test_many_get
|
||||
shouldda = { 1 => 11 , 2 => 22 , 3 => 33}
|
||||
shouldda.each do |k,v|
|
||||
@word.set_char(k,v)
|
||||
end
|
||||
shouldda.each do |k,v|
|
||||
assert_equal v , @word.get_char(k)
|
||||
end
|
||||
end
|
||||
def test_not_same
|
||||
one = Parfait.new_word("one")
|
||||
two = Parfait.new_word("two")
|
||||
assert !one.compare(two)
|
||||
end
|
||||
def test_is_same
|
||||
one = Parfait.new_word("one")
|
||||
two = Parfait.new_word("one")
|
||||
assert one.compare(two)
|
||||
end
|
||||
end
|
||||
end
|
Reference in New Issue
Block a user