[svn:parrot] r39564 - in trunk: runtime/parrot/library/Test t/library

Infinoid at svn.parrot.org Infinoid at svn.parrot.org
Sun Jun 14 21:46:30 UTC 2009


Author: Infinoid
Date: Sun Jun 14 21:46:29 2009
New Revision: 39564
URL: https://trac.parrot.org/parrot/changeset/39564

Log:
[Test/More.pir] is_deeply can compare hashes, but depends on insertion order.
Depending on the order in which a hash was built, two hashes can have perfectly identical contents, but a different Iter order.
Thus, after comparing the number of entries, we should base the rest of the comparison on *one* Iter, not two in parallel.
I think we still need more work to handle undef values properly, but this is a step in the right direction.  While we're at it, add a test.

Modified:
   trunk/runtime/parrot/library/Test/More.pir
   trunk/t/library/test_more.t

Modified: trunk/runtime/parrot/library/Test/More.pir
==============================================================================
--- trunk/runtime/parrot/library/Test/More.pir	Sun Jun 14 12:49:48 2009	(r39563)
+++ trunk/runtime/parrot/library/Test/More.pir	Sun Jun 14 21:46:29 2009	(r39564)
@@ -468,8 +468,7 @@
 structure.  It passes if they are equal and fails otherwise.  This will
 report the results with the optional test description in C<description>.
 
-This only handles comparisons of array-like structures.  It shouldn't be too
-hard to extend it for hash-like structures, too.
+This handles comparisons of array-like and hash-like structures.
 
 =cut
 
@@ -640,27 +639,22 @@
 
   compare_contents:
     .local pmc l_iter
-    .local pmc r_iter
     .local int count
 
     l_iter = new 'Iterator', l_hash
-    r_iter = new 'Iterator', r_hash
     l_iter = 0
-    r_iter = 0
     count  = 0
 
-    .local pmc l_key
-    .local pmc r_key
+    .local pmc key
     .local pmc l_elem
     .local pmc r_elem
     .local int elems_equal
 
   iter_start:
     unless l_iter goto iter_end
-    l_key  = shift l_iter
-    r_key  = shift r_iter
-    l_elem = l_hash[ l_key ]
-    r_elem = r_hash[ r_key ]
+    key  = shift l_iter
+    l_elem = l_hash[ key ]
+    r_elem = r_hash[ key ]
 
     elems_equal = compare_elements( l_elem, r_elem, position )
     unless elems_equal goto elems_not_equal
@@ -669,7 +663,7 @@
     goto iter_start
 
   elems_not_equal:
-    unshift position, l_key
+    unshift position, key
     .return( 0 )
 
   iter_end:

Modified: trunk/t/library/test_more.t
==============================================================================
--- trunk/t/library/test_more.t	Sun Jun 14 12:49:48 2009	(r39563)
+++ trunk/t/library/test_more.t	Sun Jun 14 21:46:29 2009	(r39564)
@@ -22,7 +22,7 @@
     exports = split " ", "plan test_out test_diag test_fail test_pass test_test"
     test_namespace.'export_to'(curr_namespace, exports)
 
-    plan( 74 )
+    plan( 75 )
 
     test_skip()
     test_todo()
@@ -346,24 +346,29 @@
     test_test( 'failing is_deeply() for hashes with different numbers of keys' )
 
     left['bar']  = 1
-    right['foo'] = 1
+    right['bar'] = 1
 
     test_fail( 'more diag' )
     is_deeply( left, right, 'more diag' )
     test_diag( 'Mismatch: expected 2 elements, received 1' )
     test_test( '... with description and proper pluralization' )
 
-    right['bar'] = 2
+    right['foo'] = 2
 
     test_fail()
     is_deeply( left, right )
-    test_diag( 'Mismatch at [bar]: expected 1, received 2' )
+    test_diag( 'Mismatch at [foo]: expected 1, received 2' )
     test_test( 'failing is_deeply() for hash with value mismatch' )
 
     test_fail( '2 is not 1' )
     is_deeply( left, right, '2 is not 1' )
-    test_diag( 'Mismatch at [bar]: expected 1, received 2' )
+    test_diag( 'Mismatch at [foo]: expected 1, received 2' )
     test_test( '... with description' )
+
+    right['foo'] = 1
+    test_pass()
+    is_deeply( left, right )
+    test_test( 'passing test is_deeply() for hashes created in different orders' )
 .end
 
 .sub test_is_deeply_mismatch


More information about the parrot-commits mailing list