diff --git a/test/parfait/helper.rb b/test/parfait/helper.rb new file mode 100644 index 00000000..bb3227b0 --- /dev/null +++ b/test/parfait/helper.rb @@ -0,0 +1,11 @@ +require_relative "../helper" + +module Parfait + class ParfaitTest < MiniTest::Test + + def setup + @machine = Risc.machine.boot + @space = Parfait.object_space + end + end +end diff --git a/test/parfait/test_attributes.rb b/test/parfait/test_attributes.rb index 37b5a314..4063193d 100644 --- a/test/parfait/test_attributes.rb +++ b/test/parfait/test_attributes.rb @@ -1,40 +1,41 @@ -require_relative "../helper" +require_relative "helper" -class TestAttributes < MiniTest::Test +module Parfait + class TestAttributes < ParfaitTest - def setup - Risc.machine.boot - @space = Parfait.object_space - @mess = @space.first_message - @type = @mess.get_type - end + def setup + super + @mess = @space.first_message + @type = @mess.get_type + end - def test_message_get_type - assert_equal Parfait::Type , @type.class - 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_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 + 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 end diff --git a/test/parfait/test_binary_code.rb b/test/parfait/test_binary_code.rb index fbb162df..be6e4602 100644 --- a/test/parfait/test_binary_code.rb +++ b/test/parfait/test_binary_code.rb @@ -1,10 +1,10 @@ -require_relative "../helper" +require_relative "helper" module Parfait - class TestBinaryCode < MiniTest::Test + class TestBinaryCode < ParfaitTest def setup - Risc.machine.boot + super @code = BinaryCode.new(10) end diff --git a/test/parfait/test_class.rb b/test/parfait/test_class.rb index 10bf38c4..b3d757ec 100644 --- a/test/parfait/test_class.rb +++ b/test/parfait/test_class.rb @@ -1,49 +1,50 @@ -require_relative "../helper" +require_relative "helper" -class TestClass < MiniTest::Test +module Parfait + class TestClass < ParfaitTest - def setup - Risc.machine.boot - @space = Parfait.object_space - @try = @space.create_class :Try , :Object - end + def setup + super + @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 - 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_nil_method_raises - 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 + 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 + 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_nil_method_raises + 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 end diff --git a/test/parfait/test_dictionary.rb b/test/parfait/test_dictionary.rb index 835da68b..dc08a3d9 100644 --- a/test/parfait/test_dictionary.rb +++ b/test/parfait/test_dictionary.rb @@ -1,76 +1,79 @@ -require_relative "../helper" +require_relative "helper" -class TestDictionary < MiniTest::Test +module Parfait + class TestDictionary < ParfaitTest - 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) + def setup + super + @lookup = ::Parfait::Dictionary.new end - @lookup.each do |k,v| - assert_equal v , shouldda[k] + 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 - 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 diff --git a/test/parfait/test_integer.rb b/test/parfait/test_integer.rb index a6b8b20a..8478b886 100644 --- a/test/parfait/test_integer.rb +++ b/test/parfait/test_integer.rb @@ -1,10 +1,10 @@ -require_relative "../helper" +require_relative "helper" module Parfait - class TestInteger < MiniTest::Test + class TestInteger < ParfaitTest def setup - Risc.machine.boot + super @int = Integer.new(10) end diff --git a/test/parfait/test_list.rb b/test/parfait/test_list.rb index 06a9e2be..e4c56215 100644 --- a/test/parfait/test_list.rb +++ b/test/parfait/test_list.rb @@ -1,198 +1,201 @@ -require_relative "../helper" +require_relative "helper" -class TestList < MiniTest::Test +module Parfait + class TestList < ParfaitTest - 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 setup + super + @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) + def test_length0 + assert_equal 0 , @list.get_length + assert_equal 0, @list.indexed_length end - shouldda - end - def test_many_get - shouldda = set_shouldda - shouldda.each do |k,v| - assert_equal v , @list.get(k) + def test_offset + assert_equal 2 , @list.get_offset end - end - def test_each - shouldda_values = set_shouldda.values - @list.each do |val| - shouldda_values.delete val + def test_indexed_index + # 1 type , 2 indexed_length + assert_equal 2 , @list.get_type.variable_index(:indexed_length) 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 + 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 - 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 + def test_list_inspect + @list.set(1,1) + assert_equal "1" , @list.inspect 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 + 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 - 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 + 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 end diff --git a/test/parfait/test_message.rb b/test/parfait/test_message.rb index 47e6fa77..38f4be77 100644 --- a/test/parfait/test_message.rb +++ b/test/parfait/test_message.rb @@ -1,11 +1,10 @@ -require_relative "../helper" +require_relative "helper" module Parfait - class TestMessage < MiniTest::Test + class TestMessage < ParfaitTest def setup - Risc.machine.boot - @space = Parfait.object_space + super @mess = @space.first_message end def test_length diff --git a/test/parfait/test_named_list.rb b/test/parfait/test_named_list.rb index 68f9b62b..b41c08d8 100644 --- a/test/parfait/test_named_list.rb +++ b/test/parfait/test_named_list.rb @@ -1,11 +1,10 @@ -require_relative "../helper" +require_relative "helper" module Parfait - class TestNamedLists < MiniTest::Test + class TestNamedLists < ParfaitTest def setup - Risc.machine.boot - @space = Parfait.object_space + super @named_list = @space.first_message.frame @type = @named_list.get_type end diff --git a/test/parfait/test_object.rb b/test/parfait/test_object.rb index 54eb4409..73512373 100644 --- a/test/parfait/test_object.rb +++ b/test/parfait/test_object.rb @@ -1,17 +1,20 @@ -require_relative "../helper" +require_relative "helper" -class TestObject < MiniTest::Test +module Parfait + class TestObject < ParfaitTest + + def setup + super + @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 - 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 diff --git a/test/parfait/test_space.rb b/test/parfait/test_space.rb index f9e2df80..772880a3 100644 --- a/test/parfait/test_space.rb +++ b/test/parfait/test_space.rb @@ -1,162 +1,159 @@ -require_relative "../helper" +require_relative "helper" -class TestSpace < MiniTest::Test +module Parfait + class TestSpace < ParfaitTest - def setup - @machine = Risc.machine.boot - @space = Parfait.object_space - end - - def classes - [:Word,:List,:Message,:NamedList,:Type,:Object,:Class,:Dictionary,:TypedMethod , :Integer] - end - - def test_booted - assert_equal true , @machine.booted - end - def test_space_length - assert_equal 8 , @space.get_type.instance_length , @space.get_type.inspect - end - def test_singletons - assert @space.true_object , "No truth" - assert @space.false_object , "No lies" - assert @space.nil_object , "No nothing" - 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 14, 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 + def classes + [:Word,:List,:Message,:NamedList,:Type,:Object,:Class,:Dictionary,:TypedMethod , :Integer] end - end - def test_types - assert @space.instance_variable_ged("@types").is_a? Parfait::Dictionary - end - - def test_types_each - @space.each_type do |type| - assert type.is_a?(Parfait::Type) + def test_booted + assert_equal true , @machine.booted end - end - - def test_types_hashes - types = @space.instance_variable_ged("@types") - types.each do |has , type| - assert has.is_a?(Fixnum) , has.inspect + def test_space_length + assert_equal 8 , @space.get_type.instance_length , @space.get_type.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 + def test_singletons + assert @space.true_object , "No truth" + assert @space.false_object , "No lies" + assert @space.nil_object , "No nothing" 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 + 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 - end - def test_classes_name - classes.each do |name| - assert_equal name , @space.classes[name].name + def test_global_space + assert_equal Parfait::Space , Parfait.object_space.class 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 + def test_integer + int = Parfait.object_space.get_class_by_name :Integer + assert_equal 14, 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 - end - def test_messages - mess = @space.first_message - all = [] - while mess - all << mess - assert mess.frame - mess = mess.next_message + + def test_types + assert @space.instance_variable_ged("@types").is_a? Parfait::Dictionary 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) + def test_types_each + @space.each_type do |type| + assert type.is_a?(Parfait::Type) 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_length , "name #{type.name}" - end - end - def test_no_methods_in_classes - test_remove_methods - @space.classes.each do |name , cl| - assert_equal 0 , cl.instance_type.methods_length , "name #{cl.name}" - end - end + def test_types_hashes + types = @space.instance_variable_ged("@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.frame + 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_length , "name #{type.name}" + end + end + def test_no_methods_in_classes + test_remove_methods + @space.classes.each do |name , cl| + assert_equal 0 , cl.instance_type.methods_length , "name #{cl.name}" + end + end + + end end diff --git a/test/parfait/test_typed_method.rb b/test/parfait/test_typed_method.rb index da493e04..067e74ad 100644 --- a/test/parfait/test_typed_method.rb +++ b/test/parfait/test_typed_method.rb @@ -1,97 +1,99 @@ -require_relative "../helper" +require_relative "helper" -class TestMethod < MiniTest::Test +module Parfait + class TestMethod < ParfaitTest - def setup - Risc.machine.boot - obj = Parfait.object_space.get_class_by_name(:Object).instance_type - args = Parfait::Type.for_hash( obj.object_class , { bar: :Integer , foo: :Type}) - frame = Parfait::Type.for_hash( obj.object_class , { local_bar: :Integer , local_foo: :Type}) - @method = Parfait::TypedMethod.new( obj , :meth , args , frame) - end + def setup + super + obj = Parfait.object_space.get_class_by_name(:Object).instance_type + args = Parfait::Type.for_hash( obj.object_class , { bar: :Integer , foo: :Type}) + frame = Parfait::Type.for_hash( obj.object_class , { local_bar: :Integer , local_foo: :Type}) + @method = Parfait::TypedMethod.new( obj , :meth , args , frame) + end - def test_method_name - assert_equal :meth , @method.name - 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_class_for + assert_equal :Object , @method.for_type.object_class.name + end - def test_arg1 - assert_equal 2 , @method.arguments_length , @method.arguments_type.inspect - assert_equal Symbol , @method.arguments_type.names.first.class - assert_equal :bar , @method.argument_name(1) - end + def test_arg1 + assert_equal 2 , @method.arguments_length , @method.arguments_type.inspect + assert_equal Symbol , @method.arguments_type.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_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.argument_type(3) - 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.argument_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.argument_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.argument_type(index) - 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.argument_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.argument_type(index) + end - def test_local1 - assert_equal 2 , @method.frame_length , @method.frame_type.inspect - assert_equal Symbol , @method.frame_type.names.first.class - assert_equal :local_bar , @method.locals_name(1) - end + def test_local1 + assert_equal 2 , @method.frame_length , @method.frame_type.inspect + assert_equal Symbol , @method.frame_type.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_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.frame_length - assert_equal :foo2 , @method.locals_name(3) - assert_equal :Object , @method.locals_type(3) - end + def test_add_local + @method.add_local(:foo2 , :Object) + assert_equal 3 , @method.frame_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_frame_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_frame_type2 - index = @method.has_local(:local_bar) - assert_equal :Integer , @method.locals_type(index) - end - def test_created_with_binary - assert @method.binary + 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_frame_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_frame_type2 + index = @method.has_local(:local_bar) + assert_equal :Integer , @method.locals_type(index) + end + def test_created_with_binary + assert @method.binary + end end end diff --git a/test/parfait/test_word.rb b/test/parfait/test_word.rb index b7fd6bd3..f85cc5b9 100644 --- a/test/parfait/test_word.rb +++ b/test/parfait/test_word.rb @@ -1,113 +1,114 @@ -require_relative "../helper" +require_relative "helper" + module Parfait -class TestEmptyWord < MiniTest::Test + class TestEmptyWord < ParfaitTest - def setup - Risc.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) + def setup + Risc.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 - def test_index_check_set - assert_raises RuntimeError do + + class TestWord < ParfaitTest + def setup + super + @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 -class TestWord < MiniTest::Test - - def setup - Risc.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 diff --git a/test/parfait/type/test_basic.rb b/test/parfait/type/test_basic.rb index dcc93f0f..570c2ee9 100644 --- a/test/parfait/type/test_basic.rb +++ b/test/parfait/type/test_basic.rb @@ -1,75 +1,76 @@ -require_relative "../../helper" +require_relative "../helper" -class BasicType < MiniTest::Test +module Parfait + class BasicType < ParfaitTest - def setup - Risc.machine.boot - @space = Parfait.object_space - @mess = @space.first_message - assert @mess - @type = @mess.get_type() - end + def setup + super + @mess = @space.first_message + assert @mess + @type = @mess.get_type() + end - def test_type_index - assert_equal @mess.get_type , @mess.get_internal_word(Parfait::TYPE_INDEX) , "mess" - end + def test_type_index + assert_equal @mess.get_type , @mess.get_internal_word(Parfait::TYPE_INDEX) , "mess" + end - def test_type_is_first - type = @mess.get_type - assert_equal 1 , type.variable_index(:type) - end + def test_type_is_first + type = @mess.get_type + assert_equal 1 , type.variable_index(:type) + end - def test_length - assert @mess - assert @mess.get_type - assert_equal 9 , @mess.get_type.instance_length , @mess.get_type.inspect - end + def test_length + assert @mess + assert @mess.get_type + assert_equal 9 , @mess.get_type.instance_length , @mess.get_type.inspect + end - def test_names - assert @type.names - end - def test_types - assert @type.types - end + def test_names + assert @type.names + end + def test_types + assert @type.types + end - def test_type_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 + end - def test_type_length_index - type = @mess.get_type.get_type - assert_equal 5 , type.variable_index(:methods) - assert_equal type.object_class , type.get_internal_word(4) - end + def test_type_length_index + type = @mess.get_type.get_type + assert_equal 5 , type.variable_index(:methods) + assert_equal type.object_class , type.get_internal_word(4) + end - def test_no_index_below_1 - type = @mess.get_type - names = type.names - assert_equal 9 , names.get_length , names.inspect - names.each do |n| - assert type.variable_index(n) >= 1 + def test_no_index_below_1 + type = @mess.get_type + names = type.names + assert_equal 9 , names.get_length , names.inspect + names.each do |n| + assert type.variable_index(n) >= 1 + end + end + + def test_attribute_set + @mess.set_receiver( 55) + assert_equal 55 , @mess.receiver + end + + # not really parfait test, but related and no other place currently + def test_reg_index + message_ind = Risc.resolve_to_index( :message , :receiver ) + assert_equal 3 , message_ind + @mess.set_receiver( 55) + assert_equal 55 , @mess.get_internal_word(message_ind) + end + + def test_instance_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 - - def test_attribute_set - @mess.set_receiver( 55) - assert_equal 55 , @mess.receiver - end - - # not really parfait test, but related and no other place currently - def test_reg_index - message_ind = Risc.resolve_to_index( :message , :receiver ) - assert_equal 3 , message_ind - @mess.set_receiver( 55) - assert_equal 55 , @mess.get_internal_word(message_ind) - end - - def test_instance_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 diff --git a/test/parfait/type/test_hash.rb b/test/parfait/type/test_hash.rb index 0100e9b6..4135f095 100644 --- a/test/parfait/type/test_hash.rb +++ b/test/parfait/type/test_hash.rb @@ -1,45 +1,46 @@ -require_relative "../../helper" +require_relative "../helper" -class TypeHash < MiniTest::Test +module Parfait + class TypeHash < ParfaitTest - def setup - Risc.machine.boot - @space = Parfait.object_space - @types = @space.instance_variable_ged("@types") - @first = @types.values.first - end + def setup + super + @types = @space.instance_variable_ged("@types") + @first = @types.values.first + end - def test_hash - assert_equal Parfait::Dictionary , @types.class - end + def test_hash + assert_equal Parfait::Dictionary , @types.class + end - def test_length - assert @types.length > 11 - end + def test_length + assert @types.length > 11 + end - def test_two_hashs_not_equal - assert @types.keys.last != @types.keys.first - end + def test_two_hashs_not_equal + assert @types.keys.last != @types.keys.first + end - def test_name - assert_equal "Word_Type" , @types.values.first.name - end + def test_name + assert_equal "Word_Type" , @types.values.first.name + end - def test_to_hash - hash = @first.to_hash - assert_equal hash[:type] , :Type - assert_equal 2 , hash.length - end - def test_add_is_different - type = @first.add_instance_variable :random , :Integer - assert type != @first , "new: #{type.inspect} , old: #{@first.inspect}" - assert @first.hash != type.hash - end + def test_to_hash + hash = @first.to_hash + assert_equal hash[:type] , :Type + assert_equal 2 , hash.length + end + def test_add_is_different + type = @first.add_instance_variable :random , :Integer + assert type != @first , "new: #{type.inspect} , old: #{@first.inspect}" + assert @first.hash != type.hash + end - def test_hash_for_no_ivars - list = @space.get_class_by_name(:NamedList ) - t1 = Parfait::Type.for_hash( list , type: :NewInt) - t2 = Parfait::Type.for_hash( list , type: :NewObj) - assert t1.hash != t2.hash , "Hashes should differ" + def test_hash_for_no_ivars + list = @space.get_class_by_name(:NamedList ) + t1 = Parfait::Type.for_hash( list , type: :NewInt) + t2 = Parfait::Type.for_hash( list , type: :NewObj) + assert t1.hash != t2.hash , "Hashes should differ" + end end end diff --git a/test/parfait/type/test_message.rb b/test/parfait/type/test_message.rb index 0f098670..6b1e588b 100644 --- a/test/parfait/type/test_message.rb +++ b/test/parfait/type/test_message.rb @@ -1,29 +1,30 @@ -require_relative "../../helper" +require_relative "../helper" -class TypeMessages < MiniTest::Test +module Parfait + class TypeMessages < ParfaitTest + + def setup + super + @mess = @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_methods + assert_equal 5 , @mess.get_type.get_type.variable_index(:methods) + end - def setup - Risc.machine.boot - @space = Parfait.object_space - @mess = @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_methods - assert_equal 5 , @mess.get_type.get_type.variable_index(:methods) - end - end diff --git a/test/parfait/type/test_method_api.rb b/test/parfait/type/test_method_api.rb index 1f9beb7e..3aaefab1 100644 --- a/test/parfait/type/test_method_api.rb +++ b/test/parfait/type/test_method_api.rb @@ -1,82 +1,83 @@ -require_relative "../../helper" +require_relative "../helper" -class TestMethodApi < MiniTest::Test +module Parfait + class TestMethodApi < ParfaitTest - def setup - Risc.machine.boot - @space = Parfait.object_space - @try_class = @space.create_class( :Try ) - @try_type = @try_class.instance_type - end + def setup + super + @try_class = @space.create_class( :Try ) + @try_type = @try_class.instance_type + end - def empty_frame - Parfait::Type.for_hash( @try_class , { }) - end - def foo_method( for_class = :Try) - args = Parfait::Type.for_hash( @try_class , { bar: :Integer}) - ::Parfait::TypedMethod.new( @space.get_class_by_name(for_class).instance_type , :foo , args,empty_frame) - end - def add_foo_to( clazz = :Try ) - foo = foo_method( clazz ) - assert_equal foo , @space.get_class_by_name(clazz).instance_type.add_method(foo) - foo - end - def object_type - @space.get_class_by_name(:Object).instance_type - end - def test_new_methods - assert_equal Parfait::List , @try_type.method_names.class - assert_equal @try_type.method_names.get_length , @try_type.methods_length - end - def test_add_method - before = @try_type.methods_length - add_foo_to - assert_equal 1 , @try_type.methods_length - before - assert @try_type.method_names.inspect.include?(":foo") - end - def test_remove_method - add_foo_to - assert @try_type.remove_method(:foo) - end - def test_remove_not_there - assert_raises RuntimeError do - @try_type.remove_method(:foo) + def empty_frame + Parfait::Type.for_hash( @try_class , { }) + end + def foo_method( for_class = :Try) + args = Parfait::Type.for_hash( @try_class , { bar: :Integer}) + ::Parfait::TypedMethod.new( @space.get_class_by_name(for_class).instance_type , :foo , args,empty_frame) + end + def add_foo_to( clazz = :Try ) + foo = foo_method( clazz ) + assert_equal foo , @space.get_class_by_name(clazz).instance_type.add_method(foo) + foo + end + def object_type + @space.get_class_by_name(:Object).instance_type + end + def test_new_methods + assert_equal Parfait::List , @try_type.method_names.class + assert_equal @try_type.method_names.get_length , @try_type.methods_length + end + def test_add_method + before = @try_type.methods_length + add_foo_to + assert_equal 1 , @try_type.methods_length - before + assert @try_type.method_names.inspect.include?(":foo") + end + def test_remove_method + add_foo_to + assert @try_type.remove_method(:foo) + end + def test_remove_not_there + assert_raises RuntimeError do + @try_type.remove_method(:foo) + end + end + def test_create_method + args = Parfait::Type.for_hash( @try_class , { bar: :Integer}) + @try_type.create_method :bar, args , empty_frame + assert @try_type.method_names.inspect.include?("bar") + end + def test_method_get + add_foo_to + assert_equal Parfait::TypedMethod , @try_type.get_method(:foo).class + end + def test_method_get_nothere + assert_nil @try_type.get_method(:foo) + test_remove_method + assert_nil @try_type.get_method(:foo) + end + def test_get_instance + foo = foo_method :Object + type = @space.get_class_by_name(:Object).instance_type + type.add_method(foo) + assert_equal :foo , type.get_method(:foo).name + end + def test_resolve_on_object + add_foo_to :Object + assert_equal :foo , object_type.resolve_method( :foo ).name + end + def test_resolve_super + add_foo_to :Object + assert_equal :foo , @try_class.instance_type.resolve_method( :foo ).name + end + def test_resolve_is_get + add_foo_to + assert_equal :foo , @try_class.instance_type.resolve_method( :foo ).name + assert_equal :foo , @try_class.instance_type.get_method( :foo ).name + end + def test_resolve_fail + assert_nil object_type.resolve_method( :foo ) end end - def test_create_method - args = Parfait::Type.for_hash( @try_class , { bar: :Integer}) - @try_type.create_method :bar, args , empty_frame - assert @try_type.method_names.inspect.include?("bar") - end - def test_method_get - add_foo_to - assert_equal Parfait::TypedMethod , @try_type.get_method(:foo).class - end - def test_method_get_nothere - assert_nil @try_type.get_method(:foo) - test_remove_method - assert_nil @try_type.get_method(:foo) - end - def test_get_instance - foo = foo_method :Object - type = @space.get_class_by_name(:Object).instance_type - type.add_method(foo) - assert_equal :foo , type.get_method(:foo).name - end - def test_resolve_on_object - add_foo_to :Object - assert_equal :foo , object_type.resolve_method( :foo ).name - end - def test_resolve_super - add_foo_to :Object - assert_equal :foo , @try_class.instance_type.resolve_method( :foo ).name - end - def test_resolve_is_get - add_foo_to - assert_equal :foo , @try_class.instance_type.resolve_method( :foo ).name - assert_equal :foo , @try_class.instance_type.get_method( :foo ).name - end - def test_resolve_fail - assert_nil object_type.resolve_method( :foo ) - end end diff --git a/test/parfait/type/test_type_api.rb b/test/parfait/type/test_type_api.rb index d6f81900..1d1f4c1e 100644 --- a/test/parfait/type/test_type_api.rb +++ b/test/parfait/type/test_type_api.rb @@ -1,93 +1,94 @@ -require_relative "../../helper" +require_relative "../helper" -class TypeApi < MiniTest::Test +module Parfait + class TypeApi < ParfaitTest - def setup - Risc.machine.boot - @space = Parfait.object_space - tc = @space.get_class_by_name( :NamedList ) - @type = tc.instance_type - end - - def test_inspect - assert @type.inspect.start_with?("Type") - end - - def test_class_type - oc = @space.get_class_by_name( :Object ) - assert_equal Parfait::Class , oc.class - type = oc.instance_type - assert_equal Parfait::Type , type.class - assert_equal 1 , type.names.get_length , type.names.inspect - assert_equal type.names.first , :type - end - - def test_class_space - space = Parfait.object_space - assert_equal Parfait::Space , space.class - type = space.get_type - assert_equal Parfait::Type , type.class - assert_equal 8 , type.names.get_length - assert_equal type.object_class.class , Parfait::Class - assert_equal type.object_class.name , :Space - end - - def test_add_name - t = @type.add_instance_variable( :boo , :Object) - assert t - t - end - - def test_added_name_length - type = test_add_name - assert_equal 2 , type.names.get_length , type.inspect - assert_equal :type , type.names.get(1) - assert_equal :boo , type.names.get(2) - end - - def test_added_name_index - type = test_add_name - assert_equal 2 , type.variable_index(:boo) - assert_equal :Object , type.type_at(2) - end - - def test_basic_var_index - assert_equal 1 , @type.variable_index(:type) - end - def test_basic_type_index - assert_equal :Type , @type.type_at(1) - end - - def test_inspect_added - type = test_add_name - assert type.inspect.include?("boo") , type.inspect - end - - def test_added_names - type = test_add_name - assert_equal :type , type.names.get(1) - assert_equal :boo , type.names.get(2) - assert_equal 2 , type.names.get_length - end - - def test_each_name - type = test_add_name - assert_equal 2 , type.get_length - counter = [ :boo , :type ] - type.names.each do |item| - assert_equal item , counter.delete(item) + def setup + super + tc = @space.get_class_by_name( :NamedList ) + @type = tc.instance_type end - assert counter.empty? , counter.inspect - end - def test_each_type - type = test_add_name - assert_equal 2 , type.get_length - counter = [ :Object , :Type] - type.types.each do |item| - assert_equal item , counter.delete(item) + def test_inspect + assert @type.inspect.start_with?("Type") end - assert counter.empty? , counter.inspect - end + def test_class_type + oc = @space.get_class_by_name( :Object ) + assert_equal Parfait::Class , oc.class + type = oc.instance_type + assert_equal Parfait::Type , type.class + assert_equal 1 , type.names.get_length , type.names.inspect + assert_equal type.names.first , :type + end + + def test_class_space + space = Parfait.object_space + assert_equal Parfait::Space , space.class + type = space.get_type + assert_equal Parfait::Type , type.class + assert_equal 8 , type.names.get_length + assert_equal type.object_class.class , Parfait::Class + assert_equal type.object_class.name , :Space + end + + def test_add_name + t = @type.add_instance_variable( :boo , :Object) + assert t + t + end + + def test_added_name_length + type = test_add_name + assert_equal 2 , type.names.get_length , type.inspect + assert_equal :type , type.names.get(1) + assert_equal :boo , type.names.get(2) + end + + def test_added_name_index + type = test_add_name + assert_equal 2 , type.variable_index(:boo) + assert_equal :Object , type.type_at(2) + end + + def test_basic_var_index + assert_equal 1 , @type.variable_index(:type) + end + def test_basic_type_index + assert_equal :Type , @type.type_at(1) + end + + def test_inspect_added + type = test_add_name + assert type.inspect.include?("boo") , type.inspect + end + + def test_added_names + type = test_add_name + assert_equal :type , type.names.get(1) + assert_equal :boo , type.names.get(2) + assert_equal 2 , type.names.get_length + end + + def test_each_name + type = test_add_name + assert_equal 2 , type.get_length + counter = [ :boo , :type ] + type.names.each do |item| + assert_equal item , counter.delete(item) + end + assert counter.empty? , counter.inspect + end + + def test_each_type + type = test_add_name + assert_equal 2 , type.get_length + counter = [ :Object , :Type] + type.types.each do |item| + assert_equal item , counter.delete(item) + end + assert counter.empty? , counter.inspect + end + + end end