From 0feead4557991c94972537360377e4aa7b496bae Mon Sep 17 00:00:00 2001 From: dukeleto Date: Mon, 28 Sep 2009 08:30:18 +0000 Subject: [PATCH] [t][TT #763] Fix is_deeply() on hashes with undefs and add tests git-svn-id: https://svn.parrot.org/parrot/trunk@41541 d31e2699-5ff4-0310-a27c-f18f2fbe73fe --- runtime/parrot/library/Test/More.pir | 27 ++++++++++++++++++-- t/library/test_more.t | 49 +++++++++++++++++++++++++++++++++--- 2 files changed, 71 insertions(+), 5 deletions(-) diff --git a/runtime/parrot/library/Test/More.pir b/runtime/parrot/library/Test/More.pir index deca795c09..f2a97e2c9e 100644 --- a/runtime/parrot/library/Test/More.pir +++ b/runtime/parrot/library/Test/More.pir @@ -519,9 +519,32 @@ This handles comparisons of array-like and hash-like structures. .local string left_value .local string right_value - right_value = pop position - left_value = pop position + .local pmc left, right + right = pop position + left = pop position + + check_right_null: + .local int rnull + rnull = isnull right + unless rnull goto set_right + right_value = 'nonexistent' + goto check_left_null + + set_right: + right_value = right + + check_left_null: + .local int lnull + lnull = isnull left + unless lnull goto set_left + left_value = 'undef' + goto create_diag + + set_left: + left_value = left + + create_diag: .local string nested_path nested_path = join '][', position diff --git a/t/library/test_more.t b/t/library/test_more.t index 0675692b4b..913eca2db5 100644 --- a/t/library/test_more.t +++ b/t/library/test_more.t @@ -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( 89 ) + plan( 93 ) test_skip() test_todo() @@ -393,6 +393,7 @@ CODE .sub test_is_deeply test_is_deeply_array() test_is_deeply_hash() + test_is_deeply_hash_tt763() test_is_deeply_mismatch() test_is_deeply_nested() .end @@ -443,9 +444,13 @@ CODE .sub test_is_deeply_hash .local pmc left .local pmc right + .local pmc undef1 + .local pmc undef2 - left = new 'Hash' - right = new 'Hash' + left = new 'Hash' + right = new 'Hash' + undef1 = new 'Undef' + undef2 = new 'Undef' test_pass() is_deeply( left, right ) @@ -488,6 +493,44 @@ CODE test_test( 'passing test is_deeply() for hashes created in different orders' ) .end +.sub test_is_deeply_hash_tt763 + .local pmc left + .local pmc right + .local pmc undef1 + .local pmc undef2 + + left = new 'Hash' + right = new 'Hash' + undef1 = new 'Undef' + undef2 = new 'Undef' + right['undef1'] = undef1 + left['undef2'] = undef2 + + test_fail() + is_deeply( left, right ) + test_diag( 'Mismatch at [undef2]: expected (undef), received nonexistent' ) + test_test( 'failing is_deeply() for undef in left, nonexistent in right' ) + + test_fail() + is_deeply( right, left ) + test_diag( 'Mismatch at [undef1]: expected (undef), received nonexistent' ) + test_test( 'failing is_deeply() for undef in left, nonexistent in right' ) + + right['undef2'] = undef2 + left['undef1'] = undef1 + + test_pass() + is_deeply( left, right ) + test_test( 'passing is_deeply() with undef values' ) + + left['foo'] = undef1 + test_fail() + is_deeply( left, right ) + test_diag( 'Mismatch: expected 3 elements, received 2') + test_test( 'failing is_deeply() for hashes differing by keys with undef values' ) + +.end + .sub test_is_deeply_mismatch .end -- 2.11.4.GIT