basic immutability for type
add_instance_variable now uses global type list to check adds hash and to_has functions use backdoor (send) for booting
This commit is contained in:
@ -70,7 +70,7 @@ class BasicType < MiniTest::Test
|
||||
|
||||
def test_add_name
|
||||
type = Parfait::Type.new Register.machine.space.get_class_by_name(:Type)
|
||||
type.add_instance_variable :boo , :Object
|
||||
type.send(:private_add_instance_variable, :boo , :Object)
|
||||
assert_equal 2 , type.variable_index(:boo)
|
||||
assert_equal 4 , type.get_length
|
||||
assert_equal :type , type.get(1)
|
||||
|
49
test/typed/type/test_hash.rb
Normal file
49
test/typed/type/test_hash.rb
Normal file
@ -0,0 +1,49 @@
|
||||
require_relative "../helper"
|
||||
|
||||
class TypeHash < MiniTest::Test
|
||||
|
||||
def setup
|
||||
@types = Register.machine.boot.space.types
|
||||
@first = @types.values.first
|
||||
end
|
||||
|
||||
def test_hash
|
||||
assert_equal Parfait::Dictionary , @types.class
|
||||
end
|
||||
|
||||
def test_length
|
||||
assert_equal 16 , @types.length
|
||||
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_to_hash
|
||||
hash = @first.to_hash
|
||||
assert_equal hash[:type] , :Word
|
||||
assert_equal hash[:char_length] , :Integer
|
||||
assert_equal 2 , @first.instance_length
|
||||
end
|
||||
|
||||
def test_hashcode_with_hash
|
||||
assert_equal @first.hash , Parfait::Type.hash_code_for( @first.to_hash)
|
||||
end
|
||||
|
||||
def test_second_hash_different
|
||||
hash2 = @first.to_hash
|
||||
hash2[:random] = :Type
|
||||
assert @first.hash != Parfait::Type.hash_code_for( hash2 )
|
||||
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
|
||||
|
||||
end
|
Reference in New Issue
Block a user