[svn:parrot] r39740 - branches/tt761_keys_revamp/t/pmc
bacek at svn.parrot.org
bacek at svn.parrot.org
Tue Jun 23 11:14:57 UTC 2009
Author: bacek
Date: Tue Jun 23 11:14:56 2009
New Revision: 39740
URL: https://trac.parrot.org/parrot/changeset/39740
Log:
[t] Add tests for storing different value-type in Hash.
Modified:
branches/tt761_keys_revamp/t/pmc/hash.t
Modified: branches/tt761_keys_revamp/t/pmc/hash.t
==============================================================================
--- branches/tt761_keys_revamp/t/pmc/hash.t Tue Jun 23 11:14:33 2009 (r39739)
+++ branches/tt761_keys_revamp/t/pmc/hash.t Tue Jun 23 11:14:56 2009 (r39740)
@@ -21,8 +21,9 @@
.sub main :main
.include 'test_more.pir'
.include 'except_types.pasm'
+ .include 'datatypes.pasm'
- plan(148)
+ plan(155)
initial_hash_tests()
more_than_one_hash()
@@ -68,6 +69,7 @@
unicode_keys_literal_rt_39249()
integer_keys()
+ value_types_convertion()
.end
.sub initial_hash_tests
@@ -1296,6 +1298,46 @@
is($S0, 'Wins!', 'Key was numified again')
.end
+# Check that we can set various value types and they properly converted
+.sub value_types_convertion
+ .local pmc hash
+ hash = new ['Hash']
+
+ # PMC is first value type
+ hash.'set_value_type'(.DATATYPE_PMC)
+ $P0 = new 'Env' # arbitary choice. Just to prevent possible casting.
+ hash['env'] = $P0
+ hash['foo'] = 42
+ hash['bar'] = 21285.06
+ hash['baz'] = 'forty two'
+
+ # Check that original value preserved
+ $P1 = hash['env']
+ $I0 = isa $P1, 'Env'
+ ok($I0, 'Env PMC preserved')
+ $I0 = hash['foo']
+ is($I0, 42, 'Intval preserved')
+ $N0 = hash['bar']
+ is($N0, 21285.06, 'Number preserved')
+ $S0 = hash['baz']
+ is($S0, 'forty two', 'String preserved')
+
+ # Clear the Hash and set INTVAL as stored values.
+ hash.'set_value_type'(.DATATYPE_INTVAL)
+ hash['foo'] = 42 # Use as-is
+ hash['bar'] = 21285.06 # Truncate to int
+ hash['baz'] = 'forty two' # Cast to int
+
+ $I0 = hash['foo']
+ is($I0, 42, 'Intval preserved with datatype int')
+ $I0 = hash['bar']
+ is($I0, 21285, 'Floatval trunkated to int')
+ $I0 = hash['baz']
+ is($I0, 0, 'String casted to int')
+
+ # TODO Add tests for String.
+.end
+
# Local Variables:
# mode: pir
# fill-column: 100
More information about the parrot-commits
mailing list