diff --git a/lib/parfait/indexed.rb b/lib/parfait/indexed.rb index 1ecf586d..abd41fa1 100644 --- a/lib/parfait/indexed.rb +++ b/lib/parfait/indexed.rb @@ -40,7 +40,9 @@ module Parfait # push means add to the end # this automatically grows the List def push value - set( self.get_length + 1 , value) + to = self.get_length + 1 + set( to , value) + to end def delete value diff --git a/test/parfait/test_all.rb b/test/parfait/test_all.rb index 81e8286f..ab3514fa 100644 --- a/test/parfait/test_all.rb +++ b/test/parfait/test_all.rb @@ -3,6 +3,7 @@ require_relative "test_class" require_relative "test_dictionary" require_relative "test_layout" require_relative "test_list" +require_relative "test_message" require_relative "test_meta" require_relative "test_method" require_relative "test_object" diff --git a/test/parfait/test_message.rb b/test/parfait/test_message.rb new file mode 100644 index 00000000..56cca1b0 --- /dev/null +++ b/test/parfait/test_message.rb @@ -0,0 +1,51 @@ +require_relative "../helper" + +class TestMessage < MiniTest::Test + + def setup + @mess = Register.machine.boot.space.first_message + end + + def test_length + assert_equal 9 , @mess.get_layout.instance_length , @mess.get_layout.inspect + assert_equal 9 , Parfait::Message.get_length_index + end + + def test_attribute_set + @mess.receiver = 55 + assert_equal 55 , @mess.receiver + end + + def test_indexed + assert_equal 9 , @mess.get_layout.variable_index(:indexed_length) + end + def test_push1 + @mess.push :name + assert_equal 1 , @mess.get_length + end + def test_push2 + @mess.push :name + assert_equal 1 , @mess.indexed_length + end + def test_push3 + @mess.push :name + assert_equal 1 , @mess.internal_object_get(9) + end + + def test_get + index = @mess.push :name + assert_equal 1 , index + assert_equal :name , @mess.get(1) + end + + def test_each + three = [:one,:two,:three] + three.each {|i| @mess.push(i)} + assert_equal 3 , @mess.get_length + @mess.each do |u| + assert_equal u , three.delete(u) + end + assert_equal 0 , three.length + end + +end